Skip to content

Commit 8e2fb78

Browse files
AvasamAlexWaygood
authored and
Juan Amari
committed
Support third-party stub external dependencies in pytype (python#9449)
Co-authored-by: Alex Waygood <[email protected]>
1 parent 81a73ea commit 8e2fb78

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

.github/workflows/tests.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ jobs:
6969
cache: pip
7070
cache-dependency-path: requirements-tests.txt
7171
- run: pip install -r requirements-tests.txt
72+
- name: Install external dependencies for 3rd-party stubs
73+
run: |
74+
DEPENDENCIES=$(python tests/get_external_stub_requirements.py)
75+
if [ -n "$DEPENDENCIES" ]; then
76+
echo "Installing packages: $DEPENDENCIES"
77+
pip install $DEPENDENCIES
78+
fi
79+
- run: pip freeze --all
7280
- run: ./tests/pytype_test.py --print-stderr
7381

7482
mypy:
@@ -117,7 +125,7 @@ jobs:
117125
python-version: "3.10"
118126
cache: pip
119127
cache-dependency-path: requirements-tests.txt
120-
- name: Install 3rd-party dependencies for stubs packages
128+
- name: Install external dependencies for 3rd-party stubs
121129
run: |
122130
pip install -r requirements-tests.txt
123131
DEPENDENCIES=$(python tests/get_external_stub_requirements.py)

CONTRIBUTING.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ virtual environment. If you're not familiar with what it is and how it works,
4646
please refer to this
4747
[documentation](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/).
4848

49+
Note that some tests require extra setup steps to install the required dependencies.
50+
4951
### Linux/Mac OS
5052

51-
On Linux and Mac OS, you will be able to run the full test suite on Python 3.8,
53+
On Linux and Mac OS, you will be able to run the full test suite on Python
5254
3.9 or 3.10.
5355
To install the necessary requirements, run the following commands from a
5456
terminal window:

tests/README.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,20 @@ objects at runtime.
1717
in the `tests` and `scripts` directories.
1818

1919
To run the tests, follow the [setup instructions](../CONTRIBUTING.md#preparing-the-environment)
20-
in the `CONTRIBUTING.md` document. In particular, we recommend running with Python 3.9+.
20+
in the `CONTRIBUTING.md` document. In particular, you have to run with Python 3.9+.
21+
22+
In order for `pytype_test` and `pyright_test` to work correctly, some third-party stubs
23+
may require extra dependencies external to typeshed to be installed in your virtual environment
24+
prior to running the test.
25+
You can list or install all of a stubs package's external dependencies using the following script:
26+
```bash
27+
(.venv3)$ python tests/get_external_stub_requirements.py <third_party_stub> # List external dependencies for <third_party_stub>
28+
(.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>
29+
(.venv3)$ python tests/get_external_stub_requirements.py # List external dependencies for all third-party stubs in typeshed
30+
# Install external dependencies for all third-party stubs in typeshed
31+
(.venv3)$ DEPENDENCIES=$(python tests/get_external_stub_requirements.py)
32+
(.venv3)$ if [ -n "$DEPENDENCIES" ]; then pip install $DEPENDENCIES; fi
33+
```
2134

2235
## Run all tests for a specific stub
2336

@@ -78,19 +91,6 @@ checks that would typically fail on incomplete stubs (such as `Unknown` checks).
7891
In typeshed's CI, pyright is run with these configuration settings on a subset of
7992
the stubs in typeshed (including the standard library).
8093

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-
9494
## regr\_test.py
9595

9696
This test runs mypy against the test cases for typeshed's stdlib and third-party

0 commit comments

Comments
 (0)