Commit 26f4380b authored by Martin v. Löwis's avatar Martin v. Löwis

Add convert_doctests_2to3.

--HG--
branch : distribute
extra : rebase_source : 38832a69542ff3b96c403b32ec5b3663b08a61d0
parent ff05819d
...@@ -96,6 +96,7 @@ dist = setup( ...@@ -96,6 +96,7 @@ dist = setup(
"include_package_data = setuptools.dist:assert_bool", "include_package_data = setuptools.dist:assert_bool",
"dependency_links = setuptools.dist:assert_string_list", "dependency_links = setuptools.dist:assert_string_list",
"test_loader = setuptools.dist:check_importable", "test_loader = setuptools.dist:check_importable",
"convert_doctests_2to3= setuptools.dist:convert_doctests_2to3"
], ],
"egg_info.writers": [ "egg_info.writers": [
......
...@@ -20,21 +20,23 @@ try: ...@@ -20,21 +20,23 @@ try:
log.debug(msg, *args) log.debug(msg, *args)
class Mixin2to3(_Mixin2to3): class Mixin2to3(_Mixin2to3):
def run_2to3(self, files): def run_2to3(self, files, doctests = False):
if not setuptools.run_2to3: if not setuptools.run_2to3:
return return
if not self.fixer_names: if not self.fixer_names:
self.fixer_names = [] self.fixer_names = []
for p in setuptools.lib2to3_fixer_packages: for p in setuptools.lib2to3_fixer_packages:
self.fixer_names.extend(get_fixers_from_package(p)) self.fixer_names.extend(get_fixers_from_package(p))
_Mixin2to3.run_2to3(self, files) if doctests:
if setuptools.run_2to3_on_doctests: if setuptools.run_2to3_on_doctests:
r = DistutilsRefactoringTool(self.fixer_names) r = DistutilsRefactoringTool(self.fixer_names)
r.refactor(files, write=True, doctests_only=True) r.refactor(files, write=True, doctests_only=True)
else:
_Mixin2to3.run_2to3(self, files)
except ImportError: except ImportError:
class Mixin2to3: class Mixin2to3:
def run_2to3(self, files): def run_2to3(self, files, doctests=True):
# Nothing done in 2.x # Nothing done in 2.x
pass pass
...@@ -53,6 +55,7 @@ class build_py(_build_py, Mixin2to3): ...@@ -53,6 +55,7 @@ class build_py(_build_py, Mixin2to3):
self.exclude_package_data = self.distribution.exclude_package_data or {} self.exclude_package_data = self.distribution.exclude_package_data or {}
if 'data_files' in self.__dict__: del self.__dict__['data_files'] if 'data_files' in self.__dict__: del self.__dict__['data_files']
self.__updated_files = [] self.__updated_files = []
self.__doctests_2to3 = []
def run(self): def run(self):
"""Build modules, packages, and copy data files to build directory""" """Build modules, packages, and copy data files to build directory"""
...@@ -66,7 +69,9 @@ class build_py(_build_py, Mixin2to3): ...@@ -66,7 +69,9 @@ class build_py(_build_py, Mixin2to3):
self.build_packages() self.build_packages()
self.build_package_data() self.build_package_data()
self.run_2to3(self.__updated_files) self.run_2to3(self.__updated_files, False)
self.run_2to3(self.__updated_files, True)
self.run_2to3(self.__doctests_2to3, True)
# Only compile actual .py files, using our base class' idea of what our # Only compile actual .py files, using our base class' idea of what our
# output files are. # output files are.
...@@ -121,7 +126,9 @@ class build_py(_build_py, Mixin2to3): ...@@ -121,7 +126,9 @@ class build_py(_build_py, Mixin2to3):
for filename in filenames: for filename in filenames:
target = os.path.join(build_dir, filename) target = os.path.join(build_dir, filename)
self.mkpath(os.path.dirname(target)) self.mkpath(os.path.dirname(target))
self.copy_file(os.path.join(src_dir, filename), target) outf, copied = self.copy_file(os.path.join(src_dir, filename), target)
if copied and filename in setuptools.convert_doctests_2to3:
self.__doctests_2to3.append(outf)
def analyze_manifest(self): def analyze_manifest(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment