diff --git a/.github/renovate.json b/.github/renovate.json index 5aa6f16c0cae..8e995a824f5f 100644 --- a/.github/renovate.json +++ b/.github/renovate.json @@ -7,17 +7,6 @@ "pre-commit": { "enabled": true }, - "customManagers": [ - { - "customType": "regex", - "fileMatch": ["^pyproject.toml$"], - "matchStrings": [ - "\\n\\[tool\\.typeshed\\]\\npyright_version\\s*=\\s*(\"|')(?[\\d.]*?)(\"|')\\s*?\\n" - ], - "depNameTemplate": "pyright", - "datasourceTemplate": "npm" - } - ], "packageRules": [ { "groupName": "GitHub Actions", @@ -36,7 +25,7 @@ }, { "groupName": "pytype and pyright", - "matchManagers": ["pip_requirements", "regex"], + "matchManagers": ["pip_requirements"], "matchPackageNames": ["pytype", "pyright"], "description": "Daily update of pyright and pytype", "separateMajorMinor": "false", diff --git a/.github/workflows/meta_tests.yml b/.github/workflows/meta_tests.yml index fe85b1177c63..cca055306b2a 100644 --- a/.github/workflows/meta_tests.yml +++ b/.github/workflows/meta_tests.yml @@ -57,15 +57,15 @@ jobs: - run: curl -LsSf https://astral.sh/uv/install.sh | sh - run: uv pip install -r requirements-tests.txt --system - name: Get pyright version - uses: SebRollen/toml-action@v1.0.2 id: pyright_version - with: - file: "pyproject.toml" - field: "tool.typeshed.pyright_version" + run: | + PYRIGHT_VERSION=$(grep pyright== requirements-tests.txt | cut -d "#" -f 1 | cut -d \; -f 1 | cut -d = -f 3) + echo pyright version: "${PYRIGHT_VERSION}" + echo PYRIGHT_VERSION="${PYRIGHT_VERSION}" >> "${GITHUB_OUTPUT}" - name: Run pyright on typeshed uses: jakebailey/pyright-action@v2 with: - version: ${{ steps.pyright_version.outputs.value }} + version: ${{ steps.pyright_version.outputs.PYRIGHT_VERSION }} python-platform: ${{ matrix.python-platform }} python-version: "3.9" # The Python version to test against. project: ./pyrightconfig.scripts_and_tests.json diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3dc1ce1fa174..ee12c4d8da33 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -128,22 +128,22 @@ jobs: - name: List 3rd-party stub dependencies installed run: uv pip freeze - name: Get pyright version - uses: SebRollen/toml-action@v1.0.2 id: pyright_version - with: - file: "pyproject.toml" - field: "tool.typeshed.pyright_version" + run: | + PYRIGHT_VERSION=$(grep pyright== requirements-tests.txt | cut -d "#" -f 1 | cut -d \; -f 1 | cut -d = -f 3) + echo pyright version: "${PYRIGHT_VERSION}" + echo PYRIGHT_VERSION="${PYRIGHT_VERSION}" >> "${GITHUB_OUTPUT}" - name: Run pyright with basic settings on all the stubs uses: jakebailey/pyright-action@v2 with: - version: ${{ steps.pyright_version.outputs.value }} + version: ${{ steps.pyright_version.outputs.PYRIGHT_VERSION }} python-platform: ${{ matrix.python-platform }} python-version: ${{ matrix.python-version }} annotate: ${{ matrix.python-version == '3.11' && matrix.python-platform == 'Linux' }} # Having each job create the same comment is too noisy. - name: Run pyright with stricter settings on some of the stubs uses: jakebailey/pyright-action@v2 with: - version: ${{ steps.pyright_version.outputs.value }} + version: ${{ steps.pyright_version.outputs.PYRIGHT_VERSION }} python-platform: ${{ matrix.python-platform }} python-version: ${{ matrix.python-version }} annotate: ${{ matrix.python-version == '3.11' && matrix.python-platform == 'Linux' }} # Having each job create the same comment is too noisy. @@ -151,7 +151,7 @@ jobs: - name: Run pyright on the test cases uses: jakebailey/pyright-action@v2 with: - version: ${{ steps.pyright_version.outputs.value }} + version: ${{ steps.pyright_version.outputs.PYRIGHT_VERSION }} python-platform: ${{ matrix.python-platform }} python-version: ${{ matrix.python-version }} annotate: ${{ matrix.python-version == '3.11' && matrix.python-platform == 'Linux' }} # Having each job create the same comment is too noisy. diff --git a/pyproject.toml b/pyproject.toml index 47af90b2c51e..7d080c0abf97 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -149,5 +149,7 @@ extra-standard-library = [ known-first-party = ["parse_metadata", "utils"] [tool.typeshed] +# TODO: Remove once stub_uploader uses requirements.txt to determine +# the version of pyright. pyright_version = "1.1.354" oldest_supported_python = "3.8" diff --git a/requirements-tests.txt b/requirements-tests.txt index 9a822ae0bff4..114ea1e33e01 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -7,6 +7,7 @@ flake8-noqa==1.4.0 # must match .pre-commit-config.yaml flake8-pyi==24.3.0 # must match .pre-commit-config.yaml mypy==1.9.0 pre-commit-hooks==4.5.0 # must match .pre-commit-config.yaml +pyright==1.1.354 pytype==2024.3.11; platform_system != "Windows" and python_version < "3.12" ruff==0.3.0 # must match .pre-commit-config.yaml diff --git a/tests/check_consistent.py b/tests/check_consistent.py index 416735035c55..cdec75dd24f6 100755 --- a/tests/check_consistent.py +++ b/tests/check_consistent.py @@ -25,7 +25,7 @@ # These type checkers and linters must have exact versions in the requirements file to ensure # consistent CI runs. -linters = {"black", "flake8", "flake8-noqa", "flake8-pyi", "ruff", "mypy", "pytype"} +linters = {"black", "flake8", "flake8-noqa", "flake8-pyi", "mypy", "pyright", "pytype", "ruff"} def assert_consistent_filetypes( diff --git a/tests/pyright_test.py b/tests/pyright_test.py index 521beebd467e..45306530ae1c 100755 --- a/tests/pyright_test.py +++ b/tests/pyright_test.py @@ -6,7 +6,7 @@ import sys from pathlib import Path -import tomli +from utils import parse_requirements, print_command _WELL_KNOWN_FILE = Path("tests", "pyright_test.py") @@ -29,12 +29,16 @@ def main() -> None: print("error running npx; is Node.js installed?", file=sys.stderr) sys.exit(1) - with open("pyproject.toml", "rb") as config: - pyright_version: str = tomli.load(config)["tool"]["typeshed"]["pyright_version"] + req = parse_requirements()["pyright"] + spec = str(req.specifier) + pyright_version = spec[2:] + # TODO: We're currently using npx to run pyright, instead of calling the + # version installed into the virtual environment, due to failures on some + # platforms. https://github.com/python/typeshed/issues/11614 os.environ["PYRIGHT_PYTHON_FORCE_VERSION"] = pyright_version command = [npx, f"pyright@{pyright_version}"] + sys.argv[1:] - print("Running:", " ".join(command)) + print_command(command) ret = subprocess.run(command).returncode sys.exit(ret) diff --git a/tests/utils.py b/tests/utils.py index 1501f9c4aeb2..cf608b9b4c28 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -5,7 +5,7 @@ import os import re import sys -from collections.abc import Mapping +from collections.abc import Iterable, Mapping from functools import lru_cache from pathlib import Path from typing import Any, Final, NamedTuple @@ -38,6 +38,12 @@ def strip_comments(text: str) -> str: # ==================================================================== +def print_command(cmd: str | Iterable[str]) -> None: + if not isinstance(cmd, str): + cmd = " ".join(cmd) + print(colored(f"Running: {cmd}", "blue")) + + def print_error(error: str, end: str = "\n", fix_path: tuple[str, str] = ("", "")) -> None: error_split = error.split("\n") old, new = fix_path