Skip to content

Commit 9cb4885

Browse files
authored
Merge pull request #41 from dimagi/sk/uv
project housekeeping updates
2 parents 9b96e38 + b5eb332 commit 9cb4885

File tree

10 files changed

+512
-98
lines changed

10 files changed

+512
-98
lines changed

.github/workflows/coverage.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,16 @@ jobs:
1010
- uses: actions/checkout@v4
1111
with:
1212
fetch-depth: 0
13-
- uses: actions/setup-python@v4
13+
- uses: astral-sh/setup-uv@v6
1414
with:
15+
version: '>=0.7'
1516
python-version: 3.9
1617
- name: Setup
1718
run: |
18-
python --version
19-
pip install --upgrade pip wheel
20-
pip install django pynose coverage
19+
uv sync --locked --dev
2120
- name: Run coverage
2221
run: |
23-
coverage run -m nose
22+
coverage run -m pytest
2423
# .coverage.* files are ignored by git
2524
coverage report -m | tee .coverage.out
2625
percent=$(grep -E '^TOTAL\s.+\s[0-9]{1,3}%$' .coverage.out \

.github/workflows/pypi.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Publish Python distribution to PyPI
2+
# Source:
3+
# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
4+
on:
5+
push:
6+
tags:
7+
- 'v*'
8+
workflow_dispatch:
9+
jobs:
10+
build:
11+
name: Build distribution package
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: astral-sh/setup-uv@v6
16+
with:
17+
version: '>=0.7'
18+
- name: Check for version match in git tag and field_audit.__version__
19+
if: startsWith(github.ref, 'refs/tags/v')
20+
run: uvx pyverno check field_audit/__init__.py "${{ github.ref }}"
21+
- name: Build a binary wheel and a source tarball
22+
run: uv build
23+
- name: Store the distribution packages
24+
uses: actions/upload-artifact@v4
25+
with:
26+
name: python-package-distributions
27+
path: dist/
28+
pypi-publish:
29+
name: Upload release to PyPI
30+
needs: [build]
31+
runs-on: ubuntu-latest
32+
environment:
33+
name: pypi
34+
url: https://pypi.org/p/django-field-audit
35+
permissions:
36+
id-token: write
37+
steps:
38+
- name: Download all the dists
39+
uses: actions/download-artifact@v4
40+
with:
41+
name: python-package-distributions
42+
path: dist/
43+
- name: Publish package distributions to PyPI
44+
uses: pypa/gh-action-pypi-publish@release/v1

.github/workflows/tests.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ jobs:
3838
--health-retries 5
3939
steps:
4040
- uses: actions/checkout@v4
41-
- uses: actions/setup-python@v4
41+
- uses: astral-sh/setup-uv@v6
4242
with:
43+
version: '>=0.7'
4344
python-version: ${{ matrix.python }}
4445
- name: Setup
4546
run: |
46-
python --version
47-
pip install --upgrade pip wheel
48-
pip install "${{ matrix.django }}" psycopg2-binary pynose flake8 coverage
47+
uv sync --locked --dev --no-install-package=django
48+
uv pip install "${{ matrix.django }}" psycopg2-binary
4949
- name: Run tests
5050
env:
5151
DB_SETTINGS: >-
@@ -57,14 +57,14 @@ jobs:
5757
"HOST":"localhost",
5858
"PORT":"5432"
5959
}
60-
run: nosetests -v --with-coverage --cover-branches --cover-package=field_audit
60+
run: uv run pytest --cov=field_audit --cov-branch -v
6161
continue-on-error: ${{ matrix.experimental }}
6262
- name: Check migrations
6363
run: |
64-
./example/manage.py makemigrations field_audit
64+
uv run ./example/manage.py makemigrations field_audit
6565
git add ./field_audit/migrations
6666
trap 'git reset --hard HEAD' EXIT # discard changes on exit (needed for continue-on-error)
6767
git diff --cached --exit-code
6868
continue-on-error: ${{ matrix.experimental }}
6969
- name: Check style
70-
run: flake8 --config=setup.cfg
70+
run: uv run ruff check

README.md

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,11 @@ All feature and bug contributions are expected to be covered by tests.
243243

244244
### Setup for developers
245245

246-
Create/activate a python virtualenv and install the required dependencies.
246+
This project uses [uv](https://docs.astral.sh/uv/) for dependency management. Install uv and then install the project dependencies:
247247

248248
```shell
249249
cd django-field-audit
250-
mkvirtualenv django-field-audit # or however you choose to setup your environment
251-
pip install django pynose flake8 coverage
250+
uv sync
252251
```
253252

254253
### Running tests
@@ -259,46 +258,40 @@ your local Python's `sqlite3` library ships with the `JSON1` extension enabled
259258

260259
- Tests
261260
```shell
262-
nosetests
261+
uv run pytest
263262
```
264263

265264
- Style check
266265
```shell
267-
flake8 --config=setup.cfg
266+
ruff check
268267
```
269268

270269
- Coverage
271270
```shell
272-
coverage run -m nose
273-
coverage report -m
271+
uv run coverage run -m pytest
272+
uv run coverage report -m
274273
```
275274

276275
### Adding migrations
277276

278277
The example `manage.py` is available for making new migrations.
279278

280279
```shell
281-
python example/manage.py makemigrations field_audit
280+
uv run python example/manage.py makemigrations field_audit
282281
```
283282

284-
### Uploading to PyPI
283+
### Publishing a new version to PyPI
285284

286-
First bump the package version in the `field_audit/__init__.py` file. Then create a changelog entry in the CHANGELOG.md
287-
file. After these changes are merged, you should tag the main branch with the new version. Then, package and upload the generated files to PyPI.
285+
Push a new tag to Github using the format vX.Y.Z where X.Y.Z matches the version
286+
in [`__init__.py`](field_audit/__init__.py).
288287

289-
```shell
290-
pip install -r pkg-requires.txt
291-
292-
python setup.py sdist bdist_wheel
293-
twine upload dist/*
294-
```
288+
Publishing is automated with [Github Actions](.github/workflows/pypi.yml).
295289

296290
## TODO
297291

298292
- Implement auditing for the remaining "special" QuerySet write operations:
299293
- `bulk_update()`
300294
- Write full library documentation using github.io.
301-
- Switch to `pytest` to support Python 3.10.
302295

303296
### Backlog
304297

pkg-requires.txt

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

pyproject.toml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
[project]
2+
name = "django-field-audit"
3+
authors = [
4+
{name = "Joel Miller", email = "jmiller@dimagi.com"},
5+
{name = "Simon Kelly", email = "simongdkelly@gmail.com"},
6+
{name = "Graham Herceg", email = "gherceg@dimagi.com"},
7+
{name = "Chris Smit", email = "chris.smit@dimagi.com"},
8+
{name = "Daniel Miller", email = "millerdev@gmail.com"},
9+
]
10+
description = "Audit Field Changes on Django Models"
11+
readme = {file = "README.md", content-type = "text/markdown"}
12+
license = {file = "LICENSE"}
13+
requires-python = ">=3.9"
14+
classifiers = [
15+
"Development Status :: 5 - Production/Stable",
16+
"Environment :: Web Environment",
17+
"Framework :: Django",
18+
"Intended Audience :: Developers",
19+
"License :: OSI Approved :: BSD License",
20+
"Operating System :: OS Independent",
21+
"Programming Language :: Python",
22+
"Programming Language :: Python :: 3",
23+
"Programming Language :: Python :: 3.9",
24+
"Programming Language :: Python :: 3.10",
25+
"Programming Language :: Python :: 3.11",
26+
"Programming Language :: Python :: 3.12",
27+
"Topic :: Software Development :: Libraries :: Python Modules",
28+
]
29+
dynamic = ["version"]
30+
dependencies = ["django>=3.2"]
31+
32+
[project.urls]
33+
Homepage = "https://github.com/dimagi/django-field-audit"
34+
Repository = "https://github.com/dimagi/django-field-audit"
35+
36+
[tool.flit.module]
37+
name = "field_audit"
38+
39+
[tool.uv]
40+
dev-dependencies = [
41+
"coverage",
42+
"pytest",
43+
"pytest-cov",
44+
"pytest-django",
45+
"ruff",
46+
]
47+
48+
[tool.pytest.ini_options]
49+
DJANGO_SETTINGS_MODULE = "tests.settings"
50+
addopts = "--tb=short --strict-markers --strict-config"
51+
python_files = ["tests.py", "test_*.py", "*_test.py"]
52+
testpaths = ["tests"]
53+
54+
[build-system]
55+
requires = ["flit_core >=3.2,<4"]
56+
build-backend = "flit_core.buildapi"
57+
58+
[tool.ruff]
59+
line-length = 80
60+
61+
[tool.ruff.lint]
62+
select = ["E", "F", "W"]
63+
64+
[tool.ruff.lint.per-file-ignores]
65+
"*/migrations/*" = ["E501"]
66+
67+
[tool.ruff.format]
68+
exclude = [
69+
"./build",
70+
".venv",
71+
]

setup.cfg

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

setup.py

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

tests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
def setup():
13-
"""Initialize database for nosetests"""
13+
"""Initialize database for pytest"""
1414
init_db()
1515

1616

0 commit comments

Comments
 (0)