Skip to content

Commit c8a38ab

Browse files
UnknownPlatypusjose-reveni
authored andcommitted
Use uv to manage dev dependencies (typeddjango#2698)
1 parent ab76f24 commit c8a38ab

File tree

5 files changed

+1110
-56
lines changed

5 files changed

+1110
-56
lines changed

.github/workflows/test.yml

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ on:
77
pull_request:
88
workflow_dispatch:
99

10+
env:
11+
UV_FROZEN: true # https://docs.astral.sh/uv/configuration/environment/#uv_frozen
12+
UV_NO_SYNC: true # prevent `uv run` cmd from bringing very dev dependencies
13+
1014
permissions:
1115
contents: read
1216

@@ -24,24 +28,26 @@ jobs:
2428
fail-fast: false
2529
steps:
2630
- uses: actions/checkout@v4
31+
- name: Install uv
32+
uses: astral-sh/setup-uv@v5
2733
- name: Set up Python ${{ matrix.python-version }}
2834
uses: actions/setup-python@v5
2935
with:
3036
python-version: ${{ matrix.python-version }}
37+
3138
- name: Install dependencies
32-
run: |
33-
pip install -U pip
34-
pip install -r ./requirements.txt
39+
run: uv sync --no-dev --group tests
3540

3641
- name: Run mypy on plugin code
37-
run: mypy --strict mypy_django_plugin
38-
42+
run: uv run mypy --strict mypy_django_plugin
3943
- name: Run mypy on ext code
40-
run: mypy --strict ext
44+
run: uv run mypy --strict ext
4145
- name: Run mypy on scripts and utils
42-
run: mypy --strict scripts
46+
run: uv run mypy --strict scripts
4347
- name: Run mypy on stubs
44-
run: mypy --cache-dir=/dev/null --no-incremental django-stubs
48+
run: uv run mypy --cache-dir=/dev/null --no-incremental django-stubs
49+
- name: Run mypy on the test cases
50+
run: uv run mypy --strict tests
4551

4652
test:
4753
timeout-minutes: 15
@@ -57,20 +63,20 @@ jobs:
5763
run: |
5864
sudo apt-get update
5965
sudo apt-get install binutils libproj-dev gdal-bin
66+
- name: Install uv
67+
uses: astral-sh/setup-uv@v5
6068
- name: Set up Python ${{ matrix.python-version }}
6169
uses: actions/setup-python@v5
6270
with:
6371
python-version: ${{ matrix.python-version }}
72+
6473
- name: Install dependencies
65-
run: |
66-
pip install -U pip
67-
pip install -r ./requirements.txt
74+
run: uv sync --no-dev --group tests
6875

6976
# Must match `shard` definition in the test matrix:
7077
- name: Run pytest tests
71-
run: PYTHONPATH='.' pytest --num-shards=4 --shard-id=${{ matrix.shard }} -n auto tests
72-
- name: Run mypy on the test cases
73-
run: mypy --strict tests
78+
run: uv run pytest --num-shards=4 --shard-id=${{ matrix.shard }} -n auto tests
79+
7480

7581
stubtest:
7682
timeout-minutes: 10
@@ -85,17 +91,18 @@ jobs:
8591
run: |
8692
sudo apt-get update
8793
sudo apt-get install binutils libproj-dev gdal-bin
94+
- name: Install uv
95+
uses: astral-sh/setup-uv@v5
8896
- name: Set up Python ${{ matrix.python-version }}
8997
uses: actions/setup-python@v5
9098
with:
9199
python-version: ${{ matrix.python-version }}
100+
92101
- name: Install dependencies
93-
run: |
94-
pip install -U pip
95-
pip install -r ./requirements.txt
102+
run: uv sync --no-dev --group tests
96103

97104
- name: Run stubtest
98-
run: ./scripts/stubtest.sh
105+
run: uv run ./scripts/stubtest.sh
99106

100107
run-pyright:
101108
timeout-minutes: 10
@@ -106,14 +113,20 @@ jobs:
106113
fail-fast: false
107114
steps:
108115
- uses: actions/checkout@v4
116+
- name: Install uv
117+
uses: astral-sh/setup-uv@v5
109118
- name: Set up Python ${{ matrix.python-version }}
110119
uses: actions/setup-python@v5
111120
with:
112121
python-version: ${{ matrix.python-version }}
122+
113123
- name: Install dependencies
114-
run: |
115-
pip install -U pip
116-
pip install -r ./requirements.txt
124+
run: uv sync --no-dev --group pyright
125+
126+
# See https://github.com/jakebailey/pyright-action#providing-a-pyright-version-sourced-from-preexisting-dependencies
127+
- name: Add venv to path
128+
run: echo "$PWD/.venv/bin" >> $GITHUB_PATH
129+
117130
- name: Run pyright on the stubs
118131
uses: jakebailey/pyright-action@v2
119132
with:
@@ -140,19 +153,18 @@ jobs:
140153
run: |
141154
sudo apt-get update
142155
sudo apt-get install binutils libproj-dev gdal-bin
156+
- name: Install uv
157+
uses: astral-sh/setup-uv@v5
143158
- name: Set up Python ${{ matrix.python-version }}
144159
uses: actions/setup-python@v5
145160
with:
146161
python-version: ${{ matrix.python-version }}
162+
147163
- name: Install dependencies
148-
run: |
149-
pip install -U pip
150-
pip install -r ./requirements.txt
151-
pip install "Django==${{ matrix.django-version }}"
152-
pip check
164+
run: uv sync --no-dev --group tests
153165

154166
- name: Run django-stubs-ext tests
155-
run: PYTHONPATH='.' pytest ext
167+
run: uv run --with "django==${{ matrix.django-version }}" pytest ext
156168

157169
build-and-check:
158170
runs-on: ubuntu-latest

CONTRIBUTING.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,19 @@ Additionally, the following resources might be useful:
3030
### Repository Setup
3131

3232
As a first step you will need to fork this repository and clone your fork locally.
33-
In order to be able to continuously 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).
33+
In order to be able to continuously sync your fork with the origin repository's master branch, you will need to set up an upstream master.
34+
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).
3435

3536
### Dependency Setup
37+
We use [uv](https://github.com/astral-sh/uv) to manage our dev dependencies.
38+
To install it, see their [installation guide](https://docs.astral.sh/uv/getting-started/installation/)
3639

37-
After your repository is setup you will then need to create and activate a git ignored virtual env, e.g.:
38-
40+
Once it's done, simply run the following command to automatically setup a virtual environment and install dev dependencies:
3941
```bash
40-
python3 -m venv .venv
42+
uv sync
4143
source .venv/bin/activate
4244
```
4345

44-
Then install the dev requirements:
45-
46-
```bash
47-
pip install -r ./requirements.txt
48-
```
49-
5046
Finally, install the pre-commit hooks:
5147

5248
```bash

pyproject.toml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,42 @@ compatible-mypy = ["mypy>=1.13,<1.16"]
4545
oracle = ["oracledb"]
4646
redis = ["redis", "types-redis"]
4747

48+
[dependency-groups]
49+
tests = [
50+
# Dev tools:
51+
"pytest==8.3.5",
52+
"pytest-mypy-plugins==3.2.0",
53+
"pytest-shard==0.1.2",
54+
"pytest-xdist==3.7.0",
55+
# Django deps:
56+
"django==5.2.1",
57+
"mysqlclient==2.2.7",
58+
"psycopg2-binary==2.9.10",
59+
"jinja2==3.1.6",
60+
"pyyaml==6.0.2",
61+
# typing:
62+
"mypy==1.15.0",
63+
"django-stubs[compatible-mypy,oracle,redis]",
64+
]
65+
pyright = ["pyright==1.1.401"]
66+
67+
dev = [
68+
{include-group = "tests"},
69+
{include-group = "pyright"},
70+
]
71+
4872
[project.urls]
4973
Homepage = "https://github.com/typeddjango/django-stubs"
5074
Funding = "https://github.com/sponsors/typeddjango"
5175
"Release notes" = "https://github.com/typeddjango/django-stubs/releases"
5276

77+
[tool.uv.sources]
78+
django-stubs = { workspace = true }
79+
django-stubs-ext = { path = "ext", editable = true }
80+
5381
[tool.hatch.build]
5482
packages = ["django-stubs", "mypy_django_plugin"]
5583

56-
5784
[tool.codespell]
5885
ignore-words-list = "aadd,acount,nam,asend"
5986

requirements.txt

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

0 commit comments

Comments
 (0)