Skip to content

Commit 7599077

Browse files
committed
Fix multi-digit version in entry point replacement
Previously, the special case to generate 'pip' and 'easy_install' entry points with the correct Python version (e.g. 'pip3.9' on Python 3.9) only accounted for single-digit version segments, and did not work correctly on Python 3.10 and up. This was missed when Python 3.10 was released because we (accidentally) generated wheels that did not need any such replacements, but was exposed in CPython 3.11.0 since it bundled pip 22.3 generated against Python 3.10.
1 parent ff207cf commit 7599077

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

news/11547.bugfix.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix entry point generation of ``pip.X``, ``pipX.Y``, and ``easy_install-X.Y``
2+
to correctly account for multi-digit Python version segments (e.g. the "11"
3+
part 3.11).

src/pip/_internal/operations/install/wheel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def get_console_script_specs(console: Dict[str, str]) -> List[str]:
325325

326326
scripts_to_generate.append(f"pip{get_major_minor_version()} = {pip_script}")
327327
# Delete any other versioned pip entry points
328-
pip_ep = [k for k in console if re.match(r"pip(\d(\.\d)?)?$", k)]
328+
pip_ep = [k for k in console if re.match(r"pip(\d+(\.\d+)?)?$", k)]
329329
for k in pip_ep:
330330
del console[k]
331331
easy_install_script = console.pop("easy_install", None)
@@ -340,7 +340,7 @@ def get_console_script_specs(console: Dict[str, str]) -> List[str]:
340340
)
341341
# Delete any other versioned easy_install entry points
342342
easy_install_ep = [
343-
k for k in console if re.match(r"easy_install(-\d\.\d)?$", k)
343+
k for k in console if re.match(r"easy_install(-\d+\.\d+)?$", k)
344344
]
345345
for k in easy_install_ep:
346346
del console[k]

tests/unit/test_wheel.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
import os
55
import pathlib
6+
import sys
67
import textwrap
78
from email import message_from_string
89
from pathlib import Path
@@ -22,7 +23,11 @@
2223
from pip._internal.models.scheme import Scheme
2324
from pip._internal.operations.build.wheel_legacy import get_legacy_build_wheel_path
2425
from pip._internal.operations.install import wheel
25-
from pip._internal.operations.install.wheel import InstalledCSVRow, RecordPath
26+
from pip._internal.operations.install.wheel import (
27+
InstalledCSVRow,
28+
RecordPath,
29+
get_console_script_specs,
30+
)
2631
from pip._internal.utils.compat import WINDOWS
2732
from pip._internal.utils.misc import hash_file
2833
from pip._internal.utils.unpacking import unpack_file
@@ -681,3 +686,31 @@ def test_rehash(self, tmpdir: Path) -> None:
681686
h, length = wheel.rehash(os.fspath(self.test_file))
682687
assert length == str(self.test_file_len)
683688
assert h == self.test_file_hash_encoded
689+
690+
691+
def test_get_console_script_specs_replaces_python_version(
692+
monkeypatch: pytest.MonkeyPatch,
693+
) -> None:
694+
# Fake Python version.
695+
monkeypatch.setattr(sys, "version_info", (10, 11))
696+
697+
entry_points = {
698+
"pip": "real_pip",
699+
"pip99": "whatever",
700+
"pip99.88": "whatever",
701+
"easy_install": "real_easy_install",
702+
"easy_install-99.88": "whatever",
703+
# The followings shouldn't be replaced.
704+
"not_pip_or_easy_install-99": "whatever",
705+
"not_pip_or_easy_install-99.88": "whatever",
706+
}
707+
specs = get_console_script_specs(entry_points)
708+
assert specs == [
709+
"pip = real_pip",
710+
"pip10 = real_pip",
711+
"pip10.11 = real_pip",
712+
"easy_install = real_easy_install",
713+
"easy_install-10.11 = real_easy_install",
714+
"not_pip_or_easy_install-99 = whatever",
715+
"not_pip_or_easy_install-99.88 = whatever",
716+
]

0 commit comments

Comments
 (0)