From 81d01aa0bdec8f9c2ed85d39b6077572abcda72a Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Fri, 23 Jun 2023 00:01:15 +0200 Subject: [PATCH] Fix PEP 561 editable install test case (#15493) --- mypy/test/testpep561.py | 25 +++++++++++++++++++++++++ test-requirements.txt | 1 - 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/mypy/test/testpep561.py b/mypy/test/testpep561.py index b8a11d7fc8af..da5025faef03 100644 --- a/mypy/test/testpep561.py +++ b/mypy/test/testpep561.py @@ -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: @@ -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) diff --git a/test-requirements.txt b/test-requirements.txt index 0eda843928bf..42c8a08a2b5d 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -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