Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d34ef50

Browse files
authored
Optional pytype install on Windows (no CI) (#12669)
1 parent 3266319 commit d34ef50

8 files changed

Lines changed: 33 additions & 37 deletions

File tree

.github/workflows/meta_tests.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,15 @@ jobs:
5252
- uses: actions/checkout@v4
5353
- uses: actions/setup-python@v5
5454
with:
55-
# Max supported Python version as of pytype 2024.2.27.
56-
python-version: "3.11"
55+
python-version: "3.12"
5756
- run: curl -LsSf https://astral.sh/uv/install.sh | sh
5857
- run: uv pip install -r requirements-tests.txt --system
5958
- name: Run pyright on typeshed
6059
uses: jakebailey/pyright-action@v2
6160
with:
6261
version: PATH
6362
python-platform: ${{ matrix.python-platform }}
64-
python-version: "3.9" # The Python version to test against.
63+
python-version: "3.9" # Oldest version supported for running scripts and tests
6564
project: ./pyrightconfig.scripts_and_tests.json
6665
stubsabot-dry-run:
6766
name: Stubsabot dry run

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
- uses: actions/checkout@v4
4242
- uses: actions/setup-python@v5
4343
with:
44-
# Max supported Python version as of pytype 2024.9.13.
44+
# Max supported Python version as of pytype 2024.9.13
4545
python-version: "3.12"
4646
- name: Install uv
4747
run: curl -LsSf https://astral.sh/uv/install.sh | sh

CONTRIBUTING.md

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ range of Python users and Python codebases. If you're trying a type
55
checker on your Python code, your experience and what you can contribute
66
are important to the project's success.
77

8-
98
## The contribution process at a glance
109

1110
1. [Prepare your environment](#preparing-the-environment).
@@ -51,10 +50,10 @@ please refer to this
5150

5251
Note that some tests require extra setup steps to install the required dependencies.
5352

54-
### Linux/Mac OS
53+
### Linux/Mac OS/WSL
5554

5655
On Linux and Mac OS, you will be able to run the full test suite on Python
57-
3.9, 3.10, or 3.11.
56+
3.9-3.12.
5857
To install the necessary requirements, run the following commands from a
5958
terminal window:
6059

@@ -67,24 +66,22 @@ $ source .venv/bin/activate
6766

6867
### Windows
6968

70-
If you are using a Windows operating system, you will not be able to run the pytype
71-
tests, as pytype
72-
[does not currently support running on Windows](https://github.com/google/pytype#requirements).
73-
One option is to install
74-
[Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/faq),
75-
which will allow you to run the full suite of tests. If you choose to install
76-
WSL, follow the Linux/Mac OS instructions above.
77-
78-
If you do not wish to install WSL, run the following commands from a Windows
79-
terminal to install all non-pytype requirements:
69+
Run the following commands from a Windows terminal to install all requirements:
8070

8171
```powershell
8272
> python -m venv .venv
83-
> .venv\scripts\activate
73+
> .venv\Scripts\activate
8474
(.venv) > pip install -U pip
8575
(.venv) > pip install -r "requirements-tests.txt"
8676
```
8777

78+
To be able to run pytype tests, you'll also need to install it manually
79+
as it's currently excluded from the requirements file:
80+
81+
```powershell
82+
(.venv) > pip install -U pytype
83+
```
84+
8885
## Code formatting
8986

9087
The code is formatted using [`Black`](https://github.com/psf/black).

requirements-tests.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ flake8-pyi==24.6.0 # must match .pre-commit-config.yaml
88
mypy==1.11.1
99
pre-commit-hooks==4.6.0 # must match .pre-commit-config.yaml
1010
pyright==1.1.379
11+
# pytype can be installed on Windows, but requires building wheels, let's not do that on the CI
1112
pytype==2024.9.13; platform_system != "Windows" and python_version < "3.13"
1213
ruff==0.5.4 # must match .pre-commit-config.yaml
1314

tests/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ for this script.
7171

7272
## pytype\_test.py
7373

74-
Note: this test cannot be run on Windows
75-
systems unless you are using Windows Subsystem for Linux.
76-
It also requires a Python version < 3.13 as pytype does not yet support
74+
Note: This test cannot be run on Python version < 3.13 as pytype does not yet support
7775
Python 3.13 and above.
7876

7977
Run using:

tests/pytype_test.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,32 @@
1414

1515
from __future__ import annotations
1616

17+
import sys
18+
from typing import TYPE_CHECKING
19+
20+
if TYPE_CHECKING:
21+
assert sys.platform != "win32", "pytype isn't yet installed in CI, but wheels can be built on Windows"
22+
if sys.version_info >= (3, 13):
23+
print("pytype does not support Python 3.13+ yet.", file=sys.stderr)
24+
sys.exit(1)
25+
26+
1727
import argparse
1828
import importlib.metadata
1929
import inspect
2030
import os
21-
import sys
2231
import traceback
2332
from collections.abc import Iterable, Sequence
2433

2534
from packaging.requirements import Requirement
2635

27-
from _metadata import read_dependencies
28-
from _utils import SupportedVersionsDict, parse_stdlib_versions_file, supported_versions_for_module
29-
30-
if sys.platform == "win32":
31-
print("pytype does not support Windows.", file=sys.stderr)
32-
sys.exit(1)
33-
if sys.version_info >= (3, 13):
34-
print("pytype does not support Python 3.13+ yet.", file=sys.stderr)
35-
sys.exit(1)
36-
3736
# pytype is not py.typed https://github.com/google/pytype/issues/1325
3837
from pytype import config as pytype_config, load_pytd # type: ignore[import]
3938
from pytype.imports import typeshed # type: ignore[import]
4039

40+
from _metadata import read_dependencies
41+
from _utils import SupportedVersionsDict, parse_stdlib_versions_file, supported_versions_for_module
42+
4143
TYPESHED_SUBDIRS = ["stdlib", "stubs"]
4244
TYPESHED_HOME = "TYPESHED_HOME"
4345
_LOADERS = {}

tests/runtests.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import re
88
import subprocess
99
import sys
10+
from importlib.util import find_spec
1011
from pathlib import Path
1112
from typing import Any
1213

@@ -127,11 +128,11 @@ def main() -> None:
127128
else:
128129
print(colored("\nSkipping stubtest since mypy failed.", "yellow"))
129130

130-
if sys.platform == "win32":
131-
print(colored("\nSkipping pytype on Windows. You can run the test with WSL.", "yellow"))
132-
else:
131+
if find_spec("pytype"):
133132
print("\nRunning pytype...")
134133
pytype_result = subprocess.run([sys.executable, "tests/pytype_test.py", path])
134+
else:
135+
print(colored("\nSkipping pytype on Windows. You need to install it first: `pip install pytype`.", "yellow"))
135136

136137
cases_path = test_cases_path(stub if folder == "stubs" else "stdlib")
137138
if not cases_path.exists():

tests/typecheck_typeshed.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ def run_mypy_as_subprocess(directory: str, platform: str, version: str) -> Retur
6969
"--custom-typeshed-dir",
7070
".",
7171
]
72-
if directory == "tests" and platform == "win32":
73-
command.extend(["--exclude", "tests/pytype_test.py"])
7472
result = subprocess.run(command, capture_output=True, text=True)
7573
if result.stderr:
7674
print_error(result.stderr)

0 commit comments

Comments
 (0)