From 4fb57b474c7ad109ef20825d4895802ff5d9cc4a Mon Sep 17 00:00:00 2001 From: Alex Morega Date: Tue, 8 Oct 2024 15:58:14 +0300 Subject: [PATCH 01/11] Fix readme and project links --- README.md | 13 ++++++------- pyproject.toml | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 61aacfe..bf21de6 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ Your site will probably have some of your own check/processor needs. Custom checks can be implemented by subclassing `birdbath.checks.BaseCheck` and implementing the `check` method: -``` +```python from birdbath.checks import BaseCheck @@ -54,7 +54,7 @@ The `check` method should either return `True` if the checks should continue, or Custom processors can be implemented by subclassing `birdbath.processors.BaseProcessor` and implementing the `run` method: -``` +```python from birdbath.processors import BaseProcessor @@ -65,7 +65,7 @@ class DeleteAllMyUsersProcessor(BaseProcessor): There are also more specialised base classes in `birdbath.processors` that can help you write cleaner custom processors. For example, the above example could be written using the `BaseModelDeleter` class instead: -``` +```python from birdbath.processors import BaseModelDeleter @@ -75,7 +75,7 @@ class DeleteAllMyUsersProcessor(BaseModelDeleter): If you only need to delete a subset of users, you can override the `get_queryset()` method, like so: -``` +```python from birdbath.processors import BaseModelDeleter @@ -88,8 +88,7 @@ class DeleteNonStaffUsersProcessor(BaseModelDeleter): If you're looking to 'anonymise' rather than delete objects, you will likely find the `BaseModelAnonymiser` class useful. You just need to indicate the fields that should be 'anonymised' or 'cleared', and the class will do the rest. For example: - -``` +```python from birdbath.processors import BaseModelAnonymiser @@ -122,7 +121,7 @@ The class will generate: If you have fields with custom validation requirements, or would simply like to generate more realistic replacement values, you can add 'generate' methods to your subclass to achieve this. `BaseModelAnonymiser` will automatically look for method matching the format `"generate_{field_name}"` when anoymising field values. For example, the following processor will generate random values for "account_holder" and "account_number" fields: -``` +```python from birdbath.processors import BaseModelAnonymiser diff --git a/pyproject.toml b/pyproject.toml index 68574b0..c1f9673 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,7 @@ dependencies = [ requires-python = ">=3.9" [project.urls] -Home = "https://git.torchbox.com/internal/django-birdbath" +Home = "https://github.com/torchbox/django-birdbath" [project.optional-dependencies] dev = [ From ac7509eecfaf8faa2fc699d30e1807ed4e90ea50 Mon Sep 17 00:00:00 2001 From: Alex Morega Date: Tue, 8 Oct 2024 16:12:30 +0300 Subject: [PATCH 02/11] Set up Github Actions with tox --- .../scripts/report_nightly_build_failure.py | 28 ++++++++++ .github/workflows/nightly.yml | 35 +++++++++++++ .github/workflows/publish.yml | 51 +++++++++++++++++++ .github/workflows/test.yml | 50 ++++++++++++++++++ tox.ini | 8 +++ 5 files changed, 172 insertions(+) create mode 100644 .github/scripts/report_nightly_build_failure.py create mode 100644 .github/workflows/nightly.yml create mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/scripts/report_nightly_build_failure.py b/.github/scripts/report_nightly_build_failure.py new file mode 100644 index 0000000..1af05f3 --- /dev/null +++ b/.github/scripts/report_nightly_build_failure.py @@ -0,0 +1,28 @@ +""" +Called by GH Actions when the nightly build fails. + +This reports an error to the #nightly-build-failures Slack channel. +""" + +import os + +import requests + + +if "SLACK_WEBHOOK_URL" in os.environ: + print("Reporting to #nightly-build-failures slack channel") + response = requests.post( + os.environ["SLACK_WEBHOOK_URL"], + json={ + "text": "A Nightly build failed. See https://github.com/torchbox/django-birdbath/actions/runs/" + + os.environ["GITHUB_RUN_ID"], + }, + timeout=30, + ) + + print("Slack responded with:", response) + +else: + print( + "Unable to report to #nightly-build-failures slack channel because SLACK_WEBHOOK_URL is not set" + ) diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml new file mode 100644 index 0000000..884108b --- /dev/null +++ b/.github/workflows/nightly.yml @@ -0,0 +1,35 @@ +name: Nightly Wagtail Test + +on: + schedule: + - cron: '0 1 * * *' + # At 01:00, daily + workflow_dispatch: + +jobs: + nightly-wagtail-test: + runs-on: ubuntu-latest + env: + WEBHOOK_EXISTS: ${{ secrets.SLACK_WEBHOOK_URL != '' }} + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - run: git clone https://github.com/wagtail/wagtail.git + + - run: python -m pip install flit + - run: flit install --deps production --extras testing + - run: python -m pip install ./wagtail + + - run: python testmanage.py test + + - name: Report failure + run: | + python -m pip install requests + python ./.github/scripts/report_nightly_build_failure.py + if: ${{ failure() && env.WEBHOOK_EXISTS == 'true' }} + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..178ffd3 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,51 @@ +# See https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ +# for a detailed guide +name: Publish to PyPI + +on: + release: + types: [published] + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read # to fetch code (actions/checkout) + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Python 3.11 + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install flit + python -m flit install --symlink + + - name: Build + run: python -m flit build + + - uses: actions/upload-artifact@v4 + with: + path: ./dist + + publish: + needs: build + runs-on: ubuntu-latest + permissions: + contents: none + id-token: write # required for trusted publishing + environment: publish + steps: + - uses: actions/download-artifact@v4 + + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + packages-dir: artifact/ + print-hash: true diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..bd925c2 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,50 @@ +name: Django Birdbath CI + +on: + push: + branches: + - main + - 'stable/**' + + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: read # to fetch code (actions/checkout) + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up Python 3.8 + uses: actions/setup-python@v5 + with: + python-version: '3.8' + - uses: pre-commit/action@v3.0.1 + + test: + runs-on: ubuntu-latest + needs: lint + strategy: + matrix: + python: ['3.8', '3.9', '3.10', '3.11', '3.12'] + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python }} + - name: Install + run: | + python -m pip install --upgrade pip + python -m pip install flit tox tox-gh-actions + flit install --extras dev + - name: Test + run: tox diff --git a/tox.ini b/tox.ini index a786ddf..99f6a8a 100644 --- a/tox.ini +++ b/tox.ini @@ -5,6 +5,14 @@ envlist = py312-django42-wagtail{52,60,61,62} isolated_build = True +[gh-actions] +python = + 3.8: python3.8 + 3.9: python3.9 + 3.10: python3.10 + 3.11: python3.11 + 3.12: python3.12 + [testenv] deps = django42: Django>=4.2,<5.0 From 783b4e2476eafd0ea0e5c56fa1695e3bdb83735d Mon Sep 17 00:00:00 2001 From: Alex Morega Date: Tue, 8 Oct 2024 16:16:55 +0300 Subject: [PATCH 03/11] We don't support py38 --- .github/workflows/test.yml | 6 +++--- tox.ini | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bd925c2..52dcc18 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,10 +22,10 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Set up Python 3.8 + - name: Set up Python 3.9 uses: actions/setup-python@v5 with: - python-version: '3.8' + python-version: '3.9' - uses: pre-commit/action@v3.0.1 test: @@ -33,7 +33,7 @@ jobs: needs: lint strategy: matrix: - python: ['3.8', '3.9', '3.10', '3.11', '3.12'] + python: ['3.9', '3.10', '3.11', '3.12'] steps: - uses: actions/checkout@v4 diff --git a/tox.ini b/tox.ini index 99f6a8a..15c7e17 100644 --- a/tox.ini +++ b/tox.ini @@ -7,7 +7,6 @@ isolated_build = True [gh-actions] python = - 3.8: python3.8 3.9: python3.9 3.10: python3.10 3.11: python3.11 From b24f55ba3e802de4dce5639aa4e77d46d86ba5ab Mon Sep 17 00:00:00 2001 From: Alex Morega Date: Tue, 8 Oct 2024 16:26:48 +0300 Subject: [PATCH 04/11] Fix pytest configuration --- pyproject.toml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index c1f9673..e520c33 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -60,3 +60,8 @@ lint.select = [ "C4", # flake8-comprehensions "UP", # pyupgrade ] + +[tool.pytest.ini_options] +django_find_project = false +pythonpath = "." +DJANGO_SETTINGS_MODULE = "tests.settings" From 54dc173e493bf90818f79f20974262cccc432794 Mon Sep 17 00:00:00 2001 From: Alex Morega Date: Tue, 8 Oct 2024 16:43:26 +0300 Subject: [PATCH 05/11] No need to install package to run tox --- .github/workflows/test.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 52dcc18..54e5408 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -43,8 +43,6 @@ jobs: python-version: ${{ matrix.python }} - name: Install run: | - python -m pip install --upgrade pip - python -m pip install flit tox tox-gh-actions - flit install --extras dev + python -m pip install --upgrade pip tox tox-gh-actions - name: Test run: tox From f6e83bf83a9495bf6f2a079d6aea33629b63b952 Mon Sep 17 00:00:00 2001 From: Alex Morega Date: Tue, 8 Oct 2024 16:46:53 +0300 Subject: [PATCH 06/11] Fix tox version mapping for Github Actions --- tox.ini | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tox.ini b/tox.ini index 15c7e17..11c90b2 100644 --- a/tox.ini +++ b/tox.ini @@ -7,10 +7,10 @@ isolated_build = True [gh-actions] python = - 3.9: python3.9 - 3.10: python3.10 - 3.11: python3.11 - 3.12: python3.12 + 3.9: py39 + 3.10: py310 + 3.11: py311 + 3.12: py312 [testenv] deps = From 9b76fe13371d9f363a9a81814261166286a9e5c9 Mon Sep 17 00:00:00 2001 From: Alex Morega Date: Tue, 8 Oct 2024 16:51:33 +0300 Subject: [PATCH 07/11] Test Django 4.2 with more Python versions --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 11c90b2..4bdaa6c 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] envlist = - py39-django42-wagtail62 + py{39,310,311,312}-django42-wagtail62 py{310,311,312}-django{50,51}-wagtail62 py312-django42-wagtail{52,60,61,62} isolated_build = True From fb6f264995273fbe24e3b599ef9d5c0ca5e09719 Mon Sep 17 00:00:00 2001 From: Alex Morega Date: Tue, 8 Oct 2024 17:01:39 +0300 Subject: [PATCH 08/11] Fix nightly workflow --- .github/workflows/nightly.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 884108b..49a12f0 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -21,10 +21,10 @@ jobs: - run: git clone https://github.com/wagtail/wagtail.git - run: python -m pip install flit - - run: flit install --deps production --extras testing + - run: flit install --extras dev - run: python -m pip install ./wagtail - - run: python testmanage.py test + - run: pytest - name: Report failure run: | From dc6112bf2e5b0432a45f453b870d863c47088520 Mon Sep 17 00:00:00 2001 From: Alex Morega Date: Wed, 9 Oct 2024 10:50:34 +0300 Subject: [PATCH 09/11] Trim down to supported Wagtail versions only --- tox.ini | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tox.ini b/tox.ini index 4bdaa6c..18ad119 100644 --- a/tox.ini +++ b/tox.ini @@ -2,7 +2,7 @@ envlist = py{39,310,311,312}-django42-wagtail62 py{310,311,312}-django{50,51}-wagtail62 - py312-django42-wagtail{52,60,61,62} + py312-django42-wagtail{52,62} isolated_build = True [gh-actions] @@ -18,8 +18,6 @@ deps = django50: Django>=5.0,<5.1 django51: Django>=5.1,<5.2 wagtail52: wagtail>=5.2,<5.3 - wagtail60: wagtail>=6.0,<6.1 - wagtail61: wagtail>=6.1,<6.2 wagtail62: wagtail>=6.2,<6.3 pytest pytest-django From e8c3810d27eb5662c68d5e965065a634c52ed2fa Mon Sep 17 00:00:00 2001 From: Alex Morega Date: Fri, 11 Oct 2024 15:10:44 +0300 Subject: [PATCH 10/11] Add support for Python 3.13 --- .github/workflows/test.yml | 2 +- pyproject.toml | 1 + tox.ini | 7 ++++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 54e5408..e4423df 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,7 +33,7 @@ jobs: needs: lint strategy: matrix: - python: ['3.9', '3.10', '3.11', '3.12'] + python: ['3.9', '3.10', '3.11', '3.12', '3.13'] steps: - uses: actions/checkout@v4 diff --git a/pyproject.toml b/pyproject.toml index e520c33..87224c6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,6 +15,7 @@ classifiers = [ "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", ] keywords = ["django", "anonymization", "data cleaning"] dependencies = [ diff --git a/tox.ini b/tox.ini index 18ad119..14eea81 100644 --- a/tox.ini +++ b/tox.ini @@ -1,8 +1,8 @@ [tox] envlist = - py{39,310,311,312}-django42-wagtail62 - py{310,311,312}-django{50,51}-wagtail62 - py312-django42-wagtail{52,62} + py{39,310,311,312,313}-django42-wagtail62 + py{310,311,312,313}-django{50,51}-wagtail62 + py{313}-django42-wagtail{52,62} isolated_build = True [gh-actions] @@ -11,6 +11,7 @@ python = 3.10: py310 3.11: py311 3.12: py312 + 3.13: py313 [testenv] deps = From 7a86c9ce616c3291fb0f6bbb2c60dff21792bbf9 Mon Sep 17 00:00:00 2001 From: Alex Morega Date: Tue, 22 Oct 2024 17:02:25 +0300 Subject: [PATCH 11/11] PR feedback --- .github/workflows/nightly.yml | 2 +- .github/workflows/test.yml | 4 ++-- pyproject.toml | 3 ++- tox.ini | 4 +++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 49a12f0..71a1f5b 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -16,7 +16,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: - python-version: '3.11' + python-version: '3.12' - run: git clone https://github.com/wagtail/wagtail.git diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e4423df..c68fcd8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,10 +22,10 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Set up Python 3.9 + - name: Set up Python 3.12 uses: actions/setup-python@v5 with: - python-version: '3.9' + python-version: '3.12' - uses: pre-commit/action@v3.0.1 test: diff --git a/pyproject.toml b/pyproject.toml index 87224c6..377ddc4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,8 @@ classifiers = [ ] keywords = ["django", "anonymization", "data cleaning"] dependencies = [ - "Faker >=8", + "Faker>=8", + "Django>=4.2", ] requires-python = ">=3.9" diff --git a/tox.ini b/tox.ini index 14eea81..5b9be82 100644 --- a/tox.ini +++ b/tox.ini @@ -1,8 +1,10 @@ [tox] envlist = + # Django versions with their respectively supported Python versions and the most recent Wagtail LTS py{39,310,311,312,313}-django42-wagtail62 py{310,311,312,313}-django{50,51}-wagtail62 - py{313}-django42-wagtail{52,62} + # Old Wagtail versions with the oldest Django LTS and Python + py39-django42-wagtail52 isolated_build = True [gh-actions]