Skip to content

Commit

Permalink
Fix PEP 561 editable install test case (#15493)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p authored and hauntsaninja committed Jun 24, 2023
1 parent eba351e commit 81d01aa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
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 @@ -8,7 +8,6 @@ flake8-bugbear==23.3.23; python_version >= "3.8" # must match version in .pre-co
flake8-noqa==1.3.1; python_version >= "3.8" # must match version in .pre-commit-config.yaml
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

0 comments on commit 81d01aa

Please sign in to comment.