summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2022-01-07 20:12:03 -0500
committerGitHub <noreply@github.com>2022-01-07 20:12:03 -0500
commit9f37366aab9cd8f6baa23e6a77cfdb8daf97757e (patch)
treedd6519d30c030e59ee6d684de2d79e178468fca6
parenta4c549dc8df0fd3f768283b5fdd7c90ab7cac43d (diff)
parenta257f0cb1f960e1d37933c5009da39a49a4622bc (diff)
downloadpython-setuptools-git-9f37366aab9cd8f6baa23e6a77cfdb8daf97757e.tar.gz
Merge pull request #2953 from liuzhe-lz/main
Fixed a bug that easy install incorrectly parsed Python 3.10 version string
-rw-r--r--changelog.d/2953.change.rst1
-rw-r--r--setuptools/command/easy_install.py4
-rw-r--r--setuptools/tests/test_easy_install.py49
3 files changed, 52 insertions, 2 deletions
diff --git a/changelog.d/2953.change.rst b/changelog.d/2953.change.rst
new file mode 100644
index 00000000..bc06b045
--- /dev/null
+++ b/changelog.d/2953.change.rst
@@ -0,0 +1 @@
+Fixed a bug that easy install incorrectly parsed Python 3.10 version string.
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py
index aad5794a..a2962a7d 100644
--- a/setuptools/command/easy_install.py
+++ b/setuptools/command/easy_install.py
@@ -243,8 +243,8 @@ class easy_install(Command):
'dist_version': self.distribution.get_version(),
'dist_fullname': self.distribution.get_fullname(),
'py_version': py_version,
- 'py_version_short': py_version[0:3],
- 'py_version_nodot': py_version[0] + py_version[2],
+ 'py_version_short': f'{sys.version_info.major}.{sys.version_info.minor}',
+ 'py_version_nodot': f'{sys.version_info.major}{sys.version_info.minor}',
'sys_prefix': prefix,
'prefix': prefix,
'sys_exec_prefix': exec_prefix,
diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py
index 6840d03b..4a2c2537 100644
--- a/setuptools/tests/test_easy_install.py
+++ b/setuptools/tests/test_easy_install.py
@@ -17,6 +17,8 @@ import time
import re
import subprocess
import pathlib
+import warnings
+from collections import namedtuple
import pytest
from jaraco import path
@@ -1058,3 +1060,50 @@ class TestWindowsScriptWriter:
hdr = hdr.rstrip('\n')
# header should not start with an escaped quote
assert not hdr.startswith('\\"')
+
+
+VersionStub = namedtuple("VersionStub", "major, minor, micro, releaselevel, serial")
+
+
+@pytest.mark.skipif(
+ os.name == 'nt',
+ reason='Installation schemes for Windows may use values for interpolation '
+ 'that come directly from sysconfig and are difficult to patch/mock'
+)
+def test_use_correct_python_version_string(tmpdir, tmpdir_cwd, monkeypatch):
+ # In issue #3001, easy_install wrongly uses the `python3.1` directory
+ # when the interpreter is `python3.10` and the `--user` option is given.
+ # See pypa/setuptools#3001.
+ dist = Distribution()
+ cmd = dist.get_command_obj('easy_install')
+ cmd.args = ['ok']
+ cmd.optimize = 0
+ cmd.user = True
+ cmd.install_userbase = str(tmpdir)
+ cmd.install_usersite = None
+ install_cmd = dist.get_command_obj('install')
+ install_cmd.install_userbase = str(tmpdir)
+ install_cmd.install_usersite = None
+
+ with monkeypatch.context() as patch, warnings.catch_warnings():
+ warnings.simplefilter("ignore")
+ version = '3.10.1 (main, Dec 21 2021, 09:17:12) [GCC 10.2.1 20210110]'
+ info = VersionStub(3, 10, 1, "final", 0)
+ patch.setattr('site.ENABLE_USER_SITE', True)
+ patch.setattr('sys.version', version)
+ patch.setattr('sys.version_info', info)
+ patch.setattr(cmd, 'create_home_path', mock.Mock())
+ cmd.finalize_options()
+
+ if os.getenv('SETUPTOOLS_USE_DISTUTILS', 'local') == 'local':
+ # Installation schemes in stdlib distutils might be outdated/bugged
+ name = "pypy" if hasattr(sys, 'pypy_version_info') else "python"
+ install_dir = cmd.install_dir.lower()
+ assert f"{name}3.10" in install_dir or f"{name}310" in install_dir
+
+ # The following "variables" are used for interpolation in distutils
+ # installation schemes, so it should be fair to treat them as "semi-public",
+ # or at least public enough so we can have a test to make sure they are correct
+ assert cmd.config_vars['py_version'] == '3.10.1'
+ assert cmd.config_vars['py_version_short'] == '3.10'
+ assert cmd.config_vars['py_version_nodot'] == '310'