Skip to content

Commit d989cdb

Browse files
committed
Merge https://github.com/pypa/distutils into remove-lib2to3-usage
2 parents 41df8fe + aede9e0 commit d989cdb

File tree

4 files changed

+2
-133
lines changed

4 files changed

+2
-133
lines changed

docs/deprecated/distutils/apiref.rst

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,24 +1941,6 @@ Subclasses of :class:`Command` must define the following methods.
19411941

19421942
.. class:: build_py
19431943

1944-
.. class:: build_py_2to3
1945-
1946-
Alternative implementation of build_py which also runs the
1947-
2to3 conversion library on each .py file that is going to be
1948-
installed. To use this in a setup.py file for a distribution
1949-
that is designed to run with both Python 2.x and 3.x, add::
1950-
1951-
try:
1952-
from distutils.command.build_py import build_py_2to3 as build_py
1953-
except ImportError:
1954-
from distutils.command.build_py import build_py
1955-
1956-
to your setup.py, and later::
1957-
1958-
cmdclass = {'build_py': build_py}
1959-
1960-
to the invocation of setup().
1961-
19621944

19631945
:mod:`distutils.command.build_scripts` --- Build the scripts of a package
19641946
=========================================================================

setuptools/_distutils/command/build_py.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from distutils.core import Command
1111
from distutils.errors import *
12-
from distutils.util import convert_path, Mixin2to3
12+
from distutils.util import convert_path
1313
from distutils import log
1414

1515
class build_py (Command):
@@ -390,27 +390,3 @@ def byte_compile(self, files):
390390
if self.optimize > 0:
391391
byte_compile(files, optimize=self.optimize,
392392
force=self.force, prefix=prefix, dry_run=self.dry_run)
393-
394-
class build_py_2to3(build_py, Mixin2to3):
395-
def run(self):
396-
self.updated_files = []
397-
398-
# Base class code
399-
if self.py_modules:
400-
self.build_modules()
401-
if self.packages:
402-
self.build_packages()
403-
self.build_package_data()
404-
405-
# 2to3
406-
self.run_2to3(self.updated_files)
407-
408-
# Remaining base class code
409-
self.byte_compile(self.get_outputs(include_bytecode=0))
410-
411-
def build_module(self, module, module_file, package):
412-
res = build_py.build_module(self, module, module_file, package)
413-
if res[1]:
414-
# file was copied
415-
self.updated_files.append(res[0])
416-
return res

setuptools/_distutils/command/build_scripts.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from distutils import sysconfig
88
from distutils.core import Command
99
from distutils.dep_util import newer
10-
from distutils.util import convert_path, Mixin2to3
10+
from distutils.util import convert_path
1111
from distutils import log
1212
import tokenize
1313

@@ -150,11 +150,3 @@ def copy_scripts(self):
150150
os.chmod(file, newmode)
151151
# XXX should we modify self.outfiles?
152152
return outfiles, updated_files
153-
154-
class build_scripts_2to3(build_scripts, Mixin2to3):
155-
156-
def copy_scripts(self):
157-
outfiles, updated_files = build_scripts.copy_scripts(self)
158-
if not self.dry_run:
159-
self.run_2to3(updated_files)
160-
return outfiles, updated_files

setuptools/_distutils/util.py

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -533,84 +533,3 @@ def rfc822_escape (header):
533533
lines = header.split('\n')
534534
sep = '\n' + 8 * ' '
535535
return sep.join(lines)
536-
537-
# 2to3 support
538-
539-
def run_2to3(files, fixer_names=None, options=None, explicit=None):
540-
"""Invoke 2to3 on a list of Python files.
541-
The files should all come from the build area, as the
542-
modification is done in-place. To reduce the build time,
543-
only files modified since the last invocation of this
544-
function should be passed in the files argument."""
545-
546-
if not files:
547-
return
548-
549-
# Make this class local, to delay import of 2to3
550-
from lib2to3.refactor import RefactoringTool, get_fixers_from_package
551-
class DistutilsRefactoringTool(RefactoringTool):
552-
def log_error(self, msg, *args, **kw):
553-
log.error(msg, *args)
554-
555-
def log_message(self, msg, *args):
556-
log.info(msg, *args)
557-
558-
def log_debug(self, msg, *args):
559-
log.debug(msg, *args)
560-
561-
if fixer_names is None:
562-
fixer_names = get_fixers_from_package('lib2to3.fixes')
563-
r = DistutilsRefactoringTool(fixer_names, options=options)
564-
r.refactor(files, write=True)
565-
566-
def copydir_run_2to3(src, dest, template=None, fixer_names=None,
567-
options=None, explicit=None):
568-
"""Recursively copy a directory, only copying new and changed files,
569-
running run_2to3 over all newly copied Python modules afterward.
570-
571-
If you give a template string, it's parsed like a MANIFEST.in.
572-
"""
573-
from distutils.dir_util import mkpath
574-
from distutils.file_util import copy_file
575-
from distutils.filelist import FileList
576-
filelist = FileList()
577-
curdir = os.getcwd()
578-
os.chdir(src)
579-
try:
580-
filelist.findall()
581-
finally:
582-
os.chdir(curdir)
583-
filelist.files[:] = filelist.allfiles
584-
if template:
585-
for line in template.splitlines():
586-
line = line.strip()
587-
if not line: continue
588-
filelist.process_template_line(line)
589-
copied = []
590-
for filename in filelist.files:
591-
outname = os.path.join(dest, filename)
592-
mkpath(os.path.dirname(outname))
593-
res = copy_file(os.path.join(src, filename), outname, update=1)
594-
if res[1]: copied.append(outname)
595-
run_2to3([fn for fn in copied if fn.lower().endswith('.py')],
596-
fixer_names=fixer_names, options=options, explicit=explicit)
597-
return copied
598-
599-
class Mixin2to3:
600-
'''Mixin class for commands that run 2to3.
601-
To configure 2to3, setup scripts may either change
602-
the class variables, or inherit from individual commands
603-
to override how 2to3 is invoked.'''
604-
605-
# provide list of fixers to run;
606-
# defaults to all from lib2to3.fixers
607-
fixer_names = None
608-
609-
# options dictionary
610-
options = None
611-
612-
# list of fixers to invoke even though they are marked as explicit
613-
explicit = None
614-
615-
def run_2to3(self, files):
616-
return run_2to3(files, self.fixer_names, self.options, self.explicit)

0 commit comments

Comments
 (0)