Skip to content

Commit ca296ca

Browse files
graingertjaraco
authored andcommitted
remove lib2to3 usage
1 parent d989cdb commit ca296ca

19 files changed

Lines changed: 434 additions & 862 deletions

docs/deprecated/python3.rst

Lines changed: 0 additions & 94 deletions
This file was deleted.

docs/references/keywords.rst

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -330,21 +330,6 @@ Keywords
330330
mess with it. For more details on how this argument works, see the section
331331
below on :ref:`Automatic Resource Extraction`.
332332

333-
``use_2to3``
334-
Convert the source code from Python 2 to Python 3 with 2to3 during the
335-
build process. See :doc:`../deprecated/python3` for more details.
336-
337-
``convert_2to3_doctests``
338-
List of doctest source files that need to be converted with 2to3.
339-
See :doc:`../deprecated/python3` for more details.
340-
341-
``use_2to3_fixers``
342-
A list of modules to search for additional fixers to be used during
343-
the 2to3 conversion. See :doc:`../deprecated/python3` for more details.
344-
345-
``use_2to3_exclude_fixers``
346-
List of fixer names to be skipped.
347-
348333
``project_urls``
349334
An arbitrary map of URL names to hyperlinks, allowing more extensible
350335
documentation of where various resources can be found than the simple

docs/userguide/declarative_config.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,6 @@ install_requires list-semi
211211
extras_require section [#opt-2]_
212212
python_requires str
213213
entry_points file:, section 51.0.0
214-
use_2to3 bool
215-
use_2to3_fixers list-comma
216-
use_2to3_exclude_fixers list-comma
217-
convert_2to3_doctests list-comma
218214
scripts list-comma
219215
eager_resources list-comma
220216
dependency_links list-comma

docs/userguide/development_mode.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@ Python's ``site-packages`` directory, it will also update the
2828
``easy-install.pth`` file to include your project's source code, thereby making
2929
it available on ``sys.path`` for all programs using that Python installation.
3030

31-
If you have enabled the ``use_2to3`` flag, then of course the ``.egg-link``
32-
will not link directly to your source code when run under Python 3, since
33-
that source code would be made for Python 2 and not work under Python 3.
34-
Instead the ``setup.py develop`` will build Python 3 code under the ``build``
35-
directory, and link there. This means that after doing code changes you will
36-
have to run ``setup.py build`` before these changes are picked up by your
37-
Python 3 installation.
38-
3931
In addition, the ``develop`` command creates wrapper scripts in the target
4032
script directory that will run your in-development scripts after ensuring that
4133
all your ``install_requires`` packages are available on ``sys.path``.

docs/userguide/keywords.rst

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,6 @@ unless you need the associated ``setuptools`` feature.
157157
mess with it. For more details on how this argument works, see the section
158158
below on :ref:`Automatic Resource Extraction`.
159159

160-
``use_2to3``
161-
Convert the source code from Python 2 to Python 3 with 2to3 during the
162-
build process. See :doc:`../deprecated/python3` for more details.
163-
164-
``convert_2to3_doctests``
165-
List of doctest source files that need to be converted with 2to3.
166-
See :doc:`../deprecated/python3` for more details.
167-
168-
``use_2to3_fixers``
169-
A list of modules to search for additional fixers to be used during
170-
the 2to3 conversion. See :doc:`../deprecated/python3` for more details.
171-
172160
``project_urls``
173161
An arbitrary map of URL names to hyperlinks, allowing more extensible
174162
documentation of where various resources can be found than the simple

pytest.ini

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,3 @@ filterwarnings=
2626
ignore:Parent module 'setuptools' not found while handling absolute import:RuntimeWarning
2727
# Suppress use of bytes for filenames on Windows until fixed #2016
2828
ignore:The Windows bytes API has been deprecated:DeprecationWarning
29-
# https://github.com/pypa/setuptools/issues/2081
30-
ignore:lib2to3 package is deprecated:PendingDeprecationWarning
31-
ignore:lib2to3 package is deprecated:DeprecationWarning

setup.cfg

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ distutils.commands =
106106
setuptools.finalize_distribution_options =
107107
parent_finalize = setuptools.dist:_Distribution.finalize_options
108108
keywords = setuptools.dist:Distribution._finalize_setup_keywords
109-
2to3_doctests = setuptools.dist:Distribution._finalize_2to3_doctests
110109
distutils.setup_keywords =
111110
eager_resources = setuptools.dist:assert_string_list
112111
namespace_packages = setuptools.dist:check_nsp
@@ -125,10 +124,6 @@ distutils.setup_keywords =
125124
dependency_links = setuptools.dist:assert_string_list
126125
test_loader = setuptools.dist:check_importable
127126
test_runner = setuptools.dist:check_importable
128-
use_2to3 = setuptools.dist:assert_bool
129-
convert_2to3_doctests = setuptools.dist:assert_string_list
130-
use_2to3_fixers = setuptools.dist:assert_string_list
131-
use_2to3_exclude_fixers = setuptools.dist:assert_string_list
132127
egg_info.writers =
133128
PKG-INFO = setuptools.command.egg_info:write_pkg_info
134129
requires.txt = setuptools.command.egg_info:write_requirements

setuptools/__init__.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,20 @@
2121

2222

2323
__all__ = [
24-
'setup', 'Distribution', 'Command', 'Extension', 'Require',
24+
'setup',
25+
'Distribution',
26+
'Command',
27+
'Extension',
28+
'Require',
2529
'SetuptoolsDeprecationWarning',
26-
'find_packages', 'find_namespace_packages',
30+
'find_packages',
31+
'find_namespace_packages',
2732
]
2833

2934
__version__ = setuptools.version.__version__
3035

3136
bootstrap_install_from = None
3237

33-
# If we run 2to3 on .py files, should we also convert docstrings?
34-
# Default: yes; assume that we can detect doctests reliably
35-
run_2to3_on_doctests = True
36-
# Standard package names for fixer packages
37-
lib2to3_fixer_packages = ['lib2to3.fixes']
38-
3938

4039
class PackageFinder:
4140
"""
@@ -60,10 +59,13 @@ def find(cls, where='.', exclude=(), include=('*',)):
6059
shell style wildcard patterns just like 'exclude'.
6160
"""
6261

63-
return list(cls._find_packages_iter(
64-
convert_path(where),
65-
cls._build_filter('ez_setup', '*__pycache__', *exclude),
66-
cls._build_filter(*include)))
62+
return list(
63+
cls._find_packages_iter(
64+
convert_path(where),
65+
cls._build_filter('ez_setup', '*__pycache__', *exclude),
66+
cls._build_filter(*include),
67+
)
68+
)
6769

6870
@classmethod
6971
def _find_packages_iter(cls, where, exclude, include):
@@ -82,7 +84,7 @@ def _find_packages_iter(cls, where, exclude, include):
8284
package = rel_path.replace(os.path.sep, '.')
8385

8486
# Skip directory trees that are not valid packages
85-
if ('.' in dir or not cls._looks_like_package(full_path)):
87+
if '.' in dir or not cls._looks_like_package(full_path):
8688
continue
8789

8890
# Should this package be included?
@@ -125,12 +127,10 @@ class MinimalDistribution(distutils.core.Distribution):
125127
A minimal version of a distribution for supporting the
126128
fetch_build_eggs interface.
127129
"""
130+
128131
def __init__(self, attrs):
129132
_incl = 'dependency_links', 'setup_requires'
130-
filtered = {
131-
k: attrs[k]
132-
for k in set(_incl) & set(attrs)
133-
}
133+
filtered = {k: attrs[k] for k in set(_incl) & set(attrs)}
134134
distutils.core.Distribution.__init__(self, filtered)
135135

136136
def finalize_options(self):
@@ -178,8 +178,9 @@ def _ensure_stringlike(self, option, what, default=None):
178178
setattr(self, option, default)
179179
return default
180180
elif not isinstance(val, str):
181-
raise DistutilsOptionError("'%s' must be a %s (got `%s`)"
182-
% (option, what, val))
181+
raise DistutilsOptionError(
182+
"'%s' must be a %s (got `%s`)" % (option, what, val)
183+
)
183184
return val
184185

185186
def ensure_string_list(self, option):
@@ -200,8 +201,8 @@ def ensure_string_list(self, option):
200201
ok = False
201202
if not ok:
202203
raise DistutilsOptionError(
203-
"'%s' must be a list of strings (got %r)"
204-
% (option, val))
204+
"'%s' must be a list of strings (got %r)" % (option, val)
205+
)
205206

206207
def reinitialize_command(self, command, reinit_subcommands=0, **kw):
207208
cmd = _Command.reinitialize_command(self, command, reinit_subcommands)

setuptools/command/build_py.py

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,12 @@
1010
import stat
1111
from setuptools.extern.more_itertools import unique_everseen
1212

13-
try:
14-
from setuptools.lib2to3_ex import Mixin2to3
15-
except Exception:
16-
17-
class Mixin2to3:
18-
def run_2to3(self, files, doctests=True):
19-
"do nothing"
20-
2113

2214
def make_writable(target):
2315
os.chmod(target, os.stat(target).st_mode | stat.S_IWRITE)
2416

2517

26-
class build_py(orig.build_py, Mixin2to3):
18+
class build_py(orig.build_py):
2719
"""Enhanced 'build_py' command that includes data files with packages
2820
2921
The data files are specified via a 'package_data' argument to 'setup()'.
@@ -36,12 +28,10 @@ class build_py(orig.build_py, Mixin2to3):
3628
def finalize_options(self):
3729
orig.build_py.finalize_options(self)
3830
self.package_data = self.distribution.package_data
39-
self.exclude_package_data = (self.distribution.exclude_package_data or
40-
{})
31+
self.exclude_package_data = self.distribution.exclude_package_data or {}
4132
if 'data_files' in self.__dict__:
4233
del self.__dict__['data_files']
4334
self.__updated_files = []
44-
self.__doctests_2to3 = []
4535

4636
def run(self):
4737
"""Build modules, packages, and copy data files to build directory"""
@@ -55,10 +45,6 @@ def run(self):
5545
self.build_packages()
5646
self.build_package_data()
5747

58-
self.run_2to3(self.__updated_files, False)
59-
self.run_2to3(self.__updated_files, True)
60-
self.run_2to3(self.__doctests_2to3, True)
61-
6248
# Only compile actual .py files, using our base class' idea of what our
6349
# output files are.
6450
self.byte_compile(orig.build_py.get_outputs(self, include_bytecode=0))
@@ -71,8 +57,7 @@ def __getattr__(self, attr):
7157
return orig.build_py.__getattr__(self, attr)
7258

7359
def build_module(self, module, module_file, package):
74-
outfile, copied = orig.build_py.build_module(self, module, module_file,
75-
package)
60+
outfile, copied = orig.build_py.build_module(self, module, module_file, package)
7661
if copied:
7762
self.__updated_files.append(outfile)
7863
return outfile, copied
@@ -123,9 +108,6 @@ def build_package_data(self):
123108
outf, copied = self.copy_file(srcfile, target)
124109
make_writable(target)
125110
srcfile = os.path.abspath(srcfile)
126-
if (copied and
127-
srcfile in self.distribution.convert_2to3_doctests):
128-
self.__doctests_2to3.append(outf)
129111

130112
def analyze_manifest(self):
131113
self.manifest_files = mf = {}
@@ -202,18 +184,11 @@ def exclude_data_files(self, package, src_dir, files):
202184
package,
203185
src_dir,
204186
)
205-
match_groups = (
206-
fnmatch.filter(files, pattern)
207-
for pattern in patterns
208-
)
187+
match_groups = (fnmatch.filter(files, pattern) for pattern in patterns)
209188
# flatten the groups of matches into an iterable of matches
210189
matches = itertools.chain.from_iterable(match_groups)
211190
bad = set(matches)
212-
keepers = (
213-
fn
214-
for fn in files
215-
if fn not in bad
216-
)
191+
keepers = (fn for fn in files if fn not in bad)
217192
# ditch dupes
218193
return list(unique_everseen(keepers))
219194

@@ -241,12 +216,17 @@ def assert_relative(path):
241216
return path
242217
from distutils.errors import DistutilsSetupError
243218

244-
msg = textwrap.dedent("""
219+
msg = (
220+
textwrap.dedent(
221+
"""
245222
Error: setup script specifies an absolute path:
246223
247224
%s
248225
249226
setup() arguments must *always* be /-separated paths relative to the
250227
setup.py directory, *never* absolute paths.
251-
""").lstrip() % path
228+
"""
229+
).lstrip()
230+
% path
231+
)
252232
raise DistutilsSetupError(msg)

0 commit comments

Comments
 (0)