Jason R. Coombs avatar Jason R. Coombs committed b3c597e

Added options to exclude 2to3 fixers. Fixes #249

Comments (0)

Files changed (4)

 * 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
 
 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',
         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
 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
 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``.
 
 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',
             "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": [

setuptools/command/build_py.py

             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)
             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):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.