Imported Upstream version 60.9.2 upstream/60.9.2
authorDongHun Kwak <dh0128.kwak@samsung.com>
Mon, 18 Jul 2022 06:39:09 +0000 (15:39 +0900)
committerDongHun Kwak <dh0128.kwak@samsung.com>
Mon, 18 Jul 2022 06:39:09 +0000 (15:39 +0900)
17 files changed:
CHANGES.rst
PKG-INFO
_distutils_hack/__init__.py
setup.cfg
setuptools.egg-info/PKG-INFO
setuptools.egg-info/SOURCES.txt
setuptools/tests/test_distutils_adoption.py
tools/__pycache__/finalize.cpython-310.pyc [new file with mode: 0644]
tools/__pycache__/finalize.cpython-37.pyc [new file with mode: 0644]
tools/__pycache__/finalize.pypy37.pyc [new file with mode: 0644]
tools/__pycache__/ppc64le-patch.cpython-310.pyc [new file with mode: 0644]
tools/__pycache__/ppc64le-patch.cpython-37.pyc [new file with mode: 0644]
tools/__pycache__/ppc64le-patch.pypy37.pyc [new file with mode: 0644]
tools/__pycache__/vendored.cpython-310.pyc [new file with mode: 0644]
tools/__pycache__/vendored.cpython-37.pyc [new file with mode: 0644]
tools/__pycache__/vendored.pypy37.pyc [new file with mode: 0644]
tools/vendored.py.orig [new file with mode: 0644]

index efe34d3..3899933 100644 (file)
@@ -1,3 +1,12 @@
+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
 -------
 
index ebd2497..fc08ddb 100644 (file)
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 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
index c6f7de6..605a6ed 100644 (file)
@@ -57,6 +57,7 @@ def ensure_local_distutils():
     # 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():
@@ -112,6 +113,7 @@ class DistutilsMetaFinder:
         class DistutilsLoader(importlib.abc.Loader):
 
             def create_module(self, spec):
+                mod.__name__ = 'distutils'
                 return mod
 
             def exec_module(self, module):
index e8c87f6..2f4d072 100644 (file)
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,6 +1,6 @@
 [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
index ebd2497..fc08ddb 100644 (file)
@@ -1,6 +1,6 @@
 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
index 3a6e8e9..279b7b2 100644 (file)
@@ -458,4 +458,14 @@ tools/msvc-build-launcher-arm64.cmd
 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
index 366f292..df8f354 100644 (file)
@@ -93,3 +93,66 @@ def test_distutils_has_origin():
     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"
diff --git a/tools/__pycache__/finalize.cpython-310.pyc b/tools/__pycache__/finalize.cpython-310.pyc
new file mode 100644 (file)
index 0000000..cf5b48a
Binary files /dev/null and b/tools/__pycache__/finalize.cpython-310.pyc differ
diff --git a/tools/__pycache__/finalize.cpython-37.pyc b/tools/__pycache__/finalize.cpython-37.pyc
new file mode 100644 (file)
index 0000000..c3c313c
Binary files /dev/null and b/tools/__pycache__/finalize.cpython-37.pyc differ
diff --git a/tools/__pycache__/finalize.pypy37.pyc b/tools/__pycache__/finalize.pypy37.pyc
new file mode 100644 (file)
index 0000000..f6a06ca
Binary files /dev/null and b/tools/__pycache__/finalize.pypy37.pyc differ
diff --git a/tools/__pycache__/ppc64le-patch.cpython-310.pyc b/tools/__pycache__/ppc64le-patch.cpython-310.pyc
new file mode 100644 (file)
index 0000000..54e7b10
Binary files /dev/null and b/tools/__pycache__/ppc64le-patch.cpython-310.pyc differ
diff --git a/tools/__pycache__/ppc64le-patch.cpython-37.pyc b/tools/__pycache__/ppc64le-patch.cpython-37.pyc
new file mode 100644 (file)
index 0000000..67fb812
Binary files /dev/null and b/tools/__pycache__/ppc64le-patch.cpython-37.pyc differ
diff --git a/tools/__pycache__/ppc64le-patch.pypy37.pyc b/tools/__pycache__/ppc64le-patch.pypy37.pyc
new file mode 100644 (file)
index 0000000..689fb3e
Binary files /dev/null and b/tools/__pycache__/ppc64le-patch.pypy37.pyc differ
diff --git a/tools/__pycache__/vendored.cpython-310.pyc b/tools/__pycache__/vendored.cpython-310.pyc
new file mode 100644 (file)
index 0000000..884f92d
Binary files /dev/null and b/tools/__pycache__/vendored.cpython-310.pyc differ
diff --git a/tools/__pycache__/vendored.cpython-37.pyc b/tools/__pycache__/vendored.cpython-37.pyc
new file mode 100644 (file)
index 0000000..d4a633c
Binary files /dev/null and b/tools/__pycache__/vendored.cpython-37.pyc differ
diff --git a/tools/__pycache__/vendored.pypy37.pyc b/tools/__pycache__/vendored.pypy37.pyc
new file mode 100644 (file)
index 0000000..039fda3
Binary files /dev/null and b/tools/__pycache__/vendored.pypy37.pyc differ
diff --git a/tools/vendored.py.orig b/tools/vendored.py.orig
new file mode 100644 (file)
index 0000000..18c69c1
--- /dev/null
@@ -0,0 +1,142 @@
+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()