Skip to content

Use dev dependency-group #40

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
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
10 changes: 5 additions & 5 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,11 +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
run: pip install --group=dev
- name: Run stubtest
run: python tests/stubtest_stdlib.py

Expand All @@ -69,10 +69,10 @@ jobs:
python-version: "3.12"
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: Run stubtest
shell: bash
run: |
Expand Down
7 changes: 3 additions & 4 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 @@ -40,7 +39,7 @@ jobs:
with:
python-version: "3.12"
- run: curl -LsSf https://astral.sh/uv/install.sh | sh
- run: uv pip install -r requirements-tests.txt --system
- run: uv pip install --dev --system
- run: python ./tests/typecheck_typeshed.py --platform=${{ matrix.platform }}
pyright:
name: Run pyright against the scripts and tests directories
Expand All @@ -55,7 +54,7 @@ jobs:
with:
python-version: "3.12"
- run: curl -LsSf https://astral.sh/uv/install.sh | sh
- run: uv pip install -r requirements-tests.txt --system
- run: uv pip install --dev --system
- name: Run pyright on typeshed
uses: jakebailey/pyright-action@v2
with:
Expand All @@ -76,5 +75,5 @@ jobs:
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 --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
Owner Author

@Avasam Avasam Mar 7, 2025

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
2 changes: 1 addition & 1 deletion .github/workflows/stubsabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
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
4 changes: 2 additions & 2 deletions .github/workflows/stubtest_stdlib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +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
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.12"
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: Run stubtest
shell: bash
run: |
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
with:
python-version: "3.12"
- run: curl -LsSf https://astral.sh/uv/install.sh | sh
- run: uv pip install -r requirements-tests.txt --system
- run: uv pip install --group=dev --system
- run: python ./tests/check_typeshed_structure.py

pytype:
Expand All @@ -44,7 +44,7 @@ jobs:
# Max supported Python version as of pytype 2024.9.13
python-version: "3.12"
- uses: astral-sh/setup-uv@v5
- run: uv pip install -r requirements-tests.txt --system
- run: uv pip install --group=dev --system
- name: Install external dependencies for 3rd-party stubs
run: |
DEPENDENCIES=$( python tests/get_external_stub_requirements.py )
Expand All @@ -69,7 +69,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- run: curl -LsSf https://astral.sh/uv/install.sh | sh
- run: uv pip install -r requirements-tests.txt --system
- run: uv pip install --group=dev --system
- run: python ./tests/mypy_test.py --platform=${{ matrix.platform }} --python-version=${{ matrix.python-version }}

regression-tests:
Expand All @@ -83,7 +83,7 @@ jobs:
# TODO: figure out why that is (#11590)
python-version: "3.11"
- run: curl -LsSf https://astral.sh/uv/install.sh | sh
- run: uv pip install -r requirements-tests.txt --system
- run: uv pip install --group=dev --system
- run: python ./tests/regr_test.py --all --verbosity QUIET

pyright:
Expand All @@ -102,7 +102,7 @@ jobs:
- uses: astral-sh/setup-uv@v5
- name: Install typeshed test-suite requirements
# Install these so we can run `get_external_stub_requirements.py`
run: uv pip install -r requirements-tests.txt --system
run: uv pip install --group=dev --system
- name: Create an isolated venv for testing
run: uv venv .venv
- name: Install 3rd-party stub dependencies
Expand Down
6 changes: 5 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ repos:
- id: mixed-line-ending
args: [--fix=lf]
- id: check-case-conflict
- repo: https://github.com/sirosen/dependency-groups
rev: 1.3.0 # must match pyproject.toml
hooks:
- id: lint-dependency-groups
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.3 # must match requirements-tests.txt
rev: v0.9.3 # must match pyproject.toml
hooks:
- id: ruff
name: Run ruff on stubs, tests and scripts
Expand Down
88 changes: 57 additions & 31 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,37 +50,63 @@ please refer to this

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

### Linux/Mac OS/WSL

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

```bash
$ python3 -m venv .venv
$ source .venv/bin/activate
(.venv)$ pip install -U pip
(.venv)$ pip install -r requirements-tests.txt
```

### Windows

Run the following commands from a Windows terminal to install all requirements:

```powershell
> python -m venv .venv
> .venv\Scripts\activate
(.venv) > pip install -U pip
(.venv) > pip install -r "requirements-tests.txt"
```

To be able to run pytype tests, you'll also need to install it manually
<table>
<tr>
<td>Linux / macOS / WSL</td>
<td>

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

```bash
$ python3 -m venv .venv
$ source .venv/bin/activate
(.venv)$ pip install -U "pip>=25.1"
(.venv)$ pip install --group=dev
```

</td>
</tr>
<tr>
<td>Windows</td>
<td>

Run the following commands from a Windows terminal to install all requirements:

```powershell
> python -m venv .venv
> .venv\Scripts\activate
(.venv) > pip install -U "pip>=25.1"
(.venv) > pip install --group=dev
```

To be able to run pytype tests, you'll also need to install it manually
as it's currently excluded from the requirements file:

```powershell
(.venv) > pip install -U pytype
```
```powershell
(.venv) > pip install -U pytype
```

</td>
</tr>
<tr>
<td>Using uv</td>
<td>

If you already have [uv](https://docs.astral.sh/uv/getting-started/installation/) installed, you can simply replace the commands above by:

```shell
uv pip install --dev
```
```shell
uv pip install -U pytype
```

</td>
</tr>
</table>

## Code formatting

Expand Down Expand Up @@ -213,7 +239,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 @@ -313,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
5 changes: 3 additions & 2 deletions lib/ts_utils/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
STDLIB_PATH: Final = TS_BASE_PATH / "stdlib"
STUBS_PATH: Final = TS_BASE_PATH / "stubs"

PYPROJECT_PATH: Final = TS_BASE_PATH / "pyproject.toml"
REQUIREMENTS_PATH: Final = TS_BASE_PATH / "requirements-tests.txt"
PYPROJECT_PATH: Final = TS_BASE_PATH / "pyproject.tosml"

TESTS_DIR: Final = "@tests"
TEST_CASES_DIR: Final = "test_cases"

print("hi!")


def distribution_path(distribution_name: str) -> Path:
"""Return the path to the directory of a third-party distribution."""
Expand Down
15 changes: 8 additions & 7 deletions lib/ts_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
from collections.abc import Iterable, Mapping
from functools import lru_cache
from pathlib import Path
import tomllib
from typing import Any, Dict, Final, NamedTuple, Tuple
from typing_extensions import TypeAlias

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

Expand All @@ -21,7 +22,7 @@ def colored(text: str, color: str | None = None, **kwargs: Any) -> str: # type:
return text


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

PYTHON_VERSION: Final = f"{sys.version_info.major}.{sys.version_info.minor}"

Expand Down Expand Up @@ -96,11 +97,11 @@ def venv_python(venv_dir: Path) -> Path:
@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}
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
36 changes: 36 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
[project]
name = "typeshed"
version = "0"

[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.15.0",
"pyright ==1.1.396",
# pytype can be installed on Windows, but requires building wheels, let's not do that on the CI
"pytype ==2024.10.11; platform_system != 'Windows' and python_version >= '3.10' and python_version < '3.13'",

# Libraries used by our various scripts.
"aiohttp ==3.10.11",
"dependency-groups ==1.3.0", # Must match .pre-commit-config.yaml.
"grpcio-tools >=1.66.2", # For grpc_tools.protoc"
"mypy-protobuf ==3.6.0",
"packaging ==24.2",
"pathspec >=0.11.1",
"pre-commit",
"ruff ==0.9.3", # Required by create_baseline_stubs.py. Must match .pre-commit-config.yaml.
"stubdefaulter ==0.1.0",
"termcolor >=2.3",
"tomli ==2.2.1",
"tomlkit ==0.13.2",
"typing_extensions >=4.12.0rc1",
"uv ==0.5.14",

# 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
Loading
Loading