From 2096d1e2ceaf6e66a82976bca4a75715aa0f6389 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sat, 31 Dec 2022 13:12:47 -0500 Subject: [PATCH 01/20] Support external-dependencies in pyright --- .github/workflows/tests.yml | 7 +++++++ tests/get_external_dependencies.py | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 tests/get_external_dependencies.py diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a9905ae1c7ed..6ede88830457 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -112,6 +112,13 @@ jobs: fail-fast: false steps: - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + cache: pip + cache-dependency-path: requirements-tests.txt + - run: pip install tomli + - run: pip install $(python tests/get_external_dependencies.py) - name: Get pyright version uses: SebRollen/toml-action@v1.0.2 id: pyright_version diff --git a/tests/get_external_dependencies.py b/tests/get_external_dependencies.py new file mode 100644 index 000000000000..ac99be90b4c6 --- /dev/null +++ b/tests/get_external_dependencies.py @@ -0,0 +1,16 @@ +#!/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") + +for distribution in distributions: + for package in read_dependencies(distribution).external_pkgs: + print(package) From a2c3bfdaef0db2c245a69f5091ae078dd0432153 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sat, 31 Dec 2022 13:34:55 -0500 Subject: [PATCH 02/20] Conditional install --- .github/workflows/tests.yml | 8 ++++++-- tests/get_external_dependencies.py | 2 +- tests/get_packages.py | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6ede88830457..a6329743c0c2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -117,8 +117,12 @@ jobs: python-version: ${{ matrix.python-version }} cache: pip cache-dependency-path: requirements-tests.txt - - run: pip install tomli - - run: pip install $(python tests/get_external_dependencies.py) + - run: | + DEPENDENCIES=$(python tests/get_external_dependencies.py) + if [ -n "$DEPENDENCIES" ]; then + pip install tomli functools + pip install $DEPENDENCIES + fi - name: Get pyright version uses: SebRollen/toml-action@v1.0.2 id: pyright_version diff --git a/tests/get_external_dependencies.py b/tests/get_external_dependencies.py index ac99be90b4c6..f940be8734f3 100644 --- a/tests/get_external_dependencies.py +++ b/tests/get_external_dependencies.py @@ -13,4 +13,4 @@ for distribution in distributions: for package in read_dependencies(distribution).external_pkgs: - print(package) + print(f"{package} ") diff --git a/tests/get_packages.py b/tests/get_packages.py index bae75ac0bc77..63221b047f17 100755 --- a/tests/get_packages.py +++ b/tests/get_packages.py @@ -14,4 +14,4 @@ for distribution in distributions: with open(f"stubs/{distribution}/METADATA.toml", "rb") as file: for package in tomli.load(file).get("tool", {}).get("stubtest", {}).get(METADATA_MAPPING[platform], []): - print(package) + print(f"{package} ") From 66b85525f78fe54c507c0ea98883d5ad9df1f56d Mon Sep 17 00:00:00 2001 From: Avasam Date: Sat, 31 Dec 2022 13:37:01 -0500 Subject: [PATCH 03/20] install tools first --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a6329743c0c2..2aa19fdb2f5c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -118,9 +118,9 @@ jobs: cache: pip cache-dependency-path: requirements-tests.txt - run: | + pip install tomli functools DEPENDENCIES=$(python tests/get_external_dependencies.py) if [ -n "$DEPENDENCIES" ]; then - pip install tomli functools pip install $DEPENDENCIES fi - name: Get pyright version From 0682f43809925ca6284b67ebf7cf6fc2c67856d0 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sat, 31 Dec 2022 13:46:01 -0500 Subject: [PATCH 04/20] Fallback to lru_cache --- .github/workflows/tests.yml | 2 +- tests/utils.py | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2aa19fdb2f5c..21bf3fd271cc 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -118,7 +118,7 @@ jobs: cache: pip cache-dependency-path: requirements-tests.txt - run: | - pip install tomli functools + pip install tomli DEPENDENCIES=$(python tests/get_external_dependencies.py) if [ -n "$DEPENDENCIES" ]; then pip install $DEPENDENCIES diff --git a/tests/utils.py b/tests/utils.py index cdfba98000b9..fae97818a012 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -8,7 +8,6 @@ import sys import venv from collections.abc import Mapping -from functools import cache from pathlib import Path from typing import NamedTuple from typing_extensions import Annotated @@ -17,14 +16,6 @@ import tomli from packaging.requirements import Requirement -# Used to install system-wide packages for different OS types: -METADATA_MAPPING = {"linux": "apt_dependencies", "darwin": "brew_dependencies", "win32": "choco_dependencies"} - - -def strip_comments(text: str) -> str: - return text.split("#")[0].strip() - - try: from termcolor import colored as colored except ImportError: @@ -33,6 +24,21 @@ def colored(s: str, _: str) -> str: # type: ignore[misc] return s +if sys.version_info >= (3, 9): + from functools import cache +else: + from functools import lru_cache + + cache = lru_cache(maxsize=None) + +# Used to install system-wide packages for different OS types: +METADATA_MAPPING = {"linux": "apt_dependencies", "darwin": "brew_dependencies", "win32": "choco_dependencies"} + + +def strip_comments(text: str) -> str: + return text.split("#")[0].strip() + + def print_error(error: str, end: str = "\n", fix_path: tuple[str, str] = ("", "")) -> None: error_split = error.split("\n") old, new = fix_path From 0a81784d382bf747c796ff66f7927a8fad7ddfa5 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sat, 31 Dec 2022 13:50:23 -0500 Subject: [PATCH 05/20] install typing_extensions --- .github/workflows/tests.yml | 2 +- tests/utils.py | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 21bf3fd271cc..46defbb90c30 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -118,7 +118,7 @@ jobs: cache: pip cache-dependency-path: requirements-tests.txt - run: | - pip install tomli + pip install tomli typing_extensions DEPENDENCIES=$(python tests/get_external_dependencies.py) if [ -n "$DEPENDENCIES" ]; then pip install $DEPENDENCIES diff --git a/tests/utils.py b/tests/utils.py index fae97818a012..bc1cde46bd3b 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -16,6 +16,14 @@ import tomli from packaging.requirements import Requirement +# Used to install system-wide packages for different OS types: +METADATA_MAPPING = {"linux": "apt_dependencies", "darwin": "brew_dependencies", "win32": "choco_dependencies"} + + +def strip_comments(text: str) -> str: + return text.split("#")[0].strip() + + try: from termcolor import colored as colored except ImportError: @@ -31,13 +39,6 @@ def colored(s: str, _: str) -> str: # type: ignore[misc] cache = lru_cache(maxsize=None) -# Used to install system-wide packages for different OS types: -METADATA_MAPPING = {"linux": "apt_dependencies", "darwin": "brew_dependencies", "win32": "choco_dependencies"} - - -def strip_comments(text: str) -> str: - return text.split("#")[0].strip() - def print_error(error: str, end: str = "\n", fix_path: tuple[str, str] = ("", "")) -> None: error_split = error.split("\n") From 1c05a3516e97b10e7f1cc3cc2b97a60442be36d3 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sat, 31 Dec 2022 13:59:34 -0500 Subject: [PATCH 06/20] pathspec + packaging --- .github/workflows/tests.yml | 2 +- tests/utils.py | 25 +++++++++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 46defbb90c30..bf1ce4201d83 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -118,7 +118,7 @@ jobs: cache: pip cache-dependency-path: requirements-tests.txt - run: | - pip install tomli typing_extensions + pip install tomli pathspec packaging DEPENDENCIES=$(python tests/get_external_dependencies.py) if [ -n "$DEPENDENCIES" ]; then pip install $DEPENDENCIES diff --git a/tests/utils.py b/tests/utils.py index bc1cde46bd3b..37f760d4a025 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -7,29 +7,23 @@ import subprocess import sys import venv -from collections.abc import Mapping from pathlib import Path -from typing import NamedTuple -from typing_extensions import Annotated +from typing import TYPE_CHECKING, NamedTuple import pathspec # type: ignore[import] import tomli from packaging.requirements import Requirement -# Used to install system-wide packages for different OS types: -METADATA_MAPPING = {"linux": "apt_dependencies", "darwin": "brew_dependencies", "win32": "choco_dependencies"} - - -def strip_comments(text: str) -> str: - return text.split("#")[0].strip() - +if TYPE_CHECKING: + from collections.abc import Iterable, Mapping + from typing_extensions import Annotated try: from termcolor import colored as colored except ImportError: - def colored(s: str, _: str) -> str: # type: ignore[misc] - return s + def colored(text: str, color: str | None = None, on_color: str | None = None, attrs: Iterable[str] | None = None) -> str: + return text if sys.version_info >= (3, 9): @@ -39,6 +33,13 @@ def colored(s: str, _: str) -> str: # type: ignore[misc] cache = lru_cache(maxsize=None) +# Used to install system-wide packages for different OS types: +METADATA_MAPPING = {"linux": "apt_dependencies", "darwin": "brew_dependencies", "win32": "choco_dependencies"} + + +def strip_comments(text: str) -> str: + return text.split("#")[0].strip() + def print_error(error: str, end: str = "\n", fix_path: tuple[str, str] = ("", "")) -> None: error_split = error.split("\n") From a7315e8bf158b736193e22665013467837e51ab9 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sat, 31 Dec 2022 14:56:56 -0500 Subject: [PATCH 07/20] Fix pyright dep installs - Install all from requirements-tests.txt - lock pyright to specific version - deduplicate dependencies from script - remove extra space --- .github/workflows/tests.yml | 4 ++-- tests/get_external_dependencies.py | 3 +-- tests/get_packages.py | 2 +- tests/utils.py | 7 ++++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index bf1ce4201d83..040769c33986 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -114,11 +114,11 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: - python-version: ${{ matrix.python-version }} + python-version: "3.10" cache: pip cache-dependency-path: requirements-tests.txt - run: | - pip install tomli pathspec packaging + pip install -r requirements-tests.txt DEPENDENCIES=$(python tests/get_external_dependencies.py) if [ -n "$DEPENDENCIES" ]; then pip install $DEPENDENCIES diff --git a/tests/get_external_dependencies.py b/tests/get_external_dependencies.py index f940be8734f3..aea44bde0141 100644 --- a/tests/get_external_dependencies.py +++ b/tests/get_external_dependencies.py @@ -7,10 +7,9 @@ from utils import read_dependencies distributions = sys.argv[1:] - if not distributions: distributions = os.listdir("stubs") for distribution in distributions: for package in read_dependencies(distribution).external_pkgs: - print(f"{package} ") + print(package) diff --git a/tests/get_packages.py b/tests/get_packages.py index 63221b047f17..bae75ac0bc77 100755 --- a/tests/get_packages.py +++ b/tests/get_packages.py @@ -14,4 +14,4 @@ for distribution in distributions: with open(f"stubs/{distribution}/METADATA.toml", "rb") as file: for package in tomli.load(file).get("tool", {}).get("stubtest", {}).get(METADATA_MAPPING[platform], []): - print(f"{package} ") + print(package) diff --git a/tests/utils.py b/tests/utils.py index 37f760d4a025..0af52929121c 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -92,14 +92,15 @@ def read_dependencies(distribution: str) -> PackageDependencies: with Path("stubs", distribution, "METADATA.toml").open("rb") as f: dependencies = tomli.load(f).get("requires", []) assert isinstance(dependencies, list) - typeshed, external = [], [] + typeshed: set[str] = set() + external: set[str] = set() for dependency in dependencies: assert isinstance(dependency, str) maybe_typeshed_dependency = Requirement(dependency).name if maybe_typeshed_dependency in pypi_name_to_typeshed_name_mapping: - typeshed.append(pypi_name_to_typeshed_name_mapping[maybe_typeshed_dependency]) + typeshed.add(pypi_name_to_typeshed_name_mapping[maybe_typeshed_dependency]) else: - external.append(dependency) + external.add(dependency) return PackageDependencies(tuple(typeshed), tuple(external)) From dd9a512d8a89c802fe52cb52600bb1119b73c265 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sat, 31 Dec 2022 15:14:50 -0500 Subject: [PATCH 08/20] Revert lru_cache shim --- tests/utils.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/utils.py b/tests/utils.py index 0af52929121c..659c4d0ab225 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -7,6 +7,8 @@ import subprocess import sys import venv +from collections.abc import Iterable, Mapping +from functools import cache from pathlib import Path from typing import TYPE_CHECKING, NamedTuple @@ -15,7 +17,6 @@ from packaging.requirements import Requirement if TYPE_CHECKING: - from collections.abc import Iterable, Mapping from typing_extensions import Annotated try: @@ -26,13 +27,6 @@ def colored(text: str, color: str | None = None, on_color: str | None = None, at return text -if sys.version_info >= (3, 9): - from functools import cache -else: - from functools import lru_cache - - cache = lru_cache(maxsize=None) - # Used to install system-wide packages for different OS types: METADATA_MAPPING = {"linux": "apt_dependencies", "darwin": "brew_dependencies", "win32": "choco_dependencies"} From 557f87102398dbe4bfca1a9af24bc5858cde4e66 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sat, 31 Dec 2022 17:25:34 -0500 Subject: [PATCH 09/20] Correctly de-duplicate requirements --- tests/get_external_dependencies.py | 7 +++++-- tests/utils.py | 7 +++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/get_external_dependencies.py b/tests/get_external_dependencies.py index aea44bde0141..df86253e3f87 100644 --- a/tests/get_external_dependencies.py +++ b/tests/get_external_dependencies.py @@ -10,6 +10,9 @@ if not distributions: distributions = os.listdir("stubs") +requirements = set[str]() for distribution in distributions: - for package in read_dependencies(distribution).external_pkgs: - print(package) + requirements.update(read_dependencies(distribution).external_pkgs) + +for requirement in sorted(requirements): + print(requirement) diff --git a/tests/utils.py b/tests/utils.py index 659c4d0ab225..76fb5b25bb31 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -86,15 +86,14 @@ def read_dependencies(distribution: str) -> PackageDependencies: with Path("stubs", distribution, "METADATA.toml").open("rb") as f: dependencies = tomli.load(f).get("requires", []) assert isinstance(dependencies, list) - typeshed: set[str] = set() - external: set[str] = set() + typeshed, external = [], [] for dependency in dependencies: assert isinstance(dependency, str) maybe_typeshed_dependency = Requirement(dependency).name if maybe_typeshed_dependency in pypi_name_to_typeshed_name_mapping: - typeshed.add(pypi_name_to_typeshed_name_mapping[maybe_typeshed_dependency]) + typeshed.append(pypi_name_to_typeshed_name_mapping[maybe_typeshed_dependency]) else: - external.add(dependency) + external.append(dependency) return PackageDependencies(tuple(typeshed), tuple(external)) From 8766612e61d542b1ea2260675c56703a1ba3731c Mon Sep 17 00:00:00 2001 From: Avasam Date: Sat, 31 Dec 2022 18:18:21 -0500 Subject: [PATCH 10/20] Update tests/utils.py --- tests/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/utils.py b/tests/utils.py index a6b17c84279a..76fb5b25bb31 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -10,7 +10,7 @@ from collections.abc import Iterable, Mapping from functools import cache from pathlib import Path -from typing import TYPE_CHECKING, Iterable, NamedTuple +from typing import TYPE_CHECKING, NamedTuple import pathspec # type: ignore[import] import tomli From 87324d46a802260bda03553570c1c8faccb8a7b4 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 1 Jan 2023 03:53:57 -0500 Subject: [PATCH 11/20] Revert if TYPE_CHECKING --- tests/utils.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/utils.py b/tests/utils.py index 76fb5b25bb31..a0f0d56ef734 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -10,15 +10,13 @@ from collections.abc import Iterable, Mapping from functools import cache from pathlib import Path -from typing import TYPE_CHECKING, NamedTuple +from typing import NamedTuple +from typing_extensions import Annotated import pathspec # type: ignore[import] import tomli from packaging.requirements import Requirement -if TYPE_CHECKING: - from typing_extensions import Annotated - try: from termcolor import colored as colored except ImportError: From 1ea0b23df9e3beafae437ffe27f74d9248b202cd Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 1 Jan 2023 04:09:22 -0500 Subject: [PATCH 12/20] Add doc about installing deps --- tests/README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/README.md b/tests/README.md index 994ef4d3e046..c0d7e3c65aab 100644 --- a/tests/README.md +++ b/tests/README.md @@ -78,6 +78,13 @@ 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). +Third-party stubs may require non-types dependencies external to typeshed to be installed in your virtual environment. +You can list or install all of a stubs' non-types dependencies using the following script: +```bash +(.venv3)$ python tests/get_external_dependencies.py # List non-types dependencies +(.venv3)$ pip install $(python tests/get_external_dependencies.py ) # Install non-types dependencies +``` + ## regr\_test.py This test runs mypy against the test cases for typeshed's stdlib and third-party From 8dd53a21f46ea2918c98c4719289ffde2d1696ed Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 1 Jan 2023 15:51:17 -0500 Subject: [PATCH 13/20] Apply suggestions from code review Co-authored-by: Alex Waygood --- .github/workflows/tests.yml | 5 ++++- tests/README.md | 8 +++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 040769c33986..5d0c83b1d5a6 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -117,12 +117,15 @@ jobs: python-version: "3.10" cache: pip cache-dependency-path: requirements-tests.txt - - run: | + - name: Install 3rd-party dependencies for stubs packages + run: | pip install -r requirements-tests.txt DEPENDENCIES=$(python tests/get_external_dependencies.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 c0d7e3c65aab..24d9779a7fcd 100644 --- a/tests/README.md +++ b/tests/README.md @@ -78,10 +78,12 @@ 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). -Third-party stubs may require non-types dependencies external to typeshed to be installed in your virtual environment. -You can list or install all of a stubs' non-types dependencies using the following script: +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_dependencies.py # List non-types dependencies +(.venv3)$ python tests/get_external_dependencies.py # List external dependencies for +(.venv3)$ python tests/get_external_dependencies.py # List external dependencies for and +(.venv3)$ python tests/get_external_dependencies.py # List external dependencies for all non stubs packages in typeshed (.venv3)$ pip install $(python tests/get_external_dependencies.py ) # Install non-types dependencies ``` From 807a8f42eb147006ef0c3d23a14cfc0f8dbcf8aa Mon Sep 17 00:00:00 2001 From: Avasam Date: Mon, 2 Jan 2023 16:32:09 -0500 Subject: [PATCH 14/20] Update tests/README.md --- tests/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/README.md b/tests/README.md index 24d9779a7fcd..4ac11d4b3ef5 100644 --- a/tests/README.md +++ b/tests/README.md @@ -84,7 +84,9 @@ You can list or install all of a stubs package's external dependencies using the (.venv3)$ python tests/get_external_dependencies.py # List external dependencies for (.venv3)$ python tests/get_external_dependencies.py # List external dependencies for and (.venv3)$ python tests/get_external_dependencies.py # List external dependencies for all non stubs packages in typeshed -(.venv3)$ pip install $(python tests/get_external_dependencies.py ) # Install non-types dependencies +# Install external dependencies for all non stubs packages in typeshed +(.venv3)$ DEPENDENCIES=$(python tests/get_external_dependencies.py) +(.venv3)$ if [ -n "$DEPENDENCIES" ]; then pip install $DEPENDENCIES; fi ``` ## regr\_test.py From 1ff9c18c53a330fefc2e86b8284190f350b4579b Mon Sep 17 00:00:00 2001 From: Avasam Date: Mon, 2 Jan 2023 16:58:19 -0500 Subject: [PATCH 15/20] Update tests/README.md Co-authored-by: Alex Waygood --- tests/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/README.md b/tests/README.md index 4ac11d4b3ef5..45486bac063b 100644 --- a/tests/README.md +++ b/tests/README.md @@ -84,7 +84,7 @@ You can list or install all of a stubs package's external dependencies using the (.venv3)$ python tests/get_external_dependencies.py # List external dependencies for (.venv3)$ python tests/get_external_dependencies.py # List external dependencies for and (.venv3)$ python tests/get_external_dependencies.py # List external dependencies for all non stubs packages in typeshed -# Install external dependencies for all non stubs packages in typeshed +# Install external dependencies for all third-party stubs packages in typeshed (.venv3)$ DEPENDENCIES=$(python tests/get_external_dependencies.py) (.venv3)$ if [ -n "$DEPENDENCIES" ]; then pip install $DEPENDENCIES; fi ``` From 5abb5e1e606aa04121f381b811f3bd76f975867d Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 2 Jan 2023 22:01:09 +0000 Subject: [PATCH 16/20] Oops another typo --- tests/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/README.md b/tests/README.md index 45486bac063b..6acd1bce445d 100644 --- a/tests/README.md +++ b/tests/README.md @@ -83,7 +83,7 @@ You can list or install all of a stubs package's external dependencies using the ```bash (.venv3)$ python tests/get_external_dependencies.py # List external dependencies for (.venv3)$ python tests/get_external_dependencies.py # List external dependencies for and -(.venv3)$ python tests/get_external_dependencies.py # List external dependencies for all non stubs packages in typeshed +(.venv3)$ python tests/get_external_dependencies.py # List external dependencies for all third-party packages in typeshed # Install external dependencies for all third-party stubs packages in typeshed (.venv3)$ DEPENDENCIES=$(python tests/get_external_dependencies.py) (.venv3)$ if [ -n "$DEPENDENCIES" ]; then pip install $DEPENDENCIES; fi From dfa4085f5d19c2cdaa2903ed7abd53c2ff684805 Mon Sep 17 00:00:00 2001 From: Avasam Date: Mon, 2 Jan 2023 18:58:37 -0500 Subject: [PATCH 17/20] Rename scripts --- .github/workflows/daily.yml | 2 +- .github/workflows/stubtest_third_party.yml | 2 +- .github/workflows/tests.yml | 2 +- tests/README.md | 10 +++++----- ...pendencies.py => get_external_stub_requirements.py} | 0 ...packages.py => get_stubtest_system_requirements.py} | 0 6 files changed, 8 insertions(+), 8 deletions(-) rename tests/{get_external_dependencies.py => get_external_stub_requirements.py} (100%) rename tests/{get_packages.py => get_stubtest_system_requirements.py} (100%) mode change 100755 => 100644 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 5d0c83b1d5a6..615da8940dcf 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -120,7 +120,7 @@ jobs: - name: Install 3rd-party dependencies for stubs packages run: | pip install -r requirements-tests.txt - DEPENDENCIES=$(python tests/get_external_dependencies.py) + DEPENDENCIES=$(python tests/get_external_stub_requirements.py) if [ -n "$DEPENDENCIES" ]; then echo "Installing packages: $DEPENDENCIES" pip install $DEPENDENCIES diff --git a/tests/README.md b/tests/README.md index 6acd1bce445d..03806292b9ae 100644 --- a/tests/README.md +++ b/tests/README.md @@ -81,11 +81,11 @@ 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_dependencies.py # List external dependencies for -(.venv3)$ python tests/get_external_dependencies.py # List external dependencies for and -(.venv3)$ python tests/get_external_dependencies.py # List external dependencies for all third-party packages in typeshed -# Install external dependencies for all third-party stubs packages in typeshed -(.venv3)$ DEPENDENCIES=$(python tests/get_external_dependencies.py) +(.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 ``` diff --git a/tests/get_external_dependencies.py b/tests/get_external_stub_requirements.py similarity index 100% rename from tests/get_external_dependencies.py rename to tests/get_external_stub_requirements.py 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 From b5a249534f1d7a07056c395549b2642ff7d40401 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Tue, 3 Jan 2023 22:08:09 +0000 Subject: [PATCH 18/20] Add some random non-types dependencies to see what happens --- stubs/SQLAlchemy/METADATA.toml | 1 + stubs/SQLAlchemy/sqlalchemy/__init__.pyi | 4 ++++ stubs/caldav/caldav/davclient.pyi | 2 ++ stubs/requests/METADATA.toml | 2 +- stubs/xxhash/METADATA.toml | 1 + stubs/xxhash/xxhash/version.pyi | 3 +++ 6 files changed, 12 insertions(+), 1 deletion(-) diff --git a/stubs/SQLAlchemy/METADATA.toml b/stubs/SQLAlchemy/METADATA.toml index 19ac9f269036..2d3311cd2841 100644 --- a/stubs/SQLAlchemy/METADATA.toml +++ b/stubs/SQLAlchemy/METADATA.toml @@ -1,4 +1,5 @@ version = "1.4.45" +requires = ["rich"] extra_description = """\ The `sqlalchemy-stubs` package is an alternative to this package and also \ includes a mypy plugin for more precise types.\ diff --git a/stubs/SQLAlchemy/sqlalchemy/__init__.pyi b/stubs/SQLAlchemy/sqlalchemy/__init__.pyi index dde3cbce262a..601bb31ca7f6 100644 --- a/stubs/SQLAlchemy/sqlalchemy/__init__.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/__init__.pyi @@ -1,3 +1,5 @@ +import rich + from .engine import ( create_engine as create_engine, create_mock_engine as create_mock_engine, @@ -130,4 +132,6 @@ from .types import ( UnicodeText as UnicodeText, ) +bar = rich.print + __version__: str diff --git a/stubs/caldav/caldav/davclient.pyi b/stubs/caldav/caldav/davclient.pyi index ab99a10c51ac..0576a034b584 100644 --- a/stubs/caldav/caldav/davclient.pyi +++ b/stubs/caldav/caldav/davclient.pyi @@ -4,6 +4,7 @@ from typing import Any from typing_extensions import TypeAlias from urllib.parse import ParseResult, SplitResult +import numpy from requests.auth import AuthBase from requests.models import Response from requests.sessions import _Timeout @@ -13,6 +14,7 @@ from .lib.url import URL from .objects import Calendar, DAVObject, Principal _Element: TypeAlias = Any # actually lxml.etree._Element +foo = numpy.NDArray class DAVResponse: reason: str diff --git a/stubs/requests/METADATA.toml b/stubs/requests/METADATA.toml index 0fe1db2749cc..571aac6a8f99 100644 --- a/stubs/requests/METADATA.toml +++ b/stubs/requests/METADATA.toml @@ -1,5 +1,5 @@ version = "2.28.*" -requires = ["types-urllib3<1.27"] # keep in sync with requests's setup.py +requires = ["types-urllib3<1.27", "numpy"] # keep in sync with requests's setup.py [tool.stubtest] ignore_missing_stub = false diff --git a/stubs/xxhash/METADATA.toml b/stubs/xxhash/METADATA.toml index 07d72516b7bc..f1ae437690a6 100644 --- a/stubs/xxhash/METADATA.toml +++ b/stubs/xxhash/METADATA.toml @@ -1,4 +1,5 @@ version = "3.0.*" +requires = ["pytest"] obsolete_since = "3.1.0" # Released on 2022-10-19 [tool.stubtest] diff --git a/stubs/xxhash/xxhash/version.pyi b/stubs/xxhash/xxhash/version.pyi index b18bf8c3c23b..245ad02a6be6 100644 --- a/stubs/xxhash/xxhash/version.pyi +++ b/stubs/xxhash/xxhash/version.pyi @@ -1,4 +1,7 @@ from _typeshed import Incomplete +import pytest + VERSION: str VERSION_TUPLE: Incomplete +baz = pytest.mark.parametrize From fad4c7cd3f6991c8890e56a1e4afd3d41dbd5d04 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Tue, 3 Jan 2023 22:17:52 +0000 Subject: [PATCH 19/20] Revert "Add some random non-types dependencies to see what happens" This reverts commit b5a249534f1d7a07056c395549b2642ff7d40401. --- stubs/SQLAlchemy/METADATA.toml | 1 - stubs/SQLAlchemy/sqlalchemy/__init__.pyi | 4 ---- stubs/caldav/caldav/davclient.pyi | 2 -- stubs/requests/METADATA.toml | 2 +- stubs/xxhash/METADATA.toml | 1 - stubs/xxhash/xxhash/version.pyi | 3 --- 6 files changed, 1 insertion(+), 12 deletions(-) diff --git a/stubs/SQLAlchemy/METADATA.toml b/stubs/SQLAlchemy/METADATA.toml index 2d3311cd2841..19ac9f269036 100644 --- a/stubs/SQLAlchemy/METADATA.toml +++ b/stubs/SQLAlchemy/METADATA.toml @@ -1,5 +1,4 @@ version = "1.4.45" -requires = ["rich"] extra_description = """\ The `sqlalchemy-stubs` package is an alternative to this package and also \ includes a mypy plugin for more precise types.\ diff --git a/stubs/SQLAlchemy/sqlalchemy/__init__.pyi b/stubs/SQLAlchemy/sqlalchemy/__init__.pyi index 601bb31ca7f6..dde3cbce262a 100644 --- a/stubs/SQLAlchemy/sqlalchemy/__init__.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/__init__.pyi @@ -1,5 +1,3 @@ -import rich - from .engine import ( create_engine as create_engine, create_mock_engine as create_mock_engine, @@ -132,6 +130,4 @@ from .types import ( UnicodeText as UnicodeText, ) -bar = rich.print - __version__: str diff --git a/stubs/caldav/caldav/davclient.pyi b/stubs/caldav/caldav/davclient.pyi index 0576a034b584..ab99a10c51ac 100644 --- a/stubs/caldav/caldav/davclient.pyi +++ b/stubs/caldav/caldav/davclient.pyi @@ -4,7 +4,6 @@ from typing import Any from typing_extensions import TypeAlias from urllib.parse import ParseResult, SplitResult -import numpy from requests.auth import AuthBase from requests.models import Response from requests.sessions import _Timeout @@ -14,7 +13,6 @@ from .lib.url import URL from .objects import Calendar, DAVObject, Principal _Element: TypeAlias = Any # actually lxml.etree._Element -foo = numpy.NDArray class DAVResponse: reason: str diff --git a/stubs/requests/METADATA.toml b/stubs/requests/METADATA.toml index 571aac6a8f99..0fe1db2749cc 100644 --- a/stubs/requests/METADATA.toml +++ b/stubs/requests/METADATA.toml @@ -1,5 +1,5 @@ version = "2.28.*" -requires = ["types-urllib3<1.27", "numpy"] # keep in sync with requests's setup.py +requires = ["types-urllib3<1.27"] # keep in sync with requests's setup.py [tool.stubtest] ignore_missing_stub = false diff --git a/stubs/xxhash/METADATA.toml b/stubs/xxhash/METADATA.toml index f1ae437690a6..07d72516b7bc 100644 --- a/stubs/xxhash/METADATA.toml +++ b/stubs/xxhash/METADATA.toml @@ -1,5 +1,4 @@ version = "3.0.*" -requires = ["pytest"] obsolete_since = "3.1.0" # Released on 2022-10-19 [tool.stubtest] diff --git a/stubs/xxhash/xxhash/version.pyi b/stubs/xxhash/xxhash/version.pyi index 245ad02a6be6..b18bf8c3c23b 100644 --- a/stubs/xxhash/xxhash/version.pyi +++ b/stubs/xxhash/xxhash/version.pyi @@ -1,7 +1,4 @@ from _typeshed import Incomplete -import pytest - VERSION: str VERSION_TUPLE: Incomplete -baz = pytest.mark.parametrize From a89c6818d51b2b5b501b2b092ab6cd215bbca613 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Tue, 3 Jan 2023 22:20:51 +0000 Subject: [PATCH 20/20] Reflow docs to keep line length <90 characters where practical --- tests/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/README.md b/tests/README.md index 03806292b9ae..a064c2913a92 100644 --- a/tests/README.md +++ b/tests/README.md @@ -78,7 +78,9 @@ 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. +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