Skip to content

Commit 3e24c65

Browse files
AvasamAlexWaygood
andauthored
Rework how pyright is run in CI to allow for non-types dependencies(#9434)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
1 parent 7c15e69 commit 3e24c65

7 files changed

Lines changed: 49 additions & 4 deletions

File tree

‎.github/workflows/daily.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
- name: Run stubtest
7272
shell: bash
7373
run: |
74-
PACKAGES=$(python tests/get_packages.py)
74+
PACKAGES=$(python tests/get_stubtest_system_requirements.py)
7575
7676
if [ "${{ runner.os }}" = "Linux" ]; then
7777
if [ -n "$PACKAGES" ]; then

‎.github/workflows/stubtest_third_party.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
5959
if [ -n "$STUBS" ]; then
6060
echo "Testing $STUBS..."
61-
PACKAGES=$(python tests/get_packages.py $STUBS)
61+
PACKAGES=$(python tests/get_stubtest_system_requirements.py $STUBS)
6262
6363
if [ "${{ runner.os }}" = "Linux" ]; then
6464
if [ -n "$PACKAGES" ]; then

‎.github/workflows/tests.yml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,20 @@ jobs:
112112
fail-fast: false
113113
steps:
114114
- uses: actions/checkout@v3
115+
- uses: actions/setup-python@v4
116+
with:
117+
python-version: "3.10"
118+
cache: pip
119+
cache-dependency-path: requirements-tests.txt
120+
- name: Install 3rd-party dependencies for stubs packages
121+
run: |
122+
pip install -r requirements-tests.txt
123+
DEPENDENCIES=$(python tests/get_external_stub_requirements.py)
124+
if [ -n "$DEPENDENCIES" ]; then
125+
echo "Installing packages: $DEPENDENCIES"
126+
pip install $DEPENDENCIES
127+
fi
128+
- run: pip freeze --all
115129
- name: Get pyright version
116130
uses: SebRollen/toml-action@v1.0.2
117131
id: pyright_version

‎tests/README.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@ checks that would typically fail on incomplete stubs (such as `Unknown` checks).
7878
In typeshed's CI, pyright is run with these configuration settings on a subset of
7979
the stubs in typeshed (including the standard library).
8080

81+
In order for `pyright_test` to work correctly, some third-party stubs may require
82+
dependencies external to typeshed to be installed in your virtual environment
83+
prior to running the test.
84+
You can list or install all of a stubs package's external dependencies using the following script:
85+
```bash
86+
(.venv3)$ python tests/get_external_stub_requirements.py <third_party_stub> # List external dependencies for <third_party_stub>
87+
(.venv3)$ python tests/get_external_stub_requirements.py <third_party_stub1> <third_party_stub2> # List external dependencies for <third_party_stub1> and <third_party_stub2>
88+
(.venv3)$ python tests/get_external_stub_requirements.py # List external dependencies for all third-party stubs in typeshed
89+
# Install external dependencies for all third-party stubs in typeshed
90+
(.venv3)$ DEPENDENCIES=$(python tests/get_external_stub_requirements.py)
91+
(.venv3)$ if [ -n "$DEPENDENCIES" ]; then pip install $DEPENDENCIES; fi
92+
```
93+
8194
## regr\_test.py
8295

8396
This test runs mypy against the test cases for typeshed's stdlib and third-party
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env python3
2+
from __future__ import annotations
3+
4+
import os
5+
import sys
6+
7+
from utils import read_dependencies
8+
9+
distributions = sys.argv[1:]
10+
if not distributions:
11+
distributions = os.listdir("stubs")
12+
13+
requirements = set[str]()
14+
for distribution in distributions:
15+
requirements.update(read_dependencies(distribution).external_pkgs)
16+
17+
for requirement in sorted(requirements):
18+
print(requirement)

‎tests/utils.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
import subprocess
88
import sys
99
import venv
10-
from collections.abc import Mapping
10+
from collections.abc import Iterable, Mapping
1111
from functools import cache
1212
from pathlib import Path
13-
from typing import Iterable, NamedTuple
13+
from typing import NamedTuple
1414
from typing_extensions import Annotated
1515

1616
import pathspec # type: ignore[import]

0 commit comments

Comments
 (0)