Skip to content

Commit 853cad2

Browse files
Switch to uv to manage dev dependencies
* Using build backend `uv_build` -- as opposed to `hatchling` which is used by `django-stubs` * `setup.py` and `setup.cfg` migrated into `pyproject.toml` * Removed obsolete flake8 config. * `requirements.txt` merged into `pyproject.toml` * `pytest.ini` merged into `pyproject.toml` * GitHub `test.yml` workflows * Using `astral-sh/setup-uv@v6` to install uv & Python * Converted to use `uv run` & other `uv` commands. * New check to ensure `uv.lock` is up to date * No longer depending on `setuptools` Co-authored-by: CodingWithSaksham <[email protected]>
1 parent 04fafaf commit 853cad2

File tree

10 files changed

+1244
-167
lines changed

10 files changed

+1244
-167
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ trim_trailing_whitespace = true
1111

1212
[*.{py, pyi}]
1313
indent_size = 4
14+
15+
[*.toml]
16+
indent_size = 2

.github/workflows/test.yml

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ on:
1010
# 15:41 UTC every day
1111
- cron: "41 15 * * *"
1212

13+
env:
14+
UV_FROZEN: true # https://docs.astral.sh/uv/configuration/environment/#uv_frozen
15+
1316
permissions:
1417
contents: read
1518

@@ -24,89 +27,80 @@ jobs:
2427
strategy:
2528
fail-fast: false
2629
matrix:
27-
python-version: ['3.10', '3.11', '3.12', '3.13']
30+
python-version: ["3.10", "3.11", "3.12", "3.13"]
2831
steps:
2932
- uses: actions/checkout@v5
30-
- name: Set up Python ${{ matrix.python-version }}
31-
uses: actions/setup-python@v6
33+
- name: Install uv & Python ${{ matrix.python-version }}
34+
uses: astral-sh/setup-uv@v6
3235
with:
3336
python-version: ${{ matrix.python-version }}
3437
- name: Install dependencies
35-
run: |
36-
pip install -U pip "setuptools<79.0.0" wheel
37-
SETUPTOOLS_ENABLE_FEATURES=legacy-editable pip install -r ./requirements.txt
38+
run: uv sync
3839
- name: Run mypy on plugin code
39-
run: mypy --strict mypy_drf_plugin
40+
run: uv run mypy --strict mypy_drf_plugin
4041
- name: Run mypy on scripts and utils
41-
run: mypy --strict scripts
42+
run: uv run mypy --strict scripts
4243
- name: Run mypy on stubs
43-
run: mypy --cache-dir=/dev/null --no-incremental rest_framework-stubs
44+
run: uv run mypy --cache-dir=/dev/null --no-incremental rest_framework-stubs
4445

4546
test:
4647
timeout-minutes: 10
4748
runs-on: ubuntu-latest
4849
strategy:
4950
fail-fast: false
5051
matrix:
51-
python-version: ['3.10', '3.11', '3.12', '3.13']
52+
python-version: ["3.10", "3.11", "3.12", "3.13"]
5253
steps:
5354
- uses: actions/checkout@v5
5455
- name: Setup system dependencies
5556
run: |
5657
sudo apt-get update
5758
sudo apt-get install binutils libproj-dev gdal-bin
58-
- name: Set up Python ${{ matrix.python-version }}
59-
uses: actions/setup-python@v6
59+
- name: Install uv & Python ${{ matrix.python-version }}
60+
uses: astral-sh/setup-uv@v6
6061
with:
6162
python-version: ${{ matrix.python-version }}
6263
- name: Install dependencies
63-
run: |
64-
pip install -U pip "setuptools<79.0.0" wheel
65-
SETUPTOOLS_ENABLE_FEATURES=legacy-editable pip install -r ./requirements.txt
66-
64+
run: uv sync
6765
- name: Run tests
68-
# Suppress errors from other packages due to https://github.com/typeddjango/pytest-mypy-plugins/issues/134
69-
run: pytest --mypy-only-local-stub
66+
run: uv run pytest
7067

7168
stubtest:
7269
timeout-minutes: 10
7370
runs-on: ubuntu-latest
7471
strategy:
7572
matrix:
76-
python-version: ['3.13']
73+
python-version: ["3.13"]
7774
fail-fast: false
7875
steps:
7976
- uses: actions/checkout@v5
8077
- name: Setup system dependencies
8178
run: |
8279
sudo apt-get update
8380
sudo apt-get install binutils libproj-dev gdal-bin
84-
- name: Set up Python ${{ matrix.python-version }}
85-
uses: actions/setup-python@v6
81+
- name: Install uv & Python ${{ matrix.python-version }}
82+
uses: astral-sh/setup-uv@v6
8683
with:
8784
python-version: ${{ matrix.python-version }}
8885
- name: Install dependencies
89-
run: |
90-
pip install -U pip "setuptools<79.0.0" wheel
91-
SETUPTOOLS_ENABLE_FEATURES=legacy-editable pip install -r ./requirements.txt
86+
run: uv sync
9287

9388
- name: Run stubtest
94-
run: bash ./scripts/stubtest.sh
89+
run: uv run ./scripts/stubtest.sh
9590

9691
build-and-check:
9792
runs-on: ubuntu-latest
9893
steps:
9994
- uses: actions/checkout@v5
10095
with:
10196
fetch-tags: true
102-
- uses: actions/setup-python@v6
97+
- name: Install uv & Python
98+
uses: astral-sh/setup-uv@v6
10399
with:
104-
python-version: '3.13'
105-
- name: Install dependencies
106-
run: python3 -m pip install --upgrade build twine
100+
python-version: "3.13"
101+
- name: Ensure uv.lock is up to date
102+
run: env --unset=UV_FROZEN uv lock --check
107103
- name: Build
108-
run: |
109-
python3 -m build --sdist --wheel .
104+
run: uv build
110105
- name: Check package metadata
111-
run: |
112-
twine check --strict dist/*
106+
run: uvx twine check --strict dist/*

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ out/
1212
pip-wheel-metadata/
1313
stubgen/
1414
build/
15+
dist/

CONTRIBUTING.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,19 @@ Additionally, the following resources might be useful:
3333
### Repository Setup
3434

3535
As a first step you will need to fork this repository and clone your fork locally.
36-
In order to be able to continously sync your fork with the origin repository's master branch, you will need to set up an upstream master. To do so follow this [official github guide](https://docs.github.com/en/free-pro-team@latest/github/collaborating-with-issues-and-pull-requests/syncing-a-fork).
36+
In order to be able to continously sync your fork with the origin repository's master branch, you will need to set up an upstream master.
37+
To do so follow this [official github guide](https://docs.github.com/en/free-pro-team@latest/github/collaborating-with-issues-and-pull-requests/syncing-a-fork).
3738

3839
### Dependency Setup
3940

40-
After your repository is setup you will then need to create and activate a git ignored virtual env, e.g.:
41+
We use [uv](https://github.com/astral-sh/uv) to manage our dev dependencies.
42+
To install it, see their [installation guide](https://docs.astral.sh/uv/getting-started/installation/)
4143

42-
```bash
43-
python3 -m venv .venv
44-
source .venv/bin/activate
45-
```
46-
47-
Then install the dev requirements:
44+
Once it's done, simply run the following command to automatically setup a virtual environment and install dev dependencies:
4845

4946
```bash
50-
SETUPTOOLS_ENABLE_FEATURES=legacy-editable pip install -r ./requirements.txt
47+
uv sync
48+
source .venv/bin/activate
5149
```
5250

5351
Finally, install the pre-commit hooks:
@@ -107,6 +105,7 @@ The workflow for contributions is fairly simple:
107105
`patch` is sequentially increasing for each stubs release. Reset to `0` if `major.minor` was updated.
108106

109107
- Update `django-stubs>=` dependency to point to latest `django-stubs` release.
108+
- Update lockfile, run: `uv lock`
110109
- Use pull request title "Version x.y.z release" by convention.
111110

112111
2. Ensure the CI succeeds. A maintainer must merge this PR. If it's just a verison bump, no need

pyproject.toml

Lines changed: 107 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,116 @@
1+
[project]
2+
name = "djangorestframework-stubs"
3+
version = "3.16.3"
4+
requires-python = ">=3.10"
5+
description = "PEP-484 stubs for django-rest-framework"
6+
readme = "README.md"
7+
license = "MIT"
8+
license-files = ["LICENSE.txt"]
9+
authors = [{ name = "Maksim Kurnikov", email = "[email protected]" }]
10+
maintainers = [
11+
{ name = "Marti Raudsepp", email = "[email protected]" },
12+
{ name = "Nikita Sobolev", email = "[email protected]" },
13+
]
14+
classifiers = [
15+
"License :: OSI Approved :: MIT License",
16+
"Operating System :: OS Independent",
17+
"Programming Language :: Python :: 3.10",
18+
"Programming Language :: Python :: 3.11",
19+
"Programming Language :: Python :: 3.12",
20+
"Programming Language :: Python :: 3.13",
21+
"Typing :: Typed",
22+
"Framework :: Django",
23+
]
24+
dependencies = [
25+
"django-stubs>=5.2.5",
26+
"typing-extensions>=4.0",
27+
"requests>=2.0",
28+
"types-requests",
29+
"types-PyYAML",
30+
]
31+
32+
[project.urls]
33+
Homepage = "https://github.com/typeddjango/djangorestframework-stubs"
34+
Funding = "https://github.com/sponsors/typeddjango"
35+
"Release notes" = "https://github.com/typeddjango/djangorestframework-stubs/releases"
36+
37+
[project.optional-dependencies]
38+
compatible-mypy = ["mypy>=1.13,<1.19", "django-stubs[compatible-mypy]"]
39+
coreapi = ["coreapi>=2.0.0"]
40+
markdown = ["types-Markdown>=0.1.5"]
41+
42+
[dependency-groups]
43+
dev = [
44+
"wheel",
45+
"pre-commit==4.3.0",
46+
"pytest==8.4.2",
47+
"pytest-mypy-plugins==3.2.0",
48+
"djangorestframework==3.16.1",
49+
"types-pytz==2025.2.0.20250809",
50+
"types-requests==2.32.4.20250913",
51+
"types-urllib3==1.26.25.14",
52+
"types-Pygments==2.19.0.20250809",
53+
"types-pyyaml==6.0.12.20250915",
54+
"django-stubs[compatible-mypy] @ git+https://github.com/typeddjango/django-stubs",
55+
"django-stubs-ext @ git+https://github.com/typeddjango/django-stubs#subdirectory=ext",
56+
"djangorestframework-stubs[compatible-mypy,coreapi,markdown]",
57+
]
58+
59+
[build-system]
60+
requires = ["uv_build>=0.8.19,<0.9.0"]
61+
build-backend = "uv_build"
62+
63+
[tool.uv.build-backend]
64+
module-name = ["rest_framework-stubs", "mypy_drf_plugin"]
65+
module-root = ""
66+
67+
[tool.pytest.ini_options]
68+
pythonpath = ["."]
69+
testpaths = ["tests"]
70+
addopts = [
71+
"--tb=native",
72+
"-s",
73+
"-v",
74+
"--cache-clear",
75+
"--mypy-extension-hook=scripts.tests_extension_hook.django_plugin_hook",
76+
# Suppress errors from other packages due to https://github.com/typeddjango/pytest-mypy-plugins/issues/134
77+
"--mypy-only-local-stub",
78+
"--mypy-ini-file=mypy.ini"
79+
]
80+
81+
# Ruff configuration
182
[tool.ruff]
283
line-length = 120
384
target-version = "py310"
85+
486
# See Rules in Ruff documentation: https://docs.astral.sh/ruff/rules/
587
[tool.ruff.lint]
688
select = [
7-
"B", # bugbear
8-
"E", # pycodestyle
9-
"F", # pyflakes
10-
"INP", # flake8-tidy-imports
11-
"W", # pycodestyle
12-
"I", # isort
13-
"UP", # pyupgrade
14-
"TID251", # Disallowed imports (flake8-tidy-imports.banned-api)
15-
"PYI", # flake8-pyi
16-
"RUF100", # Equivalent to flake8-noqa NQA103
17-
"PGH004", # Equivalent to flake8-noqa NQA104
18-
"PGH003", # Disallowed blanket `type: ignore` annotations.
89+
"B", # bugbear
90+
"E", # pycodestyle
91+
"F", # pyflakes
92+
"INP", # flake8-tidy-imports
93+
"W", # pycodestyle
94+
"I", # isort
95+
"UP", # pyupgrade
96+
"TID251", # Disallowed imports (flake8-tidy-imports.banned-api)
97+
"PYI", # flake8-pyi
98+
"RUF100", # Equivalent to flake8-noqa NQA103
99+
"PGH004", # Equivalent to flake8-noqa NQA104
100+
"PGH003", # Disallowed blanket `type: ignore` annotations.
19101
]
20102
ignore = ["PYI021", "PYI024", "PYI041", "PYI043"]
21103

22104
[tool.ruff.lint.per-file-ignores]
23105
"*.pyi" = [
24-
"B",
25-
"E501",
26-
"E741",
27-
"E743",
28-
"F403", # Use wildcard import
29-
"F405",
30-
"F822",
31-
"F821",
106+
"B",
107+
"E501",
108+
"E741",
109+
"E743",
110+
"F403", # Use wildcard import
111+
"F405",
112+
"F822",
113+
"F821",
32114
]
33115
"rest_framework-stubs/compat.pyi" = ["PYI042"]
34116

@@ -39,5 +121,8 @@ ignore = ["PYI021", "PYI024", "PYI041", "PYI043"]
39121
split-on-trailing-comma = false
40122
extra-standard-library = ["_typeshed"]
41123

42-
[build-system]
43-
requires = ["setuptools<79.0.0", "wheel"]
124+
# Pyright configuration
125+
[tool.pyright]
126+
pythonVersion = "3.10"
127+
include = ["rest_framework-stubs", "tests"]
128+
exclude = [".venv", ".mypy_cache", ".pytest_cache", ".idea"]

pytest.ini

Lines changed: 0 additions & 10 deletions
This file was deleted.

requirements.txt

Lines changed: 0 additions & 13 deletions
This file was deleted.

setup.cfg

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)