Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
15 changes: 6 additions & 9 deletions .github/workflows/daily.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- cron: "0 0 * * *"
pull_request:
paths:
- "requirements-tests.txt"
- "pyproject.toml"
- ".github/workflows/daily.yml"

# Please keep the permissions minimal, as stubtest runs arbitrary code from pypi.
Expand Down Expand Up @@ -45,14 +45,11 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: requirements-tests.txt
cache-dependency-path: pyproject.toml
allow-prereleases: true
check-latest: true
- name: Install dependencies
run: pip install -r requirements-tests.txt
# Temporary to get @disjoint_base support; can remove once mypy 1.18 is released
- name: Install mypy from git
run: pip install git+https://github.com/python/mypy.git@116b92bae7b5dbf5e6bd36fd9b0c6804973e5554
run: pip install --group=dev
- name: Run stubtest
run: python tests/stubtest_stdlib.py

Expand All @@ -72,10 +69,10 @@ jobs:
python-version: "3.13"
cache: pip
cache-dependency-path: |
requirements-tests.txt
pyproject.toml
stubs/**/METADATA.toml
- name: Install dependencies
run: pip install -r requirements-tests.txt
run: pip install --group=dev
- name: Install required system packages
shell: bash
run: |
Expand Down Expand Up @@ -128,7 +125,7 @@ jobs:
python-version: "3.13"
- uses: astral-sh/setup-uv@v6
with:
version-file: "typeshed/requirements-tests.txt"
version-file: "typeshed/pyproject.toml"
- name: Run tests
run: |
cd stub_uploader
Expand Down
13 changes: 6 additions & 7 deletions .github/workflows/meta_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ on:
- "tests/**"
- "lib/**"
- ".github/workflows/meta_tests.yml"
- "requirements-tests.txt"
- "pyproject.toml"

permissions:
Expand Down Expand Up @@ -41,8 +40,8 @@ jobs:
python-version: "3.13"
- uses: astral-sh/setup-uv@v6
with:
version-file: "requirements-tests.txt"
- run: uv pip install -r requirements-tests.txt --system
version-file: "pyproject.toml"
- run: uv pip install --group=dev --system
- run: python ./tests/typecheck_typeshed.py --platform=${{ matrix.platform }}
pyright:
name: Check scripts and tests with pyright
Expand All @@ -58,8 +57,8 @@ jobs:
python-version: "3.13"
- uses: astral-sh/setup-uv@v6
with:
version-file: "requirements-tests.txt"
- run: uv pip install -r requirements-tests.txt --system
version-file: "pyproject.toml"
- run: uv pip install --group=dev --system
- name: Run pyright on typeshed
uses: jakebailey/pyright-action@v2
with:
Expand All @@ -77,10 +76,10 @@ jobs:
python-version: "3.13"
- uses: astral-sh/setup-uv@v6
with:
version-file: "requirements-tests.txt"
version-file: "pyproject.toml"
- name: Git config
run: |
git config --global user.name stubsabot
git config --global user.email '<>'
- run: uv pip install -r requirements-tests.txt --system
- run: uv pip install --group=dev --system
- run: python scripts/stubsabot.py --action-level local
4 changes: 2 additions & 2 deletions .github/workflows/mypy_primer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ jobs:
with:
python-version: "3.13"
- name: Install dependencies
run: pip install git+https://github.com/hauntsaninja/mypy_primer.git
run: pip install git+https://github.com/hauntsaninja/mypy_primer.git dependency-groups
- name: Run mypy_primer
shell: bash
run: |
cd typeshed_to_test
MYPY_VERSION=$(grep mypy== requirements-tests.txt | cut -d = -f 3)
MYPY_VERSION=$(python3 -m dependency_groups dev | grep mypy== | cut -d = -f3)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

An alternative that is less "correct" but doesn't depend on dependency_groups and is still pretty solid to random spaces

Suggested change
MYPY_VERSION=$(python3 -m dependency_groups dev | grep mypy== | cut -d = -f3)
MYPY_VERSION=$(grep -E 'mypy\s+?==' pyproject.toml | awk -F '[ ="]+' '{print $3}')

echo "new commit"
git rev-list --format=%s --max-count=1 $GITHUB_SHA
git checkout -b upstream_main origin/main
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/stubsabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ jobs:
python-version: "3.13"
- uses: astral-sh/setup-uv@v6
with:
version-file: "requirements-tests.txt"
version-file: "pyproject.toml"
- name: git config
run: |
git config --global user.name stubsabot
git config --global user.email '<>'
- name: Install dependencies
run: uv pip install -r requirements-tests.txt --system
run: uv pip install --group=dev --system
- name: Run stubsabot
run: GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} python scripts/stubsabot.py --action-level everything

Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/stubtest_stdlib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,10 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: requirements-tests.txt
cache-dependency-path: pyproject.toml
allow-prereleases: true
check-latest: true
- name: Install dependencies
run: pip install -r requirements-tests.txt
# Temporary to get @disjoint_base support; can remove once mypy 1.18 is released
- name: Install mypy from git
run: pip install git+https://github.com/python/mypy.git@116b92bae7b5dbf5e6bd36fd9b0c6804973e5554
run: pip install --group=dev
- name: Run stubtest
run: python tests/stubtest_stdlib.py
4 changes: 2 additions & 2 deletions .github/workflows/stubtest_third_party.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ jobs:
python-version: "3.13"
cache: pip
cache-dependency-path: |
requirements-tests.txt
pyproject.toml
stubs/**/METADATA.toml
- name: Install dependencies
run: pip install -r requirements-tests.txt
run: pip install --group=dev
- name: Determine changed stubs
shell: bash
run: |
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ jobs:
python-version: "3.13"
- uses: astral-sh/setup-uv@v6
with:
version-file: "requirements-tests.txt"
- run: uv pip install -r requirements-tests.txt --system
version-file: "pyproject.toml"
- run: uv pip install --group=dev --system
- run: python ./tests/check_typeshed_structure.py

mypy:
Expand All @@ -52,7 +52,7 @@ jobs:
allow-prereleases: true
- uses: astral-sh/setup-uv@v6
with:
version-file: "requirements-tests.txt"
version-file: "pyproject.toml"
- run: uv pip install -r requirements-tests.txt --system
- name: Install required APT packages
run: |
Expand Down Expand Up @@ -80,8 +80,8 @@ jobs:
python-version: "3.11"
- uses: astral-sh/setup-uv@v6
with:
version-file: "requirements-tests.txt"
- run: uv pip install -r requirements-tests.txt --system
version-file: "pyproject.toml"
- run: uv pip install --group=dev --system
- run: python ./tests/regr_test.py --all --verbosity QUIET

pyright:
Expand All @@ -99,10 +99,10 @@ jobs:
python-version: "3.13"
- uses: astral-sh/setup-uv@v6
with:
version-file: "requirements-tests.txt"
version-file: "pyproject.toml"
- name: Install typeshed test-suite requirements
# Install these so we can run `get_*_requirements.py`
run: uv pip install -r requirements-tests.txt --system
run: uv pip install --group=dev --system
- name: Install required APT packages
run: |
PACKAGES=$(python tests/get_stubtest_system_requirements.py)
Expand Down Expand Up @@ -170,5 +170,5 @@ jobs:
- name: Run tests
run: |
cd stub_uploader
uv pip install -r requirements.txt --system
uv pip install --group=dev --system
python -m pytest tests
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ repos:
- id: mixed-line-ending
args: [--fix=lf]
- id: check-case-conflict
- repo: https://github.com/sirosen/dependency-groups
rev: 1.3.1 # must match pyproject.toml
hooks:
- id: lint-dependency-groups
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.12.2 # must match requirements-tests.txt
hooks:
Expand Down
15 changes: 7 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ Note that some tests require extra setup steps to install the required dependenc
```bash
$ python3 -m venv .venv
$ source .venv/bin/activate
(.venv)$ pip install -U pip
(.venv)$ pip install -r requirements-tests.txt
(.venv)$ pip install -U "pip>=25.1"
(.venv)$ pip install --group=dev
```

</td>
Expand All @@ -79,8 +79,8 @@ Note that some tests require extra setup steps to install the required dependenc
```powershell
> py -m venv .venv
> .venv\Scripts\activate
(.venv) > python -m pip install -U pip
(.venv) > pip install -r requirements-tests.txt
(.venv) > python -m pip install -U "pip>=25.1"
(.venv) > pip install --group=dev
```

</td>
Expand All @@ -93,8 +93,7 @@ Note that some tests require extra setup steps to install the required dependenc
If you already have [uv](https://docs.astral.sh/uv/getting-started/installation/) installed, you can simply replace the commands above with:

```shell
uv venv
uv pip install -r requirements-tests.txt
uv pip install --group=dev
```

</td>
Expand Down Expand Up @@ -209,7 +208,7 @@ This has the following keys:
in addition to the requirements in the `requires` field.
* `apt_dependencies` (default: `[]`): A list of Ubuntu APT packages
that need to be installed for stubtest to run successfully.
* `brew_dependencies` (default: `[]`): A list of MacOS Homebrew packages
* `brew_dependencies` (default: `[]`): A list of macOS Homebrew packages
that need to be installed for stubtest to run successfully
* `choco_dependencies` (default: `[]`): A list of Windows Chocolatey packages
that need to be installed for stubtest to run successfully
Expand Down Expand Up @@ -340,7 +339,7 @@ replacing `$INSERT_LIBRARY_NAME_HERE` with the name of the library:
When the script has finished running, it will print instructions telling you what to do next.

If it has been a while since you set up the virtualenv, make sure you have
the latest mypy (`pip install -r requirements-tests.txt`) before running the script.
the latest mypy (`pip install --group=dev`) before running the script.

### Supported type system features

Expand Down
1 change: 0 additions & 1 deletion lib/ts_utils/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
STUBS_PATH: Final = TS_BASE_PATH / "stubs"

PYPROJECT_PATH: Final = TS_BASE_PATH / "pyproject.toml"
REQUIREMENTS_PATH: Final = TS_BASE_PATH / "requirements-tests.txt"
GITIGNORE_PATH: Final = TS_BASE_PATH / ".gitignore"
PYRIGHT_CONFIG: Final = TS_BASE_PATH / "pyrightconfig.stricter.json"

Expand Down
16 changes: 9 additions & 7 deletions lib/ts_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
from typing_extensions import TypeAlias

import pathspec
import tomllib
from dependency_groups import resolve
from packaging.requirements import Requirement

from .paths import GITIGNORE_PATH, REQUIREMENTS_PATH, STDLIB_PATH, STUBS_PATH, TEST_CASES_DIR, allowlists_path, test_cases_path
from .paths import GITIGNORE_PATH, PYPROJECT_PATH, STDLIB_PATH, STUBS_PATH, TEST_CASES_DIR, allowlists_path, test_cases_path

if TYPE_CHECKING:
from _typeshed import OpenTextMode
Expand Down Expand Up @@ -99,12 +101,12 @@ def venv_python(venv_dir: Path) -> Path:

@functools.cache
def parse_requirements() -> Mapping[str, Requirement]:
"""Return a dictionary of requirements from the requirements file."""
with REQUIREMENTS_PATH.open(encoding="UTF-8") as requirements_file:
stripped_lines = map(strip_comments, requirements_file)
stripped_more = [li for li in stripped_lines if not li.startswith("-")]
requirements = map(Requirement, filter(None, stripped_more))
return {requirement.name: requirement for requirement in requirements}
"""Return a dictionary of requirements found in the dev dependency group."""
with PYPROJECT_PATH.open("rb") as requirements_file:
pyproject = tomllib.load(requirements_file)

requirements = [Requirement(requirement) for requirement in resolve(pyproject["dependency-groups"], "dev")]
return {requirement.name: requirement for requirement in requirements}


def get_mypy_req() -> str:
Expand Down
33 changes: 32 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,37 @@ name = "typeshed"
version = "0"
requires-python = ">=3.9" # Minimum version to run tests, used by uv run

[dependency-groups]
dev = [
# Type checkers that we test our stubs against. These should always
# be pinned to a specific version to make failure reproducible.
"mypy ==1.18.1",
"pyright ==1.1.405",

# Libraries used by our various scripts.
"aiohttp ==3.12.15",
"dependency-groups ==1.3.1", # Must match .pre-commit-config.yaml.
# TODO (2025-05-09): Installing this on Python 3.14 on Windows fails at the moment.
"grpcio-tools >=1.66.2; python_version < '3.14'", # For grpc_tools.protoc"
"mypy-protobuf ==3.6.0",
"packaging ==25.0",
"pathspec >=0.11.1",
"pre-commit",
"ruff ==0.12.2", # Required by create_baseline_stubs.py. Must match .pre-commit-config.yaml.
"stubdefaulter ==0.1.0",
"termcolor >=2.3",
"tomli ==2.2.1; python_version < '3.11'",
"tomlkit ==0.13.3",
"typing_extensions >=4.15.0rc1",
"uv ==0.8.6",

# Utilities for typeshed infrastructure scripts.
"ts_utils @ file:lib",
]

[tool.uv.sources]
ts_utils = { path = "lib", editable = true }

[tool.black]
line-length = 130
target-version = ["py310"]
Expand Down Expand Up @@ -159,7 +190,7 @@ ignore = [
# see https://github.com/astral-sh/ruff/issues/6465
"E721", # Do not compare types, use `isinstance()`
# Highly opinionated, and it's often necessary to violate it
"PLC0415", # `import` should be at the top-level of a file
"PLC0415", # `import` should be at the top-level of a file
# Leave the size and complexity of tests to human interpretation
"PLR09", # Too many ...
# Too many magic number "2" that are preferable inline. https://github.com/astral-sh/ruff/issues/10009
Expand Down
25 changes: 0 additions & 25 deletions requirements-tests.txt

This file was deleted.

4 changes: 2 additions & 2 deletions scripts/create_baseline_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ async def get_project_urls_from_pypi(project: str, session: aiohttp.ClientSessio


async def get_upstream_repo_url(project: str) -> str | None:
# aiohttp is overkill here, but it would also just be silly
# to have both requests and aiohttp in our requirements-tests.txt file.
# aiohttp is overkill here, but it would also just be silly to have
# both requests and aiohttp in our dev dependency-group in pyproject.toml.
async with aiohttp.ClientSession() as session:
project_urls = await get_project_urls_from_pypi(project, session)

Expand Down
Loading
Loading