From efe32727c68db99aea8b2c3efd8fcc8f9b52178f Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Thu, 22 Jun 2023 04:47:19 +0200 Subject: [PATCH 1/3] Revert "Add pip as test requirement for PEP 660 editable installs (#15482)" This reverts commit 7d031beb017450ac990c97e288d064290e3be55f. --- test-requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/test-requirements.txt b/test-requirements.txt index 8aea01f9e996..51cd62d4064c 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -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 From 2efac0dbbe9d5430c8617f75b7f855695a20b7a0 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Thu, 22 Jun 2023 04:46:32 +0200 Subject: [PATCH 2/3] Fix PEP 561 - editable install - test case --- mypy/test/testpep561.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mypy/test/testpep561.py b/mypy/test/testpep561.py index b8a11d7fc8af..bacbcca4ebb2 100644 --- a/mypy/test/testpep561.py +++ b/mypy/test/testpep561.py @@ -46,6 +46,18 @@ 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, version_str: str) -> None: + """Install a newer pip version.""" + install_cmd = [python_executable, "-m", "pip", "install", f"pip{version_str}"] + 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 +105,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, ">=21.3.1") for pkg in pkgs: install_package(pkg, python_executable, editable) From 2e098dea19982ca9ed1dc290edb019b4f0c7d5a6 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Thu, 22 Jun 2023 11:27:05 +0200 Subject: [PATCH 3/3] Performance improvements --- mypy/test/testpep561.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/mypy/test/testpep561.py b/mypy/test/testpep561.py index bacbcca4ebb2..da5025faef03 100644 --- a/mypy/test/testpep561.py +++ b/mypy/test/testpep561.py @@ -46,9 +46,19 @@ 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, version_str: str) -> None: - """Install a newer pip version.""" - install_cmd = [python_executable, "-m", "pip", "install", f"pip{version_str}"] +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) @@ -107,7 +117,7 @@ def test_pep561(testcase: DataDrivenTestCase) -> None: venv_dir, python_executable = venv if editable: # Editable installs with PEP 660 require pip>=21.3 - upgrade_pip(python_executable, ">=21.3.1") + upgrade_pip(python_executable) for pkg in pkgs: install_package(pkg, python_executable, editable)