Skip to content

Commit a899720

Browse files
authored
Install pyright from PyPI (#11575)
1 parent 0ad1501 commit a899720

File tree

8 files changed

+32
-30
lines changed

8 files changed

+32
-30
lines changed

.github/renovate.json

+1-12
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,6 @@
77
"pre-commit": {
88
"enabled": true
99
},
10-
"customManagers": [
11-
{
12-
"customType": "regex",
13-
"fileMatch": ["^pyproject.toml$"],
14-
"matchStrings": [
15-
"\\n\\[tool\\.typeshed\\]\\npyright_version\\s*=\\s*(\"|')(?<currentValue>[\\d.]*?)(\"|')\\s*?\\n"
16-
],
17-
"depNameTemplate": "pyright",
18-
"datasourceTemplate": "npm"
19-
}
20-
],
2110
"packageRules": [
2211
{
2312
"groupName": "GitHub Actions",
@@ -36,7 +25,7 @@
3625
},
3726
{
3827
"groupName": "pytype and pyright",
39-
"matchManagers": ["pip_requirements", "regex"],
28+
"matchManagers": ["pip_requirements"],
4029
"matchPackageNames": ["pytype", "pyright"],
4130
"description": "Daily update of pyright and pytype",
4231
"separateMajorMinor": "false",

.github/workflows/meta_tests.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ jobs:
5757
- run: curl -LsSf https://astral.sh/uv/install.sh | sh
5858
- run: uv pip install -r requirements-tests.txt --system
5959
- name: Get pyright version
60-
uses: SebRollen/[email protected]
6160
id: pyright_version
62-
with:
63-
file: "pyproject.toml"
64-
field: "tool.typeshed.pyright_version"
61+
run: |
62+
PYRIGHT_VERSION=$(grep pyright== requirements-tests.txt | cut -d "#" -f 1 | cut -d \; -f 1 | cut -d = -f 3)
63+
echo pyright version: "${PYRIGHT_VERSION}"
64+
echo PYRIGHT_VERSION="${PYRIGHT_VERSION}" >> "${GITHUB_OUTPUT}"
6565
- name: Run pyright on typeshed
6666
uses: jakebailey/pyright-action@v2
6767
with:
68-
version: ${{ steps.pyright_version.outputs.value }}
68+
version: ${{ steps.pyright_version.outputs.PYRIGHT_VERSION }}
6969
python-platform: ${{ matrix.python-platform }}
7070
python-version: "3.9" # The Python version to test against.
7171
project: ./pyrightconfig.scripts_and_tests.json

.github/workflows/tests.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -130,30 +130,30 @@ jobs:
130130
- name: List 3rd-party stub dependencies installed
131131
run: uv pip freeze
132132
- name: Get pyright version
133-
uses: SebRollen/[email protected]
134133
id: pyright_version
135-
with:
136-
file: "pyproject.toml"
137-
field: "tool.typeshed.pyright_version"
134+
run: |
135+
PYRIGHT_VERSION=$(grep pyright== requirements-tests.txt | cut -d "#" -f 1 | cut -d \; -f 1 | cut -d = -f 3)
136+
echo pyright version: "${PYRIGHT_VERSION}"
137+
echo PYRIGHT_VERSION="${PYRIGHT_VERSION}" >> "${GITHUB_OUTPUT}"
138138
- name: Run pyright with basic settings on all the stubs
139139
uses: jakebailey/pyright-action@v2
140140
with:
141-
version: ${{ steps.pyright_version.outputs.value }}
141+
version: ${{ steps.pyright_version.outputs.PYRIGHT_VERSION }}
142142
python-platform: ${{ matrix.python-platform }}
143143
python-version: ${{ matrix.python-version }}
144144
annotate: ${{ matrix.python-version == '3.11' && matrix.python-platform == 'Linux' }} # Having each job create the same comment is too noisy.
145145
- name: Run pyright with stricter settings on some of the stubs
146146
uses: jakebailey/pyright-action@v2
147147
with:
148-
version: ${{ steps.pyright_version.outputs.value }}
148+
version: ${{ steps.pyright_version.outputs.PYRIGHT_VERSION }}
149149
python-platform: ${{ matrix.python-platform }}
150150
python-version: ${{ matrix.python-version }}
151151
annotate: ${{ matrix.python-version == '3.11' && matrix.python-platform == 'Linux' }} # Having each job create the same comment is too noisy.
152152
project: ./pyrightconfig.stricter.json
153153
- name: Run pyright on the test cases
154154
uses: jakebailey/pyright-action@v2
155155
with:
156-
version: ${{ steps.pyright_version.outputs.value }}
156+
version: ${{ steps.pyright_version.outputs.PYRIGHT_VERSION }}
157157
python-platform: ${{ matrix.python-platform }}
158158
python-version: ${{ matrix.python-version }}
159159
annotate: ${{ matrix.python-version == '3.11' && matrix.python-platform == 'Linux' }} # Having each job create the same comment is too noisy.

pyproject.toml

+2
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,7 @@ extra-standard-library = [
149149
known-first-party = ["parse_metadata", "utils"]
150150

151151
[tool.typeshed]
152+
# TODO: Remove once stub_uploader uses requirements.txt to determine
153+
# the version of pyright.
152154
pyright_version = "1.1.354"
153155
oldest_supported_python = "3.8"

requirements-tests.txt

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ flake8-noqa==1.4.0 # must match .pre-commit-config.yaml
77
flake8-pyi==24.3.0 # must match .pre-commit-config.yaml
88
mypy==1.9.0
99
pre-commit-hooks==4.5.0 # must match .pre-commit-config.yaml
10+
pyright==1.1.354
1011
pytype==2024.3.11; platform_system != "Windows" and python_version < "3.12"
1112
ruff==0.3.0 # must match .pre-commit-config.yaml
1213

tests/check_consistent.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
# These type checkers and linters must have exact versions in the requirements file to ensure
2727
# consistent CI runs.
28-
linters = {"black", "flake8", "flake8-noqa", "flake8-pyi", "ruff", "mypy", "pytype"}
28+
linters = {"black", "flake8", "flake8-noqa", "flake8-pyi", "mypy", "pyright", "pytype", "ruff"}
2929

3030

3131
def assert_consistent_filetypes(

tests/pyright_test.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import sys
77
from pathlib import Path
88

9-
import tomli
9+
from utils import parse_requirements, print_command
1010

1111
_WELL_KNOWN_FILE = Path("tests", "pyright_test.py")
1212

@@ -29,12 +29,16 @@ def main() -> None:
2929
print("error running npx; is Node.js installed?", file=sys.stderr)
3030
sys.exit(1)
3131

32-
with open("pyproject.toml", "rb") as config:
33-
pyright_version: str = tomli.load(config)["tool"]["typeshed"]["pyright_version"]
32+
req = parse_requirements()["pyright"]
33+
spec = str(req.specifier)
34+
pyright_version = spec[2:]
3435

36+
# TODO: We're currently using npx to run pyright, instead of calling the
37+
# version installed into the virtual environment, due to failures on some
38+
# platforms. https://github.com/python/typeshed/issues/11614
3539
os.environ["PYRIGHT_PYTHON_FORCE_VERSION"] = pyright_version
3640
command = [npx, f"pyright@{pyright_version}"] + sys.argv[1:]
37-
print("Running:", " ".join(command))
41+
print_command(command)
3842

3943
ret = subprocess.run(command).returncode
4044
sys.exit(ret)

tests/utils.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import os
66
import re
77
import sys
8-
from collections.abc import Mapping
8+
from collections.abc import Iterable, Mapping
99
from functools import lru_cache
1010
from pathlib import Path
1111
from typing import Any, Final, NamedTuple
@@ -38,6 +38,12 @@ def strip_comments(text: str) -> str:
3838
# ====================================================================
3939

4040

41+
def print_command(cmd: str | Iterable[str]) -> None:
42+
if not isinstance(cmd, str):
43+
cmd = " ".join(cmd)
44+
print(colored(f"Running: {cmd}", "blue"))
45+
46+
4147
def print_error(error: str, end: str = "\n", fix_path: tuple[str, str] = ("", "")) -> None:
4248
error_split = error.split("\n")
4349
old, new = fix_path

0 commit comments

Comments
 (0)