diff --git a/.github/workflows/daily.yml b/.github/workflows/daily.yml index 6dafad073f13..86c7821c8921 100644 --- a/.github/workflows/daily.yml +++ b/.github/workflows/daily.yml @@ -71,7 +71,7 @@ jobs: - name: Run stubtest shell: bash run: | - PACKAGES=$(python tests/get_packages.py) + PACKAGES=$(python tests/get_stubtest_system_requirements.py) if [ "${{ runner.os }}" = "Linux" ]; then if [ -n "$PACKAGES" ]; then diff --git a/.github/workflows/stubtest_third_party.yml b/.github/workflows/stubtest_third_party.yml index 3e17e2f5b639..b6394cb85157 100644 --- a/.github/workflows/stubtest_third_party.yml +++ b/.github/workflows/stubtest_third_party.yml @@ -58,7 +58,7 @@ jobs: if [ -n "$STUBS" ]; then echo "Testing $STUBS..." - PACKAGES=$(python tests/get_packages.py $STUBS) + PACKAGES=$(python tests/get_stubtest_system_requirements.py $STUBS) if [ "${{ runner.os }}" = "Linux" ]; then if [ -n "$PACKAGES" ]; then diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a9905ae1c7ed..615da8940dcf 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -112,6 +112,20 @@ jobs: fail-fast: false steps: - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: "3.10" + cache: pip + cache-dependency-path: requirements-tests.txt + - name: Install 3rd-party dependencies for stubs packages + run: | + pip install -r requirements-tests.txt + DEPENDENCIES=$(python tests/get_external_stub_requirements.py) + if [ -n "$DEPENDENCIES" ]; then + echo "Installing packages: $DEPENDENCIES" + pip install $DEPENDENCIES + fi + - run: pip freeze --all - name: Get pyright version uses: SebRollen/toml-action@v1.0.2 id: pyright_version diff --git a/tests/README.md b/tests/README.md index 994ef4d3e046..a064c2913a92 100644 --- a/tests/README.md +++ b/tests/README.md @@ -78,6 +78,19 @@ checks that would typically fail on incomplete stubs (such as `Unknown` checks). In typeshed's CI, pyright is run with these configuration settings on a subset of the stubs in typeshed (including the standard library). +In order for `pyright_test` to work correctly, some third-party stubs may require +dependencies external to typeshed to be installed in your virtual environment +prior to running the test. +You can list or install all of a stubs package's external dependencies using the following script: +```bash +(.venv3)$ python tests/get_external_stub_requirements.py # List external dependencies for +(.venv3)$ python tests/get_external_stub_requirements.py # List external dependencies for and +(.venv3)$ python tests/get_external_stub_requirements.py # List external dependencies for all third-party stubs in typeshed +# Install external dependencies for all third-party stubs in typeshed +(.venv3)$ DEPENDENCIES=$(python tests/get_external_stub_requirements.py) +(.venv3)$ if [ -n "$DEPENDENCIES" ]; then pip install $DEPENDENCIES; fi +``` + ## regr\_test.py This test runs mypy against the test cases for typeshed's stdlib and third-party diff --git a/tests/get_external_stub_requirements.py b/tests/get_external_stub_requirements.py new file mode 100644 index 000000000000..df86253e3f87 --- /dev/null +++ b/tests/get_external_stub_requirements.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import os +import sys + +from utils import read_dependencies + +distributions = sys.argv[1:] +if not distributions: + distributions = os.listdir("stubs") + +requirements = set[str]() +for distribution in distributions: + requirements.update(read_dependencies(distribution).external_pkgs) + +for requirement in sorted(requirements): + print(requirement) diff --git a/tests/get_packages.py b/tests/get_stubtest_system_requirements.py old mode 100755 new mode 100644 similarity index 100% rename from tests/get_packages.py rename to tests/get_stubtest_system_requirements.py diff --git a/tests/utils.py b/tests/utils.py index 208bab902108..a0f0d56ef734 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -7,10 +7,10 @@ import subprocess import sys import venv -from collections.abc import Mapping +from collections.abc import Iterable, Mapping from functools import cache from pathlib import Path -from typing import Iterable, NamedTuple +from typing import NamedTuple from typing_extensions import Annotated import pathspec # type: ignore[import]