Skip to content

Commit

Permalink
Merge pull request #2731 from graingert/remove-lib2to3-usage
Browse files Browse the repository at this point in the history
remove lib2to3 usage
  • Loading branch information
jaraco committed Sep 4, 2021
2 parents 8a15e44 + 2dddaff commit 1ba66c1
Show file tree
Hide file tree
Showing 24 changed files with 436 additions and 998 deletions.
1 change: 1 addition & 0 deletions changelog.d/2086.breaking.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed support for 2to3 during builds. Projects should port to a unified codebase or pin to an older version of Setuptools using PEP 518 build-requires.
18 changes: 0 additions & 18 deletions docs/deprecated/distutils/apiref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=========================================================================
Expand Down
94 changes: 0 additions & 94 deletions docs/deprecated/python3.rst

This file was deleted.

15 changes: 0 additions & 15 deletions docs/references/keywords.rst
Original file line number Diff line number Diff line change
Expand Up @@ -330,21 +330,6 @@ Keywords
mess with it. For more details on how this argument works, see the section
below on :ref:`Automatic Resource Extraction`.

``use_2to3``
Convert the source code from Python 2 to Python 3 with 2to3 during the
build process. See :doc:`../deprecated/python3` for more details.

``convert_2to3_doctests``
List of doctest source files that need to be converted with 2to3.
See :doc:`../deprecated/python3` for more details.

``use_2to3_fixers``
A list of modules to search for additional fixers to be used during
the 2to3 conversion. See :doc:`../deprecated/python3` for more details.

``use_2to3_exclude_fixers``
List of fixer names to be skipped.

``project_urls``
An arbitrary map of URL names to hyperlinks, allowing more extensible
documentation of where various resources can be found than the simple
Expand Down
4 changes: 0 additions & 4 deletions docs/userguide/declarative_config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,6 @@ install_requires list-semi
extras_require section [#opt-2]_
python_requires str
entry_points file:, section 51.0.0
use_2to3 bool
use_2to3_fixers list-comma
use_2to3_exclude_fixers list-comma
convert_2to3_doctests list-comma
scripts list-comma
eager_resources list-comma
dependency_links list-comma
Expand Down
8 changes: 0 additions & 8 deletions docs/userguide/development_mode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ Python's ``site-packages`` directory, it will also update the
``easy-install.pth`` file to include your project's source code, thereby making
it available on ``sys.path`` for all programs using that Python installation.

If you have enabled the ``use_2to3`` flag, then of course the ``.egg-link``
will not link directly to your source code when run under Python 3, since
that source code would be made for Python 2 and not work under Python 3.
Instead the ``setup.py develop`` will build Python 3 code under the ``build``
directory, and link there. This means that after doing code changes you will
have to run ``setup.py build`` before these changes are picked up by your
Python 3 installation.

In addition, the ``develop`` command creates wrapper scripts in the target
script directory that will run your in-development scripts after ensuring that
all your ``install_requires`` packages are available on ``sys.path``.
Expand Down
12 changes: 0 additions & 12 deletions docs/userguide/keywords.rst
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,6 @@ unless you need the associated ``setuptools`` feature.
mess with it. For more details on how this argument works, see the section
below on :ref:`Automatic Resource Extraction`.

``use_2to3``
Convert the source code from Python 2 to Python 3 with 2to3 during the
build process. See :doc:`../deprecated/python3` for more details.

``convert_2to3_doctests``
List of doctest source files that need to be converted with 2to3.
See :doc:`../deprecated/python3` for more details.

``use_2to3_fixers``
A list of modules to search for additional fixers to be used during
the 2to3 conversion. See :doc:`../deprecated/python3` for more details.

``project_urls``
An arbitrary map of URL names to hyperlinks, allowing more extensible
documentation of where various resources can be found than the simple
Expand Down
3 changes: 0 additions & 3 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,3 @@ filterwarnings=
ignore:Parent module 'setuptools' not found while handling absolute import:RuntimeWarning
# Suppress use of bytes for filenames on Windows until fixed #2016
ignore:The Windows bytes API has been deprecated:DeprecationWarning
# https://github.com/pypa/setuptools/issues/2081
ignore:lib2to3 package is deprecated:PendingDeprecationWarning
ignore:lib2to3 package is deprecated:DeprecationWarning
5 changes: 0 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ distutils.commands =
setuptools.finalize_distribution_options =
parent_finalize = setuptools.dist:_Distribution.finalize_options
keywords = setuptools.dist:Distribution._finalize_setup_keywords
2to3_doctests = setuptools.dist:Distribution._finalize_2to3_doctests
distutils.setup_keywords =
eager_resources = setuptools.dist:assert_string_list
namespace_packages = setuptools.dist:check_nsp
Expand All @@ -125,10 +124,6 @@ distutils.setup_keywords =
dependency_links = setuptools.dist:assert_string_list
test_loader = setuptools.dist:check_importable
test_runner = 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_exclude_fixers = setuptools.dist:assert_string_list
egg_info.writers =
PKG-INFO = setuptools.command.egg_info:write_pkg_info
requires.txt = setuptools.command.egg_info:write_requirements
Expand Down
43 changes: 22 additions & 21 deletions setuptools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,20 @@


__all__ = [
'setup', 'Distribution', 'Command', 'Extension', 'Require',
'setup',
'Distribution',
'Command',
'Extension',
'Require',
'SetuptoolsDeprecationWarning',
'find_packages', 'find_namespace_packages',
'find_packages',
'find_namespace_packages',
]

__version__ = setuptools.version.__version__

bootstrap_install_from = None

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


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

return list(cls._find_packages_iter(
convert_path(where),
cls._build_filter('ez_setup', '*__pycache__', *exclude),
cls._build_filter(*include)))
return list(
cls._find_packages_iter(
convert_path(where),
cls._build_filter('ez_setup', '*__pycache__', *exclude),
cls._build_filter(*include),
)
)

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

# Skip directory trees that are not valid packages
if ('.' in dir or not cls._looks_like_package(full_path)):
if '.' in dir or not cls._looks_like_package(full_path):
continue

# Should this package be included?
Expand Down Expand Up @@ -125,12 +127,10 @@ class MinimalDistribution(distutils.core.Distribution):
A minimal version of a distribution for supporting the
fetch_build_eggs interface.
"""

def __init__(self, attrs):
_incl = 'dependency_links', 'setup_requires'
filtered = {
k: attrs[k]
for k in set(_incl) & set(attrs)
}
filtered = {k: attrs[k] for k in set(_incl) & set(attrs)}
distutils.core.Distribution.__init__(self, filtered)

def finalize_options(self):
Expand Down Expand Up @@ -178,8 +178,9 @@ def _ensure_stringlike(self, option, what, default=None):
setattr(self, option, default)
return default
elif not isinstance(val, str):
raise DistutilsOptionError("'%s' must be a %s (got `%s`)"
% (option, what, val))
raise DistutilsOptionError(
"'%s' must be a %s (got `%s`)" % (option, what, val)
)
return val

def ensure_string_list(self, option):
Expand All @@ -200,8 +201,8 @@ def ensure_string_list(self, option):
ok = False
if not ok:
raise DistutilsOptionError(
"'%s' must be a list of strings (got %r)"
% (option, val))
"'%s' must be a list of strings (got %r)" % (option, val)
)

def reinitialize_command(self, command, reinit_subcommands=0, **kw):
cmd = _Command.reinitialize_command(self, command, reinit_subcommands)
Expand Down
26 changes: 1 addition & 25 deletions setuptools/_distutils/command/build_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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):
Expand Down Expand Up @@ -390,27 +390,3 @@ def byte_compile(self, files):
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
10 changes: 1 addition & 9 deletions setuptools/_distutils/command/build_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
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

Expand Down Expand Up @@ -150,11 +150,3 @@ def copy_scripts(self):
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
Loading

0 comments on commit 1ba66c1

Please sign in to comment.