Install a package from test-data/packages/pkg/
(
pkg: str, python_executable: str = sys.executable, editable: bool = False
)
| 64 | |
| 65 | |
| 66 | def install_package( |
| 67 | pkg: str, python_executable: str = sys.executable, editable: bool = False |
| 68 | ) -> None: |
| 69 | """Install a package from test-data/packages/pkg/""" |
| 70 | working_dir = os.path.join(package_path, pkg) |
| 71 | with tempfile.TemporaryDirectory() as dir: |
| 72 | install_cmd = [python_executable, "-m", "pip", "install"] |
| 73 | if editable: |
| 74 | install_cmd.append("-e") |
| 75 | install_cmd.append(".") |
| 76 | |
| 77 | # Note that newer versions of pip (21.3+) don't |
| 78 | # follow this env variable, but this is for compatibility |
| 79 | env = {"PIP_BUILD": dir} |
| 80 | # Inherit environment for Windows |
| 81 | env.update(os.environ) |
| 82 | try: |
| 83 | with filelock.FileLock(pip_lock, timeout=pip_timeout): |
| 84 | proc = subprocess.run(install_cmd, cwd=working_dir, capture_output=True, env=env) |
| 85 | except filelock.Timeout as err: |
| 86 | raise Exception(f"Failed to acquire {pip_lock}") from err |
| 87 | if proc.returncode != 0: |
| 88 | raise Exception(proc.stdout.decode("utf-8") + proc.stderr.decode("utf-8")) |
| 89 | |
| 90 | |
| 91 | def test_pep561(testcase: DataDrivenTestCase) -> None: |