+v60.9.2
+-------
+
+
+Misc
+^^^^
+* #3035: When loading distutils from the vendored copy, rewrite ``__name__`` to ensure consistent importing from inside and out.
+
+
v60.9.1
-------
Metadata-Version: 2.1
Name: setuptools
-Version: 60.9.1
+Version: 60.9.2
Summary: Easily download, build, install, upgrade, and uninstall Python packages
Home-page: https://github.com/pypa/setuptools
Author: Python Packaging Authority
# check that submodules load as expected
core = importlib.import_module('distutils.core')
assert '_distutils' in core.__file__, core.__file__
+ assert 'setuptools._distutils.log' not in sys.modules
def do_override():
class DistutilsLoader(importlib.abc.Loader):
def create_module(self, spec):
+ mod.__name__ = 'distutils'
return mod
def exec_module(self, module):
[metadata]
name = setuptools
-version = 60.9.1
+version = 60.9.2
author = Python Packaging Authority
author_email = distutils-sig@python.org
description = Easily download, build, install, upgrade, and uninstall Python packages
Metadata-Version: 2.1
Name: setuptools
-Version: 60.9.1
+Version: 60.9.2
Summary: Easily download, build, install, upgrade, and uninstall Python packages
Home-page: https://github.com/pypa/setuptools
Author: Python Packaging Authority
tools/msvc-build-launcher.cmd
tools/ppc64le-patch.py
tools/towncrier_template.rst
-tools/vendored.py
\ No newline at end of file
+tools/vendored.py
+tools/vendored.py.orig
+tools/__pycache__/finalize.cpython-310.pyc
+tools/__pycache__/finalize.cpython-37.pyc
+tools/__pycache__/finalize.pypy37.pyc
+tools/__pycache__/ppc64le-patch.cpython-310.pyc
+tools/__pycache__/ppc64le-patch.cpython-37.pyc
+tools/__pycache__/ppc64le-patch.pypy37.pyc
+tools/__pycache__/vendored.cpython-310.pyc
+tools/__pycache__/vendored.cpython-37.pyc
+tools/__pycache__/vendored.pypy37.pyc
\ No newline at end of file
Distutils module spec should have an origin. #2990.
"""
assert __import__('distutils').__spec__.origin
+
+
+ENSURE_IMPORTS_ARE_NOT_DUPLICATED = r"""
+# Depending on the importlib machinery and _distutils_hack, some imports are
+# duplicated resulting in different module objects being loaded, which prevents
+# patches as shown in #3042.
+# This script provides a way of verifying if this duplication is happening.
+
+from distutils import cmd
+import distutils.command.sdist as sdist
+
+# import last to prevent caching
+from distutils import {imported_module}
+
+for mod in (cmd, sdist):
+ assert mod.{imported_module} == {imported_module}, (
+ f"\n{{mod.dir_util}}\n!=\n{{{imported_module}}}"
+ )
+
+print("success")
+"""
+
+
+@pytest.mark.parametrize(
+ "distutils_version, imported_module",
+ [
+ ("stdlib", "dir_util"),
+ ("stdlib", "file_util"),
+ ("stdlib", "archive_util"),
+ ("local", "dir_util"),
+ ("local", "file_util"),
+ ("local", "archive_util"),
+ ]
+)
+def test_modules_are_not_duplicated_on_import(
+ distutils_version, imported_module, tmpdir_cwd, venv
+):
+ env = dict(SETUPTOOLS_USE_DISTUTILS=distutils_version)
+ script = ENSURE_IMPORTS_ARE_NOT_DUPLICATED.format(imported_module=imported_module)
+ cmd = ['python', '-c', script]
+ output = popen_text(venv.run)(cmd, env=win_sr(env)).strip()
+ assert output == "success"
+
+
+ENSURE_LOG_IMPORT_IS_NOT_DUPLICATED = r"""
+# Similar to ENSURE_IMPORTS_ARE_NOT_DUPLICATED
+import distutils.dist as dist
+from distutils import log
+
+assert dist.log == log, (
+ f"\n{dist.log}\n!=\n{log}"
+)
+
+print("success")
+"""
+
+
+@pytest.mark.parametrize("distutils_version", "local stdlib".split())
+def test_log_module_is_not_duplicated_on_import(distutils_version, tmpdir_cwd, venv):
+ env = dict(SETUPTOOLS_USE_DISTUTILS=distutils_version)
+ cmd = ['python', '-c', ENSURE_LOG_IMPORT_IS_NOT_DUPLICATED]
+ output = popen_text(venv.run)(cmd, env=win_sr(env)).strip()
+ assert output == "success"
--- /dev/null
+import re
+import sys
+import subprocess
+
+from path import Path
+
+
+def remove_all(paths):
+ for path in paths:
+ path.rmtree() if path.isdir() else path.remove()
+
+
+def update_vendored():
+ update_pkg_resources()
+ update_setuptools()
+
+
+def rewrite_packaging(pkg_files, new_root):
+ """
+ Rewrite imports in packaging to redirect to vendored copies.
+ """
+ for file in pkg_files.glob('*.py'):
+ text = file.text()
+ text = re.sub(r' (pyparsing)', rf' {new_root}.\1', text)
+ text = text.replace(
+ 'from six.moves.urllib import parse',
+ 'from urllib import parse',
+ )
+ file.write_text(text)
+
+
+def rewrite_jaraco_text(pkg_files, new_root):
+ """
+ Rewrite imports in jaraco.text to redirect to vendored copies.
+ """
+ for file in pkg_files.glob('*.py'):
+ text = file.read_text()
+ text = re.sub(r' (jaraco\.)', rf' {new_root}.\1', text)
+ text = re.sub(r' (importlib_resources)', rf' {new_root}.\1', text)
+ # suppress loading of lorem_ipsum; ref #3072
+ text = re.sub(r'^lorem_ipsum.*\n$', '', text, flags=re.M)
+ file.write_text(text)
+
+
+def rewrite_jaraco(pkg_files, new_root):
+ """
+ Rewrite imports in jaraco.functools to redirect to vendored copies.
+ """
+ for file in pkg_files.glob('*.py'):
+ text = file.read_text()
+ text = re.sub(r' (more_itertools)', rf' {new_root}.\1', text)
+ file.write_text(text)
+ # required for zip-packaged setuptools #3084
+ pkg_files.joinpath('__init__.py').write_text('')
+
+
+def rewrite_importlib_resources(pkg_files, new_root):
+ """
+ Rewrite imports in importlib_resources to redirect to vendored copies.
+ """
+ for file in pkg_files.glob('*.py'):
+ text = file.read_text().replace('importlib_resources.abc', '.abc')
+ text = text.replace('zipp', '..zipp')
+ file.write_text(text)
+
+
+<<<<<<< HEAD
+def rewrite_importlib_metadata(pkg_files, new_root):
+ """
+ Rewrite imports in importlib_metadata to redirect to vendored copies.
+ """
+ for file in pkg_files.glob('*.py'):
+ text = file.read_text().replace('typing_extensions', '..typing_extensions')
+ text = text.replace('import zipp', 'from .. import zipp')
+ file.write_text(text)
+=======
+def rewrite_more_itertools(pkg_files: Path):
+ """
+ Defer import of concurrent.futures. Workaround for #3090.
+ """
+ more_file = pkg_files.joinpath('more.py')
+ text = more_file.read_text()
+ text = re.sub(r'^.*concurrent.futures.*?\n', '', text, flags=re.MULTILINE)
+ text = re.sub(
+ 'ThreadPoolExecutor',
+ '__import__("concurrent.futures").futures.ThreadPoolExecutor',
+ text,
+ )
+ more_file.write_text(text)
+>>>>>>> main
+
+
+def clean(vendor):
+ """
+ Remove all files out of the vendor directory except the meta
+ data (as pip uninstall doesn't support -t).
+ """
+ remove_all(
+ path
+ for path in vendor.glob('*')
+ if path.basename() != 'vendored.txt'
+ )
+
+
+def install(vendor):
+ clean(vendor)
+ install_args = [
+ sys.executable,
+ '-m', 'pip',
+ 'install',
+ '-r', str(vendor / 'vendored.txt'),
+ '-t', str(vendor),
+ ]
+ subprocess.check_call(install_args)
+ (vendor / '__init__.py').write_text('')
+
+
+def update_pkg_resources():
+ vendor = Path('pkg_resources/_vendor')
+ install(vendor)
+ rewrite_packaging(vendor / 'packaging', 'pkg_resources.extern')
+ rewrite_jaraco_text(vendor / 'jaraco/text', 'pkg_resources.extern')
+ rewrite_jaraco(vendor / 'jaraco', 'pkg_resources.extern')
+ rewrite_importlib_resources(vendor / 'importlib_resources', 'pkg_resources.extern')
+ rewrite_more_itertools(vendor / "more_itertools")
+
+
+def update_setuptools():
+ vendor = Path('setuptools/_vendor')
+ install(vendor)
+ rewrite_packaging(vendor / 'packaging', 'setuptools.extern')
+ rewrite_jaraco_text(vendor / 'jaraco/text', 'setuptools.extern')
+ rewrite_jaraco(vendor / 'jaraco', 'setuptools.extern')
+ rewrite_importlib_resources(vendor / 'importlib_resources', 'setuptools.extern')
+<<<<<<< HEAD
+ rewrite_importlib_metadata(vendor / 'importlib_metadata', 'setuptools.extern')
+=======
+ rewrite_more_itertools(vendor / "more_itertools")
+>>>>>>> main
+
+
+__name__ == '__main__' and update_vendored()