summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2021-09-04 12:01:04 -0400
committerJason R. Coombs <jaraco@jaraco.com>2021-09-04 12:01:04 -0400
commitd989cdb36f50785d23b07939ba8b4fc2b68cf02a (patch)
tree696f25e6e8108f7e74442c343eb1a64179162379
parent41df8fea702b80fc2bfa1828a01f0b5b89bc36ac (diff)
parentaede9e035dde34b0f2a6e9fe3a3bd87d4b9d7370 (diff)
downloadpython-setuptools-git-d989cdb36f50785d23b07939ba8b4fc2b68cf02a.tar.gz
Merge https://github.com/pypa/distutils into remove-lib2to3-usage
-rw-r--r--docs/deprecated/distutils/apiref.rst18
-rw-r--r--setuptools/_distutils/command/build_py.py26
-rw-r--r--setuptools/_distutils/command/build_scripts.py10
-rw-r--r--setuptools/_distutils/util.py81
4 files changed, 2 insertions, 133 deletions
diff --git a/docs/deprecated/distutils/apiref.rst b/docs/deprecated/distutils/apiref.rst
index 40a360dd..f721fc16 100644
--- a/docs/deprecated/distutils/apiref.rst
+++ b/docs/deprecated/distutils/apiref.rst
@@ -1941,24 +1941,6 @@ Subclasses of :class:`Command` must define the following methods.
.. class:: build_py
-.. class:: build_py_2to3
-
- Alternative implementation of build_py which also runs the
- 2to3 conversion library on each .py file that is going to be
- installed. To use this in a setup.py file for a distribution
- that is designed to run with both Python 2.x and 3.x, add::
-
- try:
- from distutils.command.build_py import build_py_2to3 as build_py
- except ImportError:
- from distutils.command.build_py import build_py
-
- to your setup.py, and later::
-
- cmdclass = {'build_py': build_py}
-
- to the invocation of setup().
-
:mod:`distutils.command.build_scripts` --- Build the scripts of a package
=========================================================================
diff --git a/setuptools/_distutils/command/build_py.py b/setuptools/_distutils/command/build_py.py
index edc2171c..7ef9bcef 100644
--- a/setuptools/_distutils/command/build_py.py
+++ b/setuptools/_distutils/command/build_py.py
@@ -9,7 +9,7 @@ import glob
from distutils.core import Command
from distutils.errors import *
-from distutils.util import convert_path, Mixin2to3
+from distutils.util import convert_path
from distutils import log
class build_py (Command):
@@ -390,27 +390,3 @@ class build_py (Command):
if self.optimize > 0:
byte_compile(files, optimize=self.optimize,
force=self.force, prefix=prefix, dry_run=self.dry_run)
-
-class build_py_2to3(build_py, Mixin2to3):
- def run(self):
- self.updated_files = []
-
- # Base class code
- if self.py_modules:
- self.build_modules()
- if self.packages:
- self.build_packages()
- self.build_package_data()
-
- # 2to3
- self.run_2to3(self.updated_files)
-
- # Remaining base class code
- self.byte_compile(self.get_outputs(include_bytecode=0))
-
- def build_module(self, module, module_file, package):
- res = build_py.build_module(self, module, module_file, package)
- if res[1]:
- # file was copied
- self.updated_files.append(res[0])
- return res
diff --git a/setuptools/_distutils/command/build_scripts.py b/setuptools/_distutils/command/build_scripts.py
index ccc70e64..e3312cf0 100644
--- a/setuptools/_distutils/command/build_scripts.py
+++ b/setuptools/_distutils/command/build_scripts.py
@@ -7,7 +7,7 @@ from stat import ST_MODE
from distutils import sysconfig
from distutils.core import Command
from distutils.dep_util import newer
-from distutils.util import convert_path, Mixin2to3
+from distutils.util import convert_path
from distutils import log
import tokenize
@@ -150,11 +150,3 @@ class build_scripts(Command):
os.chmod(file, newmode)
# XXX should we modify self.outfiles?
return outfiles, updated_files
-
-class build_scripts_2to3(build_scripts, Mixin2to3):
-
- def copy_scripts(self):
- outfiles, updated_files = build_scripts.copy_scripts(self)
- if not self.dry_run:
- self.run_2to3(updated_files)
- return outfiles, updated_files
diff --git a/setuptools/_distutils/util.py b/setuptools/_distutils/util.py
index 4232fd21..64f06dd4 100644
--- a/setuptools/_distutils/util.py
+++ b/setuptools/_distutils/util.py
@@ -533,84 +533,3 @@ def rfc822_escape (header):
lines = header.split('\n')
sep = '\n' + 8 * ' '
return sep.join(lines)
-
-# 2to3 support
-
-def run_2to3(files, fixer_names=None, options=None, explicit=None):
- """Invoke 2to3 on a list of Python files.
- The files should all come from the build area, as the
- modification is done in-place. To reduce the build time,
- only files modified since the last invocation of this
- function should be passed in the files argument."""
-
- if not files:
- return
-
- # Make this class local, to delay import of 2to3
- from lib2to3.refactor import RefactoringTool, get_fixers_from_package
- class DistutilsRefactoringTool(RefactoringTool):
- def log_error(self, msg, *args, **kw):
- log.error(msg, *args)
-
- def log_message(self, msg, *args):
- log.info(msg, *args)
-
- def log_debug(self, msg, *args):
- log.debug(msg, *args)
-
- if fixer_names is None:
- fixer_names = get_fixers_from_package('lib2to3.fixes')
- r = DistutilsRefactoringTool(fixer_names, options=options)
- r.refactor(files, write=True)
-
-def copydir_run_2to3(src, dest, template=None, fixer_names=None,
- options=None, explicit=None):
- """Recursively copy a directory, only copying new and changed files,
- running run_2to3 over all newly copied Python modules afterward.
-
- If you give a template string, it's parsed like a MANIFEST.in.
- """
- from distutils.dir_util import mkpath
- from distutils.file_util import copy_file
- from distutils.filelist import FileList
- filelist = FileList()
- curdir = os.getcwd()
- os.chdir(src)
- try:
- filelist.findall()
- finally:
- os.chdir(curdir)
- filelist.files[:] = filelist.allfiles
- if template:
- for line in template.splitlines():
- line = line.strip()
- if not line: continue
- filelist.process_template_line(line)
- copied = []
- for filename in filelist.files:
- outname = os.path.join(dest, filename)
- mkpath(os.path.dirname(outname))
- res = copy_file(os.path.join(src, filename), outname, update=1)
- if res[1]: copied.append(outname)
- run_2to3([fn for fn in copied if fn.lower().endswith('.py')],
- fixer_names=fixer_names, options=options, explicit=explicit)
- return copied
-
-class Mixin2to3:
- '''Mixin class for commands that run 2to3.
- To configure 2to3, setup scripts may either change
- the class variables, or inherit from individual commands
- to override how 2to3 is invoked.'''
-
- # provide list of fixers to run;
- # defaults to all from lib2to3.fixers
- fixer_names = None
-
- # options dictionary
- options = None
-
- # list of fixers to invoke even though they are marked as explicit
- explicit = None
-
- def run_2to3(self, files):
- return run_2to3(files, self.fixer_names, self.options, self.explicit)