Skip to content

Commit 81d01aa

Browse files
cdce8phauntsaninja
authored andcommitted
Fix PEP 561 editable install test case (#15493)
1 parent eba351e commit 81d01aa

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

mypy/test/testpep561.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,28 @@ def virtualenv(python_executable: str = sys.executable) -> Iterator[tuple[str, s
4646
yield venv_dir, os.path.abspath(os.path.join(venv_dir, "bin", "python"))
4747

4848

49+
def upgrade_pip(python_executable: str) -> None:
50+
"""Install pip>=21.3.1. Required for editable installs with PEP 660."""
51+
if (
52+
sys.version_info >= (3, 11)
53+
or (3, 10, 3) <= sys.version_info < (3, 11)
54+
or (3, 9, 11) <= sys.version_info < (3, 10)
55+
or (3, 8, 13) <= sys.version_info < (3, 9)
56+
):
57+
# Skip for more recent Python releases which come with pip>=21.3.1
58+
# out of the box - for performance reasons.
59+
return
60+
61+
install_cmd = [python_executable, "-m", "pip", "install", "pip>=21.3.1"]
62+
try:
63+
with filelock.FileLock(pip_lock, timeout=pip_timeout):
64+
proc = subprocess.run(install_cmd, capture_output=True, env=os.environ)
65+
except filelock.Timeout as err:
66+
raise Exception(f"Failed to acquire {pip_lock}") from err
67+
if proc.returncode != 0:
68+
raise Exception(proc.stdout.decode("utf-8") + proc.stderr.decode("utf-8"))
69+
70+
4971
def install_package(
5072
pkg: str, python_executable: str = sys.executable, editable: bool = False
5173
) -> None:
@@ -93,6 +115,9 @@ def test_pep561(testcase: DataDrivenTestCase) -> None:
93115
assert pkgs, "No packages to install for PEP 561 test?"
94116
with virtualenv(python) as venv:
95117
venv_dir, python_executable = venv
118+
if editable:
119+
# Editable installs with PEP 660 require pip>=21.3
120+
upgrade_pip(python_executable)
96121
for pkg in pkgs:
97122
install_package(pkg, python_executable, editable)
98123

test-requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ flake8-bugbear==23.3.23; python_version >= "3.8" # must match version in .pre-co
88
flake8-noqa==1.3.1; python_version >= "3.8" # must match version in .pre-commit-config.yaml
99
isort[colors]==5.12.0; python_version >= "3.8" # must match version in .pre-commit-config.yaml
1010
lxml>=4.9.1; (python_version<'3.11' or sys_platform!='win32') and python_version<'3.12'
11-
pip>=21.3.1
1211
pre-commit
1312
pre-commit-hooks==4.4.0
1413
psutil>=4.0

0 commit comments

Comments
 (0)