From 9a2838d8dc45e93b28387f5a437f38ec33c1f947 Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Thu, 21 Oct 2021 11:56:04 -0700 Subject: [PATCH] Fix PEP 561 tests for latest pip (#11356) In pip 21.3 the build argument is removed, so this uses an environment variable to still work on older versions. --- mypy/test/testpep561.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/mypy/test/testpep561.py b/mypy/test/testpep561.py index adbbaefb8de4..d30d94c49bee 100644 --- a/mypy/test/testpep561.py +++ b/mypy/test/testpep561.py @@ -62,7 +62,7 @@ def install_package(pkg: str, working_dir = os.path.join(package_path, pkg) with tempfile.TemporaryDirectory() as dir: if use_pip: - install_cmd = [python_executable, '-m', 'pip', 'install', '-b', '{}'.format(dir)] + install_cmd = [python_executable, '-m', 'pip', 'install'] if editable: install_cmd.append('-e') install_cmd.append('.') @@ -72,7 +72,16 @@ def install_package(pkg: str, install_cmd.append('develop') else: install_cmd.append('install') - proc = subprocess.run(install_cmd, cwd=working_dir, stdout=PIPE, stderr=PIPE) + # Note that newer versions of pip (21.3+) don't + # follow this env variable, but this is for compatibility + env = {'PIP_BUILD': dir} + # Inherit environment for Windows + env.update(os.environ) + proc = subprocess.run(install_cmd, + cwd=working_dir, + stdout=PIPE, + stderr=PIPE, + env=env) if proc.returncode != 0: raise Exception(proc.stdout.decode('utf-8') + proc.stderr.decode('utf-8'))