Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions mypy/test/testpep561.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,28 @@ def virtualenv(python_executable: str = sys.executable) -> Iterator[tuple[str, s
yield venv_dir, os.path.abspath(os.path.join(venv_dir, "bin", "python"))


def upgrade_pip(python_executable: str) -> None:
"""Install pip>=21.3.1. Required for editable installs with PEP 660."""
if (
sys.version_info >= (3, 11)
or (3, 10, 3) <= sys.version_info < (3, 11)
or (3, 9, 11) <= sys.version_info < (3, 10)
or (3, 8, 13) <= sys.version_info < (3, 9)
):
# Skip for more recent Python releases which come with pip>=21.3.1
# out of the box - for performance reasons.
return

install_cmd = [python_executable, "-m", "pip", "install", "pip>=21.3.1"]
try:
with filelock.FileLock(pip_lock, timeout=pip_timeout):
proc = subprocess.run(install_cmd, capture_output=True, env=os.environ)
except filelock.Timeout as err:
raise Exception(f"Failed to acquire {pip_lock}") from err
if proc.returncode != 0:
raise Exception(proc.stdout.decode("utf-8") + proc.stderr.decode("utf-8"))


def install_package(
pkg: str, python_executable: str = sys.executable, editable: bool = False
) -> None:
Expand Down Expand Up @@ -93,6 +115,9 @@ def test_pep561(testcase: DataDrivenTestCase) -> None:
assert pkgs, "No packages to install for PEP 561 test?"
with virtualenv(python) as venv:
venv_dir, python_executable = venv
if editable:
# Editable installs with PEP 660 require pip>=21.3
upgrade_pip(python_executable)
for pkg in pkgs:
install_package(pkg, python_executable, editable)

Expand Down
1 change: 0 additions & 1 deletion test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ black==23.3.0 # must match version in .pre-commit-config.yaml
filelock>=3.3.0
isort[colors]==5.12.0; python_version >= "3.8" # must match version in .pre-commit-config.yaml
lxml>=4.9.1; (python_version<'3.11' or sys_platform!='win32') and python_version<'3.12'
pip>=21.3.1
pre-commit
pre-commit-hooks==4.4.0
psutil>=4.0
Expand Down