Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install and run pytype on Windows and Python 3.12 #12547

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/meta_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,15 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
# Max supported Python version as of pytype 2024.2.27.
python-version: "3.11"
python-version: "3.12"
- run: curl -LsSf https://astral.sh/uv/install.sh | sh
- run: uv pip install -r requirements-tests.txt --system
- name: Run pyright on typeshed
uses: jakebailey/pyright-action@v2
with:
version: PATH
python-platform: ${{ matrix.python-platform }}
python-version: "3.9" # The Python version to test against.
python-version: "3.9" # Oldest version supported for running scripts and tests
project: ./pyrightconfig.scripts_and_tests.json
stubsabot-dry-run:
name: Stubsabot dry run
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
# Max supported Python version as of pytype 2024.2.27.
python-version: "3.11"
python-version: "3.12"
- name: Install uv
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- run: uv pip install -r requirements-tests.txt --system
Expand Down
18 changes: 4 additions & 14 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ range of Python users and Python codebases. If you're trying a type
checker on your Python code, your experience and what you can contribute
are important to the project's success.


## The contribution process at a glance

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

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

### Linux/Mac OS
### Linux/Mac OS/WSL

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

Expand All @@ -67,20 +66,11 @@ $ source .venv/bin/activate

### Windows

If you are using a Windows operating system, you will not be able to run the pytype
tests, as pytype
[does not currently support running on Windows](https://github.com/google/pytype#requirements).
One option is to install
[Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/faq),
which will allow you to run the full suite of tests. If you choose to install
WSL, follow the Linux/Mac OS instructions above.

If you do not wish to install WSL, run the following commands from a Windows
terminal to install all non-pytype requirements:
Run the following commands from a Windows terminal to install all requirements:

```powershell
> python -m venv .venv
> .venv\scripts\activate
> .venv\Scripts\activate
(.venv) > pip install -U pip
(.venv) > pip install -r "requirements-tests.txt"
```
Expand Down
1 change: 1 addition & 0 deletions requirements-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mypy==1.11.1
pre-commit-hooks==4.6.0 # must match .pre-commit-config.yaml
pyright==1.1.379
pytype==2024.4.11; platform_system != "Windows" and python_version < "3.12"
pytype @ git+https://github.com/google/pytype.git@bd2e0b3#egg=pytype ; (platform_system == "Windows" and python_version <= "3.12") or python_version == "3.12"
ruff==0.5.4 # must match .pre-commit-config.yaml

# Libraries used by our various scripts.
Expand Down
5 changes: 0 additions & 5 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ for this script.

## pytype\_test.py

Note: this test cannot be run on Windows
systems unless you are using Windows Subsystem for Linux.
It also requires a Python version < 3.11 as pytype does not yet support
Python 3.11 and above.

Run using:
```bash
(.venv3)$ python3 tests/pytype_test.py
Expand Down
6 changes: 4 additions & 2 deletions tests/check_typeshed_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,11 @@ def check_requirement_pins() -> None:
for package in linters:
assert package in requirements, f"type checker/linter '{package}' not found in {REQS_FILE}"
spec = requirements[package].specifier
assert len(spec) == 1, f"type checker/linter '{package}' has complex specifier in {REQS_FILE}"
if package != "pytype": # Temporarily allow complex specification for pytype
assert len(spec) == 1, f"type checker/linter '{package}' has complex specifier in {REQS_FILE}"
url = requirements[package].url
msg = f"type checker/linter '{package}' is not pinned to an exact version in {REQS_FILE}"
assert str(spec).startswith("=="), msg
assert str(spec).startswith("==") or "@" in str(url), msg
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds support to target a specific git commit for install. But won't be necessary once an actual pytype version releases.



if __name__ == "__main__":
Expand Down
9 changes: 9 additions & 0 deletions tests/pytype_exclude_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
stdlib/builtins.pyi
stdlib/typing.pyi

# References modules not available on Python 3.12 (distutils and asyncore)
stdlib/asynchat.pyi
stdlib/distutils/cmd.pyi
stdlib/distutils/command/__init__.pyi
stdlib/distutils/command/build_py.pyi
stdlib/distutils/command/build_scripts.pyi
stdlib/distutils/cygwinccompiler.pyi
stdlib/smtpd.pyi

Avasam marked this conversation as resolved.
Show resolved Hide resolved
# errors about import statements
stubs/mysqlclient/MySQLdb/__init__.pyi
stubs/mysqlclient/MySQLdb/connections.pyi
Expand Down
12 changes: 3 additions & 9 deletions tests/pytype_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import argparse
import importlib.metadata
import importlib.util
import inspect
import os
import sys
Expand All @@ -24,19 +25,12 @@

from packaging.requirements import Requirement

from _metadata import read_dependencies

if sys.platform == "win32":
print("pytype does not support Windows.", file=sys.stderr)
sys.exit(1)
if sys.version_info >= (3, 12):
print("pytype does not support Python 3.12+ yet.", file=sys.stderr)
sys.exit(1)

# pytype is not py.typed https://github.com/google/pytype/issues/1325
from pytype import config as pytype_config, load_pytd # type: ignore[import]
from pytype.imports import typeshed # type: ignore[import]

from _metadata import read_dependencies

TYPESHED_SUBDIRS = ["stdlib", "stubs"]
TYPESHED_HOME = "TYPESHED_HOME"
_LOADERS = {}
Expand Down
12 changes: 3 additions & 9 deletions tests/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,8 @@ def main() -> None:
else:
print(colored("\nSkipping stubtest since mypy failed.", "yellow"))

if sys.platform == "win32":
print(colored("\nSkipping pytype on Windows. You can run the test with WSL.", "yellow"))
else:
print("\nRunning pytype...")
pytype_result = subprocess.run([sys.executable, "tests/pytype_test.py", path])
print("\nRunning pytype...")
pytype_result = subprocess.run([sys.executable, "tests/pytype_test.py", path])

cases_path = test_cases_path(stub if folder == "stubs" else "stdlib")
if not cases_path.exists():
Expand Down Expand Up @@ -214,10 +211,7 @@ def main() -> None:
print("stubtest:", _SKIPPED)
else:
print("stubtest:", _SUCCESS if stubtest_result.returncode == 0 else _FAILED)
if not pytype_result:
print("pytype:", _SKIPPED)
else:
print("pytype:", _SUCCESS if pytype_result.returncode == 0 else _FAILED)
print("pytype:", _SUCCESS if pytype_result.returncode == 0 else _FAILED)
if pyright_testcases_skipped:
print("Pyright regression tests:", _SKIPPED)
else:
Expand Down
2 changes: 0 additions & 2 deletions tests/typecheck_typeshed.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ def run_mypy_as_subprocess(directory: str, platform: str, version: str) -> Retur
"--custom-typeshed-dir",
".",
]
if directory == "tests" and platform == "win32":
command.extend(["--exclude", "tests/pytype_test.py"])
result = subprocess.run(command, capture_output=True, text=True)
if result.stderr:
print_error(result.stderr)
Expand Down