Support @tests/requirements-stubtest.txt files (#5704)

This commit is contained in:
Sebastian Rittau
2021-06-28 19:42:27 +02:00
committed by GitHub
parent 6b8f047b05
commit 2b64f54008
2 changed files with 16 additions and 0 deletions

View File

@@ -113,3 +113,7 @@ check on the command line:
```
(.venv3)$ python3 tests/stubtest_third_party.py Pillow toml # check stubs/Pillow and stubs/toml
```
For each distribution, stubtest ignores definitions listed in a `@tests/stubtest_allowlist.txt` file,
relative to the distribution. Additional packages that are needed to run stubtest for a
distribution can be added to `@tests/requirements-stubtest.txt`.

View File

@@ -53,6 +53,18 @@ def run_stubtest(dist: Path) -> None:
else:
dist_req = f"{dist.name}=={dist_version}.*"
# If @tests/requirements-stubtest.txt exists, run "pip install" on it.
req_path = dist / "@tests" / "requirements-stubtest.txt"
if req_path.exists():
try:
pip_cmd = [pip_exe, "install", "-r", str(req_path)]
subprocess.run(pip_cmd, check=True, capture_output=True)
except subprocess.CalledProcessError as e:
print(f"Failed to install requirements for {dist.name}", file=sys.stderr)
print(e.stdout.decode(), file=sys.stderr)
print(e.stderr.decode(), file=sys.stderr)
raise
# We need stubtest to be able to import the package, so install mypy into the venv
# Hopefully mypy continues to not need too many dependencies
# TODO: Maybe find a way to cache these in CI