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
9 changes: 4 additions & 5 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v4
- uses: astral-sh/setup-uv@v6
with:
version: '>=0.7'
python-version: 3.9
- name: Setup
run: |
python --version
pip install --upgrade pip wheel
pip install django pynose coverage
uv sync --locked --dev
- name: Run coverage
run: |
coverage run -m nose
coverage run -m pytest
# .coverage.* files are ignored by git
coverage report -m | tee .coverage.out
percent=$(grep -E '^TOTAL\s.+\s[0-9]{1,3}%$' .coverage.out \
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Publish Python distribution to PyPI
# Source:
# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
on:
push:
tags:
- 'v*'
workflow_dispatch:
jobs:
build:
name: Build distribution package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v6
with:
version: '>=0.7'
- name: Check for version match in git tag and field_audit.__version__
if: startsWith(github.ref, 'refs/tags/v')
run: uvx pyverno check field_audit/__init__.py "${{ github.ref }}"
- name: Build a binary wheel and a source tarball
run: uv build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
pypi-publish:
name: Upload release to PyPI
needs: [build]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/django-field-audit
permissions:
id-token: write
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
14 changes: 7 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ jobs:
--health-retries 5
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: astral-sh/setup-uv@v6
with:
version: '>=0.7'
python-version: ${{ matrix.python }}
- name: Setup
run: |
python --version
pip install --upgrade pip wheel
pip install "${{ matrix.django }}" psycopg2-binary pynose flake8 coverage
uv sync --locked --dev --no-install-package=django
uv pip install "${{ matrix.django }}" psycopg2-binary
- name: Run tests
env:
DB_SETTINGS: >-
Expand All @@ -57,14 +57,14 @@ jobs:
"HOST":"localhost",
"PORT":"5432"
}
run: nosetests -v --with-coverage --cover-branches --cover-package=field_audit
run: uv run pytest --cov=field_audit --cov-branch -v
continue-on-error: ${{ matrix.experimental }}
- name: Check migrations
run: |
./example/manage.py makemigrations field_audit
uv run ./example/manage.py makemigrations field_audit
git add ./field_audit/migrations
trap 'git reset --hard HEAD' EXIT # discard changes on exit (needed for continue-on-error)
git diff --cached --exit-code
continue-on-error: ${{ matrix.experimental }}
- name: Check style
run: flake8 --config=setup.cfg
run: uv run ruff check
29 changes: 11 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,11 @@ All feature and bug contributions are expected to be covered by tests.

### Setup for developers

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

```shell
cd django-field-audit
mkvirtualenv django-field-audit # or however you choose to setup your environment
pip install django pynose flake8 coverage
uv sync
```

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

- Tests
```shell
nosetests
uv run pytest
```

- Style check
```shell
flake8 --config=setup.cfg
ruff check
```

- Coverage
```shell
coverage run -m nose
coverage report -m
uv run coverage run -m pytest
uv run coverage report -m
```

### Adding migrations

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

```shell
python example/manage.py makemigrations field_audit
uv run python example/manage.py makemigrations field_audit
```

### Uploading to PyPI
### Publishing a new version to PyPI

First bump the package version in the `field_audit/__init__.py` file. Then create a changelog entry in the CHANGELOG.md
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.
Push a new tag to Github using the format vX.Y.Z where X.Y.Z matches the version
in [`__init__.py`](field_audit/__init__.py).

```shell
pip install -r pkg-requires.txt

python setup.py sdist bdist_wheel
twine upload dist/*
```
Publishing is automated with [Github Actions](.github/workflows/pypi.yml).

## TODO

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

### Backlog

Expand Down
3 changes: 0 additions & 3 deletions pkg-requires.txt

This file was deleted.

71 changes: 71 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
[project]
name = "django-field-audit"
authors = [
{name = "Joel Miller", email = "jmiller@dimagi.com"},
{name = "Simon Kelly", email = "simongdkelly@gmail.com"},
{name = "Graham Herceg", email = "gherceg@dimagi.com"},
{name = "Chris Smit", email = "chris.smit@dimagi.com"},
{name = "Daniel Miller", email = "millerdev@gmail.com"},
]
description = "Audit Field Changes on Django Models"
readme = {file = "README.md", content-type = "text/markdown"}
license = {file = "LICENSE"}
requires-python = ">=3.9"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Web Environment",
"Framework :: Django",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Software Development :: Libraries :: Python Modules",
]
dynamic = ["version"]
dependencies = ["django>=3.2"]

[project.urls]
Homepage = "https://github.com/dimagi/django-field-audit"
Repository = "https://github.com/dimagi/django-field-audit"

[tool.flit.module]
name = "field_audit"

[tool.uv]
dev-dependencies = [
"coverage",
"pytest",
"pytest-cov",
"pytest-django",
"ruff",
]

[tool.pytest.ini_options]
DJANGO_SETTINGS_MODULE = "tests.settings"
addopts = "--tb=short --strict-markers --strict-config"
python_files = ["tests.py", "test_*.py", "*_test.py"]
testpaths = ["tests"]

[build-system]
requires = ["flit_core >=3.2,<4"]
build-backend = "flit_core.buildapi"

[tool.ruff]
line-length = 80

[tool.ruff.lint]
select = ["E", "F", "W"]

[tool.ruff.lint.per-file-ignores]
"*/migrations/*" = ["E501"]

[tool.ruff.format]
exclude = [
"./build",
".venv",
]
11 changes: 0 additions & 11 deletions setup.cfg

This file was deleted.

53 changes: 0 additions & 53 deletions setup.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


def setup():
"""Initialize database for nosetests"""
"""Initialize database for pytest"""
init_db()


Expand Down
Loading