From 280a623332ddab38cf451f6bf73bf7ea55f4d4ac Mon Sep 17 00:00:00 2001 From: JinWang An Date: Mon, 27 Mar 2023 17:02:42 +0900 Subject: [PATCH] Imported Upstream version 60.3.0 --- .bumpversion.cfg | 2 +- .github/workflows/main.yml | 1 + CHANGES.rst | 13 +++++ _distutils_hack/__init__.py | 10 ++++ setup.cfg | 2 +- setuptools/_distutils/_collections.py | 56 +++++++++++++++++++ setuptools/_distutils/command/install.py | 20 ++++--- setuptools/_distutils/tests/py38compat.py | 9 +++ setuptools/_distutils/tests/test_bdist_rpm.py | 9 ++- setuptools/_distutils/tests/test_build_ext.py | 8 ++- setuptools/command/easy_install.py | 2 +- 11 files changed, 115 insertions(+), 17 deletions(-) create mode 100644 setuptools/_distutils/_collections.py diff --git a/.bumpversion.cfg b/.bumpversion.cfg index f696b07..36b7126 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 60.2.0 +current_version = 60.3.0 commit = True tag = True diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5a01e9a..94d0a08 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,6 +12,7 @@ jobs: python: - pypy-3.7 - 3.7 + - 3.8 - 3.9 - "3.10" platform: diff --git a/CHANGES.rst b/CHANGES.rst index 59b29fb..51fab99 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,16 @@ +v60.3.0 +------- + + +Changes +^^^^^^^ +* #2993: In _distutils_hack, bypass the distutils exception for pip when get-pip is being invoked, because it imports setuptools. + +Misc +^^^^ +* #2989: Merge with pypa/distutils@788cc159. Includes fix for config vars missing from sysconfig. + + v60.2.0 ------- diff --git a/_distutils_hack/__init__.py b/_distutils_hack/__init__.py index c0170d0..4745f8b 100644 --- a/_distutils_hack/__init__.py +++ b/_distutils_hack/__init__.py @@ -116,6 +116,8 @@ class DistutilsMetaFinder: """ if self.pip_imported_during_build(): return + if self.is_get_pip(): + return clear_distutils() self.spec_for_distutils = lambda: None @@ -130,6 +132,14 @@ class DistutilsMetaFinder: for frame, line in traceback.walk_stack(None) ) + @classmethod + def is_get_pip(cls): + """ + Detect if get-pip is being invoked. Ref #2993. + """ + import __main__ + return os.path.basename(__main__.__file__) == 'get-pip.py' + @staticmethod def frame_file_is_setup(frame): """ diff --git a/setup.cfg b/setup.cfg index 75a41c8..0af9cd5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = setuptools -version = 60.2.0 +version = 60.3.0 author = Python Packaging Authority author_email = distutils-sig@python.org description = Easily download, build, install, upgrade, and uninstall Python packages diff --git a/setuptools/_distutils/_collections.py b/setuptools/_distutils/_collections.py new file mode 100644 index 0000000..98fce80 --- /dev/null +++ b/setuptools/_distutils/_collections.py @@ -0,0 +1,56 @@ +import collections +import itertools + + +# from jaraco.collections 3.5.1 +class DictStack(list, collections.abc.Mapping): + """ + A stack of dictionaries that behaves as a view on those dictionaries, + giving preference to the last. + + >>> stack = DictStack([dict(a=1, c=2), dict(b=2, a=2)]) + >>> stack['a'] + 2 + >>> stack['b'] + 2 + >>> stack['c'] + 2 + >>> len(stack) + 3 + >>> stack.push(dict(a=3)) + >>> stack['a'] + 3 + >>> set(stack.keys()) == set(['a', 'b', 'c']) + True + >>> set(stack.items()) == set([('a', 3), ('b', 2), ('c', 2)]) + True + >>> dict(**stack) == dict(stack) == dict(a=3, c=2, b=2) + True + >>> d = stack.pop() + >>> stack['a'] + 2 + >>> d = stack.pop() + >>> stack['a'] + 1 + >>> stack.get('b', None) + >>> 'c' in stack + True + """ + + def __iter__(self): + dicts = list.__iter__(self) + return iter(set(itertools.chain.from_iterable(c.keys() for c in dicts))) + + def __getitem__(self, key): + for scope in reversed(tuple(list.__iter__(self))): + if key in scope: + return scope[key] + raise KeyError(key) + + push = list.append + + def __contains__(self, other): + return collections.abc.Mapping.__contains__(self, other) + + def __len__(self): + return len(list(iter(self))) diff --git a/setuptools/_distutils/command/install.py b/setuptools/_distutils/command/install.py index cdcc052..511938f 100644 --- a/setuptools/_distutils/command/install.py +++ b/setuptools/_distutils/command/install.py @@ -17,6 +17,7 @@ from distutils.file_util import write_file from distutils.util import convert_path, subst_vars, change_root from distutils.util import get_platform from distutils.errors import DistutilsOptionError +from .. import _collections from site import USER_BASE from site import USER_SITE @@ -394,7 +395,8 @@ class install(Command): except AttributeError: # sys.abiflags may not be defined on all platforms. abiflags = '' - self.config_vars = {'dist_name': self.distribution.get_name(), + local_vars = { + 'dist_name': self.distribution.get_name(), 'dist_version': self.distribution.get_version(), 'dist_fullname': self.distribution.get_fullname(), 'py_version': py_version, @@ -408,12 +410,14 @@ class install(Command): 'platlibdir': getattr(sys, 'platlibdir', 'lib'), 'implementation_lower': _get_implementation().lower(), 'implementation': _get_implementation(), - 'platsubdir': sysconfig.get_config_var('platsubdir'), } if HAS_USER_SITE: - self.config_vars['userbase'] = self.install_userbase - self.config_vars['usersite'] = self.install_usersite + local_vars['userbase'] = self.install_userbase + local_vars['usersite'] = self.install_usersite + + self.config_vars = _collections.DictStack( + [sysconfig.get_config_vars(), local_vars]) self.expand_basedirs() @@ -421,15 +425,13 @@ class install(Command): # Now define config vars for the base directories so we can expand # everything else. - self.config_vars['base'] = self.install_base - self.config_vars['platbase'] = self.install_platbase - self.config_vars['installed_base'] = ( - sysconfig.get_config_vars()['installed_base']) + local_vars['base'] = self.install_base + local_vars['platbase'] = self.install_platbase if DEBUG: from pprint import pprint print("config vars:") - pprint(self.config_vars) + pprint(dict(self.config_vars)) # Expand "~" and configuration variables in the installation # directories. diff --git a/setuptools/_distutils/tests/py38compat.py b/setuptools/_distutils/tests/py38compat.py index 32269c7..c949f58 100644 --- a/setuptools/_distutils/tests/py38compat.py +++ b/setuptools/_distutils/tests/py38compat.py @@ -2,6 +2,11 @@ import contextlib import builtins +import sys + +from test.support import requires_zlib +import test.support + ModuleNotFoundError = getattr(builtins, 'ModuleNotFoundError', ImportError) @@ -51,3 +56,7 @@ try: from test.support.warnings_helper import save_restore_warnings_filters except (ModuleNotFoundError, ImportError): save_restore_warnings_filters = _save_restore_warnings_filters + + +if sys.version_info < (3, 9): + requires_zlib = lambda: test.support.requires_zlib diff --git a/setuptools/_distutils/tests/test_bdist_rpm.py b/setuptools/_distutils/tests/test_bdist_rpm.py index 3b22af3..08a7cb4 100644 --- a/setuptools/_distutils/tests/test_bdist_rpm.py +++ b/setuptools/_distutils/tests/test_bdist_rpm.py @@ -3,13 +3,16 @@ import unittest import sys import os -from test.support import run_unittest, requires_zlib +from test.support import run_unittest from distutils.core import Distribution from distutils.command.bdist_rpm import bdist_rpm from distutils.tests import support from distutils.spawn import find_executable +from .py38compat import requires_zlib + + SETUP_PY = """\ from distutils.core import setup import foo @@ -44,7 +47,7 @@ class BuildRpmTestCase(support.TempdirManager, # spurious sdtout/stderr output under Mac OS X @unittest.skipUnless(sys.platform.startswith('linux'), 'spurious sdtout/stderr output under Mac OS X') - @requires_zlib + @requires_zlib() @unittest.skipIf(find_executable('rpm') is None, 'the rpm command is not found') @unittest.skipIf(find_executable('rpmbuild') is None, @@ -87,7 +90,7 @@ class BuildRpmTestCase(support.TempdirManager, # spurious sdtout/stderr output under Mac OS X @unittest.skipUnless(sys.platform.startswith('linux'), 'spurious sdtout/stderr output under Mac OS X') - @requires_zlib + @requires_zlib() # http://bugs.python.org/issue1533164 @unittest.skipIf(find_executable('rpm') is None, 'the rpm command is not found') diff --git a/setuptools/_distutils/tests/test_build_ext.py b/setuptools/_distutils/tests/test_build_ext.py index cb0db2b..920e4dc 100644 --- a/setuptools/_distutils/tests/test_build_ext.py +++ b/setuptools/_distutils/tests/test_build_ext.py @@ -493,12 +493,16 @@ class BuildExtTestCase(TempdirManager, # format the target value as defined in the Apple # Availability Macros. We can't use the macro names since # at least one value we test with will not exist yet. - if target[1] < 10: + if target[:2] < (10, 10): # for 10.1 through 10.9.x -> "10n0" target = '%02d%01d0' % target else: # for 10.10 and beyond -> "10nn00" - target = '%02d%02d00' % target + if len(target) >= 2: + target = '%02d%02d00' % target + else: + # 11 and later can have no minor version (11 instead of 11.0) + target = '%02d0000' % target deptarget_ext = Extension( 'deptarget', [deptarget_c], diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index fb34d10..aad5794 100644 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -1350,7 +1350,7 @@ class easy_install(Command): if self.prefix: # Set default install_dir/scripts from --prefix - config_vars = config_vars.copy() + config_vars = dict(config_vars) config_vars['base'] = self.prefix scheme = self.INSTALL_SCHEMES.get(os.name, self.DEFAULT_SCHEME) for attr, val in scheme.items(): -- 2.34.1