From: JinWang An Date: Mon, 27 Mar 2023 08:02:42 +0000 (+0900) Subject: Imported Upstream version 60.3.1 X-Git-Tag: upstream/60.3.1^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f57f576cd92bedf5d3e08374fdd8ea4a26dee430;p=platform%2Fupstream%2Fpython-setuptools.git Imported Upstream version 60.3.1 --- diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 36b7126..ca91c30 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 60.3.0 +current_version = 60.3.1 commit = True tag = True diff --git a/CHANGES.rst b/CHANGES.rst index 51fab99..2c52ecf 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,12 @@ +v60.3.1 +------- + + +Misc +^^^^ +* #3002: Suppress AttributeError when detecting get-pip. + + v60.3.0 ------- diff --git a/_distutils_hack/__init__.py b/_distutils_hack/__init__.py index 4745f8b..75bc446 100644 --- a/_distutils_hack/__init__.py +++ b/_distutils_hack/__init__.py @@ -73,6 +73,17 @@ def do_override(): ensure_local_distutils() +class suppress(contextlib.suppress, contextlib.ContextDecorator): + """ + A version of contextlib.suppress with decorator support. + + >>> @suppress(KeyError) + ... def key_error(): + ... {}[''] + >>> key_error() + """ + + class DistutilsMetaFinder: def find_spec(self, fullname, path, target=None): if path is not None: @@ -133,6 +144,7 @@ class DistutilsMetaFinder: ) @classmethod + @suppress(AttributeError) def is_get_pip(cls): """ Detect if get-pip is being invoked. Ref #2993. diff --git a/setup.cfg b/setup.cfg index 0af9cd5..a726d2f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = setuptools -version = 60.3.0 +version = 60.3.1 author = Python Packaging Authority author_email = distutils-sig@python.org description = Easily download, build, install, upgrade, and uninstall Python packages diff --git a/setuptools/tests/test_distutils_adoption.py b/setuptools/tests/test_distutils_adoption.py index 27759b1..1e73f9a 100644 --- a/setuptools/tests/test_distutils_adoption.py +++ b/setuptools/tests/test_distutils_adoption.py @@ -42,12 +42,24 @@ def popen_text(call): if sys.version_info < (3, 7) else functools.partial(call, text=True) +def win_sr(env): + """ + On Windows, SYSTEMROOT must be present to avoid + + > Fatal Python error: _Py_HashRandomization_Init: failed to + > get random numbers to initialize Python + """ + if env is None: + return + if platform.system() == 'Windows': + env['SYSTEMROOT'] = os.environ['SYSTEMROOT'] + return env + + def find_distutils(venv, imports='distutils', env=None, **kwargs): py_cmd = 'import {imports}; print(distutils.__file__)'.format(**locals()) cmd = ['python', '-c', py_cmd] - if platform.system() == 'Windows': - env['SYSTEMROOT'] = os.environ['SYSTEMROOT'] - return popen_text(venv.run)(cmd, env=env, **kwargs) + return popen_text(venv.run)(cmd, env=win_sr(env), **kwargs) def count_meta_path(venv, env=None): @@ -58,7 +70,7 @@ def count_meta_path(venv, env=None): print(len(list(filter(is_distutils, sys.meta_path)))) """) cmd = ['python', '-c', py_cmd] - return int(popen_text(venv.run)(cmd, env=env)) + return int(popen_text(venv.run)(cmd, env=win_sr(env))) def test_distutils_stdlib(venv): @@ -89,3 +101,12 @@ def test_distutils_local(venv): env = dict(SETUPTOOLS_USE_DISTUTILS='local') assert venv.name in find_distutils(venv, env=env).split(os.sep) assert count_meta_path(venv, env=env) <= 1 + + +def test_pip_import(venv): + """ + Ensure pip can be imported. + Regression test for #3002. + """ + cmd = ['python', '-c', 'import pip'] + popen_text(venv.run)(cmd)