Patchwork [2,of,6] setup: remove support for 2to3

login
register
mail settings
Submitter Gregory Szorc
Date Feb. 28, 2016, 5:35 a.m.
Message ID <8f044924a7f8098fb524.1456637753@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/13441/
State Accepted
Headers show

Comments

Gregory Szorc - Feb. 28, 2016, 5:35 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1456636284 28800
#      Sat Feb 27 21:11:24 2016 -0800
# Node ID 8f044924a7f8098fb524f0a43e708fe2590b6380
# Parent  b93c9325939d07ccf189a07fbe9097729370b4e1
setup: remove support for 2to3

We want to run unaltered source on multiple Python versions. We
won't be using 2to3 for Python 3 support.

Patch

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -79,29 +79,16 @@  from distutils import file_util
 from distutils.errors import (
     CCompilerError,
     DistutilsError,
     DistutilsExecError,
 )
 from distutils.sysconfig import get_python_inc, get_config_var
 from distutils.version import StrictVersion
 
-convert2to3 = '--c2to3' in sys.argv
-if convert2to3:
-    try:
-        from distutils.command.build_py import build_py_2to3 as build_py
-        from lib2to3.refactor import get_fixers_from_package as getfixers
-    except ImportError:
-        if sys.version_info[0] < 3:
-            raise SystemExit("--c2to3 is only compatible with python3.")
-        raise
-    sys.path.append('contrib')
-elif sys.version_info[0] >= 3:
-    raise SystemExit("setup.py with python3 needs --c2to3 (experimental)")
-
 scripts = ['hg']
 if os.name == 'nt':
     # We remove hg.bat if we are able to build hg.exe.
     scripts.append('contrib/win32/hg.bat')
 
 # simplified version of distutils.ccompiler.CCompiler.has_function
 # that actually removes its temporary files.
 def hasfunction(cc, funcname):
@@ -230,25 +217,17 @@  try:
     from mercurial import __version__
     version = __version__.version
 except ImportError:
     version = 'unknown'
 
 class hgbuild(build):
     # Insert hgbuildmo first so that files in mercurial/locale/ are found
     # when build_py is run next.
-    sub_commands = [('build_mo', None),
-
-    # We also need build_ext before build_py. Otherwise, when 2to3 is
-    # called (in build_py), it will not find osutil & friends,
-    # thinking that those modules are global and, consequently, making
-    # a mess, now that all module imports are global.
-
-                    ('build_ext', build.has_ext_modules),
-                   ] + build.sub_commands
+    sub_commands = [('build_mo', None)] + build.sub_commands
 
 class hgbuildmo(build):
 
     description = "build translations (.mo files)"
 
     def run(self):
         if not find_executable('msgfmt'):
             self.warn("could not find msgfmt executable, no translations "
@@ -277,18 +256,16 @@  class hgbuildmo(build):
 
 
 class hgdist(Distribution):
     pure = ispypy
 
     global_options = Distribution.global_options + \
                      [('pure', None, "use pure (slow) Python "
                         "code instead of C extensions"),
-                      ('c2to3', None, "(experimental!) convert "
-                        "code with 2to3"),
                      ]
 
     def has_ext_modules(self):
         # self.ext_modules is emptied in hgbuildpy.finalize_options which is
         # too late for some cases
         return not self.pure and Distribution.has_ext_modules(self)
 
 class hgbuildext(build_ext):
@@ -323,20 +300,16 @@  class hgbuildscripts(build_scripts):
             self.copy_file(hgexecommand.hgexepath, dest)
 
             # Remove hg.bat because it is redundant with hg.exe.
             self.scripts.remove('contrib/win32/hg.bat')
 
         return build_scripts.run(self)
 
 class hgbuildpy(build_py):
-    if convert2to3:
-        fixer_names = sorted(set(getfixers("lib2to3.fixes") +
-                                 getfixers("hgfixes")))
-
     def finalize_options(self):
         build_py.finalize_options(self)
 
         if self.distribution.pure:
             self.distribution.ext_modules = []
         else:
             h = os.path.join(get_python_inc(), 'Python.h')
             if not os.path.exists(h):