aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2011-10-04 11:01:49 -0400
committerJason R. Coombs <jaraco@jaraco.com>2011-10-04 11:01:49 -0400
commit694a9231f495a82cf62340f9b98eb4fd7272ecf3 (patch)
tree64b9ae456f9bec343e2331340b482c6bb7370912
parentd36c067b3247bf7dc3102051b088fe744ac74ae0 (diff)
downloadexternal_python_setuptools-694a9231f495a82cf62340f9b98eb4fd7272ecf3.tar.gz
external_python_setuptools-694a9231f495a82cf62340f9b98eb4fd7272ecf3.tar.bz2
external_python_setuptools-694a9231f495a82cf62340f9b98eb4fd7272ecf3.zip
Added options to exclude 2to3 fixers. Fixes #249
--HG-- branch : distribute extra : rebase_source : 2033bcdd4c2e78e0e03796f1f9cf6d6e9a59fc21
-rw-r--r--CHANGES.txt1
-rw-r--r--docs/python3.txt33
-rwxr-xr-xsetup.py3
-rw-r--r--setuptools/command/build_py.py28
4 files changed, 39 insertions, 26 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 855447a7..6b981dd4 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -16,6 +16,7 @@ CHANGES
* Issue #208: Fixed parsed_versions, it now honors post-releases as noted in the documentation
* Issue #207: Windows cli and gui wrappers pass CTRL-C to child python process
* Issue #227: easy_install now passe its arguments to setup.py bdist_egg
+* Issue #249: Added options to exclude 2to3 fixers
------
0.6.22
diff --git a/docs/python3.txt b/docs/python3.txt
index 43845f60..2f6cde4a 100644
--- a/docs/python3.txt
+++ b/docs/python3.txt
@@ -26,18 +26,20 @@ directory, as opposed from the source directory as is normally done.
Distribute will convert all Python files, and also all doctests in Python
files. However, if you have doctests located in separate text files, these
-will not automatically be converted. By adding them to the
-``convert_2to3_doctests`` keyword parameter Distrubute will convert them as
-well.
+will not automatically be converted. By adding them to the
+``convert_2to3_doctests`` keyword parameter Distrubute will convert them as
+well.
By default, the conversion uses all fixers in the ``lib2to3.fixers`` package.
-To use additional fixes, the parameter ``use_2to3_fixers`` can be set
-to a list of names of packages containing fixers.
+To use additional fixers, the parameter ``use_2to3_fixers`` can be set
+to a list of names of packages containing fixers. To exclude fixers, the
+parameter ``use_2to3_exclude_fixers`` can be set to fixer names to be
+skipped.
A typical setup.py can look something like this::
from setuptools import setup
-
+
setup(
name='your.module',
version = '1.0',
@@ -49,7 +51,8 @@ A typical setup.py can look something like this::
test_suite = 'your.module.tests',
use_2to3 = True,
convert_2to3_doctests = ['src/your/module/README.txt'],
- use_2to3_fixers = ['your.fixers']
+ use_2to3_fixers = ['your.fixers'],
+ use_2to3_exclude_fixers = ['lib2to3.fixes.fix_import'],
)
Differential conversion
@@ -58,10 +61,10 @@ Differential conversion
Note that a file will only be copied and converted during the build process
if the source file has been changed. If you add a file to the doctests
that should be converted, it will not be converted the next time you run
-the tests, since it hasn't been modified. You need to remove it from the
+the tests, since it hasn't been modified. You need to remove it from the
build directory. Also if you run the build, install or test commands before
adding the use_2to3 parameter, you will have to remove the build directory
-before you run the test command, as the files otherwise will seem updated,
+before you run the test command, as the files otherwise will seem updated,
and no conversion will happen.
In general, if code doesn't seem to be converted, deleting the build directory
@@ -80,12 +83,6 @@ already converted code, and hence no 2to3 conversion is needed during install.
Advanced features
=================
-If certain fixers are to be suppressed, this again can be overridden with the
-list ``setuptools.command.build_py.build_py.fixer_names``, which at some
-point contains the list of all fixer class names. For an example of how this
-can be done, see the `jaraco.util <https://bitbucket.org/jaraco/jaraco.util>`_
-project.
-
If you don't want to run the 2to3 conversion on the doctests in Python files,
you can turn that off by setting ``setuptools.use_2to3_on_doctests = False``.
@@ -96,18 +93,18 @@ Setuptools do not know about the new keyword parameters to support Python 3.
As a result it will warn about the unknown keyword parameters if you use
setuptools instead of Distribute under Python 2. This is not an error, and
install process will continue as normal, but if you want to get rid of that
-error this is easy. Simply conditionally add the new parameters into an extra
+error this is easy. Simply conditionally add the new parameters into an extra
dict and pass that dict into setup()::
from setuptools import setup
import sys
-
+
extra = {}
if sys.version_info >= (3,):
extra['use_2to3'] = True
extra['convert_2to3_doctests'] = ['src/your/module/README.txt']
extra['use_2to3_fixers'] = ['your.fixers']
-
+
setup(
name='your.module',
version = '1.0',
diff --git a/setup.py b/setup.py
index 216cdd2a..28efcf97 100755
--- a/setup.py
+++ b/setup.py
@@ -172,7 +172,8 @@ dist = setup(
"test_loader = setuptools.dist:check_importable",
"use_2to3 = setuptools.dist:assert_bool",
"convert_2to3_doctests = setuptools.dist:assert_string_list",
- "use_2to3_fixers = setuptools.dist:assert_string_list",
+ "use_2to3_fixers = setuptools.dist:assert_string_list",
+ "use_2to3_exclude_fixers = setuptools.dist:assert_string_list",
],
"egg_info.writers": [
diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py
index a01e2843..d53960fe 100644
--- a/setuptools/command/build_py.py
+++ b/setuptools/command/build_py.py
@@ -28,13 +28,8 @@ try:
if not files:
return
log.info("Fixing "+" ".join(files))
- if not self.fixer_names:
- self.fixer_names = []
- for p in setuptools.lib2to3_fixer_packages:
- self.fixer_names.extend(get_fixers_from_package(p))
- if self.distribution.use_2to3_fixers is not None:
- for p in self.distribution.use_2to3_fixers:
- self.fixer_names.extend(get_fixers_from_package(p))
+ self.__build_fixer_names()
+ self.__exclude_fixers()
if doctests:
if setuptools.run_2to3_on_doctests:
r = DistutilsRefactoringTool(self.fixer_names)
@@ -42,6 +37,25 @@ try:
else:
_Mixin2to3.run_2to3(self, files)
+ def __build_fixer_names(self):
+ if self.fixer_names: return
+ self.fixer_names = []
+ for p in setuptools.lib2to3_fixer_packages:
+ self.fixer_names.extend(get_fixers_from_package(p))
+ if self.distribution.use_2to3_fixers is not None:
+ for p in self.distribution.use_2to3_fixers:
+ self.fixer_names.extend(get_fixers_from_package(p))
+
+ def __exclude_fixers(self):
+ excluded_fixers = getattr(self, 'exclude_fixers', [])
+ if self.distribution.use_2to3_exclude_fixers is not None:
+ excluded_fixers.extend(self.distribution.use_2to3_exclude_fixers)
+ for fixer_name in excluded_fixers:
+ if fixer_name not in self.fixer_names:
+ log.warn("Excluded fixer %s not found", fixer_name)
+ continue
+ self.fixer_names.remove(fixer_name)
+
except ImportError:
class Mixin2to3:
def run_2to3(self, files, doctests=True):