Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ trim_trailing_whitespace = true

[*.{py, pyi}]
indent_size = 4

[*.toml]
indent_size = 2
60 changes: 27 additions & 33 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ on:
# 15:41 UTC every day
- cron: "41 15 * * *"

env:
UV_FROZEN: true # https://docs.astral.sh/uv/configuration/environment/#uv_frozen

permissions:
contents: read

Expand All @@ -24,89 +27,80 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.10', '3.11', '3.12', '3.13']
python-version: ["3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v5
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
- name: Install uv & Python ${{ matrix.python-version }}
uses: astral-sh/setup-uv@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install -U pip "setuptools<79.0.0" wheel
SETUPTOOLS_ENABLE_FEATURES=legacy-editable pip install -r ./requirements.txt
run: uv sync
- name: Run mypy on plugin code
run: mypy --strict mypy_drf_plugin
run: uv run mypy --strict mypy_drf_plugin
- name: Run mypy on scripts and utils
run: mypy --strict scripts
run: uv run mypy --strict scripts
- name: Run mypy on stubs
run: mypy --cache-dir=/dev/null --no-incremental rest_framework-stubs
run: uv run mypy --cache-dir=/dev/null --no-incremental rest_framework-stubs

test:
timeout-minutes: 10
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ['3.10', '3.11', '3.12', '3.13']
python-version: ["3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v5
- name: Setup system dependencies
run: |
sudo apt-get update
sudo apt-get install binutils libproj-dev gdal-bin
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
- name: Install uv & Python ${{ matrix.python-version }}
uses: astral-sh/setup-uv@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install -U pip "setuptools<79.0.0" wheel
SETUPTOOLS_ENABLE_FEATURES=legacy-editable pip install -r ./requirements.txt

run: uv sync
- name: Run tests
# Suppress errors from other packages due to https://github.com/typeddjango/pytest-mypy-plugins/issues/134
run: pytest --mypy-only-local-stub
run: uv run pytest
Copy link
Contributor Author

Choose a reason for hiding this comment

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

--mypy-only-local-stub moved to pyproject.toml pytest config.


stubtest:
timeout-minutes: 10
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.13']
python-version: ["3.13"]
fail-fast: false
steps:
- uses: actions/checkout@v5
- name: Setup system dependencies
run: |
sudo apt-get update
sudo apt-get install binutils libproj-dev gdal-bin
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
- name: Install uv & Python ${{ matrix.python-version }}
uses: astral-sh/setup-uv@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install -U pip "setuptools<79.0.0" wheel
SETUPTOOLS_ENABLE_FEATURES=legacy-editable pip install -r ./requirements.txt
run: uv sync

- name: Run stubtest
run: bash ./scripts/stubtest.sh
run: uv run ./scripts/stubtest.sh

build-and-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
fetch-tags: true
- uses: actions/setup-python@v6
- name: Install uv & Python
uses: astral-sh/setup-uv@v6
with:
python-version: '3.13'
- name: Install dependencies
run: python3 -m pip install --upgrade build twine
python-version: "3.13"
- name: Ensure uv.lock is up to date
run: env --unset=UV_FROZEN uv lock --check
- name: Build
run: |
python3 -m build --sdist --wheel .
run: uv build
- name: Check package metadata
run: |
twine check --strict dist/*
run: uvx twine check --strict dist/*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ out/
pip-wheel-metadata/
stubgen/
build/
dist/
17 changes: 8 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,19 @@ Additionally, the following resources might be useful:
### Repository Setup

As a first step you will need to fork this repository and clone your fork locally.
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).
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).

### Dependency Setup

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

```bash
python3 -m venv .venv
source .venv/bin/activate
```

Then install the dev requirements:
Once it's done, simply run the following command to automatically setup a virtual environment and install dev dependencies:

```bash
SETUPTOOLS_ENABLE_FEATURES=legacy-editable pip install -r ./requirements.txt
uv sync
source .venv/bin/activate
```

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

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

2. Ensure the CI succeeds. A maintainer must merge this PR. If it's just a verison bump, no need
Expand Down
129 changes: 107 additions & 22 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,34 +1,116 @@
[project]
name = "djangorestframework-stubs"
version = "3.16.3"
requires-python = ">=3.10"
description = "PEP-484 stubs for django-rest-framework"
readme = "README.md"
license = "MIT"
license-files = ["LICENSE.txt"]
authors = [{ name = "Maksim Kurnikov", email = "[email protected]" }]
maintainers = [
{ name = "Marti Raudsepp", email = "[email protected]" },
{ name = "Nikita Sobolev", email = "[email protected]" },
]
classifiers = [
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Typing :: Typed",
"Framework :: Django",
]
dependencies = [
"django-stubs>=5.2.5",
"typing-extensions>=4.0",
"requests>=2.0",
"types-requests",
"types-PyYAML",
]

[project.urls]
Homepage = "https://github.com/typeddjango/djangorestframework-stubs"
Funding = "https://github.com/sponsors/typeddjango"
"Release notes" = "https://github.com/typeddjango/djangorestframework-stubs/releases"

[project.optional-dependencies]
compatible-mypy = ["mypy>=1.13,<1.19", "django-stubs[compatible-mypy]"]
coreapi = ["coreapi>=2.0.0"]
markdown = ["types-Markdown>=0.1.5"]

[dependency-groups]
dev = [
"wheel",
"pre-commit==4.3.0",
"pytest==8.4.2",
"pytest-mypy-plugins==3.2.0",
"djangorestframework==3.16.1",
"types-pytz==2025.2.0.20250809",
"types-requests==2.32.4.20250913",
"types-urllib3==1.26.25.14",
"types-Pygments==2.19.0.20250809",
"types-pyyaml==6.0.12.20250915",
"django-stubs[compatible-mypy] @ git+https://github.com/typeddjango/django-stubs",
"django-stubs-ext @ git+https://github.com/typeddjango/django-stubs#subdirectory=ext",
"djangorestframework-stubs[compatible-mypy,coreapi,markdown]",
]

[build-system]
requires = ["uv_build>=0.8.19,<0.9.0"]
build-backend = "uv_build"

[tool.uv.build-backend]
module-name = ["rest_framework-stubs", "mypy_drf_plugin"]
module-root = ""

[tool.pytest.ini_options]
pythonpath = ["."]
testpaths = ["tests"]
addopts = [
"--tb=native",
"-s",
"-v",
"--cache-clear",
"--mypy-extension-hook=scripts.tests_extension_hook.django_plugin_hook",
# Suppress errors from other packages due to https://github.com/typeddjango/pytest-mypy-plugins/issues/134
"--mypy-only-local-stub",
"--mypy-ini-file=mypy.ini"
Comment on lines +77 to +78
Copy link

Copilot AI Sep 20, 2025

Choose a reason for hiding this comment

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

The mypy configuration reference should be updated to use pyproject.toml instead of mypy.ini since the project is consolidating configurations. Consider migrating mypy settings to [tool.mypy] in this file.

Suggested change
"--mypy-only-local-stub",
"--mypy-ini-file=mypy.ini"
"--mypy-only-local-stub"

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

@intgr intgr Sep 20, 2025

Choose a reason for hiding this comment

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

Migrating mypy.ini turned out to be problematic. Maybe later.

Copy link
Contributor

Choose a reason for hiding this comment

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

Did this previously, it made none of the tests pass. We need to approach this carefully then.

Copy link
Contributor

@CodingWithSaksham CodingWithSaksham Sep 20, 2025

Choose a reason for hiding this comment

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

Updated my code to use uv-build instead of hatch and 29 out of the 36 test cases are failing!

Seems like pytest is unable to find

disable_error_code = ["empty-body"]
enable_error_code = ["ignore-without-code"]

when written in pyproject.toml

]

# Ruff configuration
[tool.ruff]
line-length = 120
target-version = "py310"

# See Rules in Ruff documentation: https://docs.astral.sh/ruff/rules/
[tool.ruff.lint]
select = [
"B", # bugbear
"E", # pycodestyle
"F", # pyflakes
"INP", # flake8-tidy-imports
"W", # pycodestyle
"I", # isort
"UP", # pyupgrade
"TID251", # Disallowed imports (flake8-tidy-imports.banned-api)
"PYI", # flake8-pyi
"RUF100", # Equivalent to flake8-noqa NQA103
"PGH004", # Equivalent to flake8-noqa NQA104
"PGH003", # Disallowed blanket `type: ignore` annotations.
"B", # bugbear
"E", # pycodestyle
"F", # pyflakes
"INP", # flake8-tidy-imports
"W", # pycodestyle
"I", # isort
"UP", # pyupgrade
"TID251", # Disallowed imports (flake8-tidy-imports.banned-api)
"PYI", # flake8-pyi
"RUF100", # Equivalent to flake8-noqa NQA103
"PGH004", # Equivalent to flake8-noqa NQA104
"PGH003", # Disallowed blanket `type: ignore` annotations.
]
ignore = ["PYI021", "PYI024", "PYI041", "PYI043"]

[tool.ruff.lint.per-file-ignores]
"*.pyi" = [
"B",
"E501",
"E741",
"E743",
"F403", # Use wildcard import
"F405",
"F822",
"F821",
"B",
"E501",
"E741",
"E743",
"F403", # Use wildcard import
"F405",
"F822",
"F821",
]
"rest_framework-stubs/compat.pyi" = ["PYI042"]

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

[build-system]
requires = ["setuptools<79.0.0", "wheel"]
# Pyright configuration
[tool.pyright]
pythonVersion = "3.10"
include = ["rest_framework-stubs", "tests"]
exclude = [".venv", ".mypy_cache", ".pytest_cache", ".idea"]
10 changes: 0 additions & 10 deletions pytest.ini

This file was deleted.

13 changes: 0 additions & 13 deletions requirements.txt

This file was deleted.

13 changes: 0 additions & 13 deletions setup.cfg

This file was deleted.

Loading