From 2b64f54008f6dbaded7970336e26c4f02fa82fd9 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Mon, 28 Jun 2021 19:42:27 +0200 Subject: [PATCH] Support @tests/requirements-stubtest.txt files (#5704) --- tests/README.md | 4 ++++ tests/stubtest_third_party.py | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/tests/README.md b/tests/README.md index 1986a2b99..5d5794947 100644 --- a/tests/README.md +++ b/tests/README.md @@ -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`. diff --git a/tests/stubtest_third_party.py b/tests/stubtest_third_party.py index 57b293872..9d726bc08 100755 --- a/tests/stubtest_third_party.py +++ b/tests/stubtest_third_party.py @@ -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