From 188db8dfa35b5b914700f9f929918cfe84a3b670 Mon Sep 17 00:00:00 2001 From: Alex Tomkins Date: Sat, 27 Jul 2024 21:32:33 +0100 Subject: [PATCH 1/9] Update copyright year --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index f1a4302..2c5097a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2019-2023, Developer Society Limited +Copyright (c) 2019-2024, Developer Society Limited All rights reserved. Redistribution and use in source and binary forms, with or without From 5f21b0bb2d90c9bae6da22ee308e6d92461d9067 Mon Sep 17 00:00:00 2001 From: Alex Tomkins Date: Sat, 27 Jul 2024 21:21:32 +0100 Subject: [PATCH 2/9] Drop support for Python 3.7 --- pyproject.toml | 2 +- requirements/testing.txt | 6 +++--- setup.py | 3 +-- tox.ini | 6 +++--- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5b56786..16dec98 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.black] line-length = 99 -target-version = ['py37'] +target-version = ['py38'] exclude = '/migrations/' [tool.isort] diff --git a/requirements/testing.txt b/requirements/testing.txt index c1d4d15..99553d6 100644 --- a/requirements/testing.txt +++ b/requirements/testing.txt @@ -1,5 +1,5 @@ -black==24.3.0 ; python_version >= '3.8' +black==24.3.0 coverage==7.2.7 -flake8==6.0.0 ; python_version >= '3.8' -isort==5.12.0 ; python_version >= '3.8' +flake8==6.0.0 +isort==5.12.0 pipdeptree==2.9.0 diff --git a/setup.py b/setup.py index ccf0cde..64a9c5c 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ def read(filename): platforms=["any"], packages=find_packages(exclude=["tests"]), include_package_data=True, - python_requires=">=3.7", + python_requires=">=3.8", install_requires=["Django>=2.2"], classifiers=[ "Intended Audience :: Developers", @@ -29,7 +29,6 @@ def read(filename): "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", diff --git a/tox.ini b/tox.ini index 371191a..70c4cd2 100644 --- a/tox.ini +++ b/tox.ini @@ -2,9 +2,9 @@ envlist = check lint - {py37,py38,py39}-django2.2 - {py37,py38,py39,py310}-django3.2 - {py38,py39,py310,py311}-django4.2 + py{38,39}-django2.2 + py{38,39,310}-django3.2 + py{38,39,310,311}-django4.2 coverage no_package = true From 5d41c2acde63a404dff39ff8165b97aa84d12db2 Mon Sep 17 00:00:00 2001 From: Alex Tomkins Date: Sat, 27 Jul 2024 21:27:39 +0100 Subject: [PATCH 3/9] Tweak tox.ini --- tox.ini | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tox.ini b/tox.ini index 70c4cd2..2e7b348 100644 --- a/tox.ini +++ b/tox.ini @@ -18,19 +18,16 @@ deps = django3.2,django4.2: psycopg2>=2.9,<2.10 allowlist_externals = make commands = make test -usedevelop = true +package = editable [testenv:check] basepython = python3.11 commands = make check -skip_install = true [testenv:lint] basepython = python3.11 commands = make lint -skip_install = true [testenv:coverage] basepython = python3.11 commands = make coverage-report -skip_install = true From 2a863d266becb076a8db5d434533a18c6fbdeffe Mon Sep 17 00:00:00 2001 From: Alex Tomkins Date: Sat, 27 Jul 2024 21:28:42 +0100 Subject: [PATCH 4/9] Add support for Python 3.12 --- .github/workflows/ci.yml | 2 +- setup.py | 1 + tox.ini | 8 ++++---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index adddae8..ff87b13 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: - name: Setup Python uses: actions/setup-python@v5 with: - python-version: '3.11' + python-version: '3.12' cache: 'pip' cache-dependency-path: 'requirements/*.txt' - name: Run tox diff --git a/setup.py b/setup.py index 64a9c5c..bcd38ef 100644 --- a/setup.py +++ b/setup.py @@ -33,6 +33,7 @@ def read(filename): "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Framework :: Django", "Framework :: Django :: 2.2", "Framework :: Django :: 3.2", diff --git a/tox.ini b/tox.ini index 2e7b348..d0aa199 100644 --- a/tox.ini +++ b/tox.ini @@ -4,7 +4,7 @@ envlist = lint py{38,39}-django2.2 py{38,39,310}-django3.2 - py{38,39,310,311}-django4.2 + py{38,39,310,311,312}-django4.2 coverage no_package = true @@ -21,13 +21,13 @@ commands = make test package = editable [testenv:check] -basepython = python3.11 +basepython = python3.12 commands = make check [testenv:lint] -basepython = python3.11 +basepython = python3.12 commands = make lint [testenv:coverage] -basepython = python3.11 +basepython = python3.12 commands = make coverage-report From 425c4eedc12f7e205e10721fb79ecf5c75808c27 Mon Sep 17 00:00:00 2001 From: Alex Tomkins Date: Sat, 27 Jul 2024 21:29:09 +0100 Subject: [PATCH 5/9] Minor package updates --- requirements/local.txt | 6 +++--- requirements/testing.txt | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/requirements/local.txt b/requirements/local.txt index 88dfe9d..e49167e 100644 --- a/requirements/local.txt +++ b/requirements/local.txt @@ -2,6 +2,6 @@ bump2version==1.0.1 Django>=4.2,<5.0 -psycopg2==2.9.6 -tox==4.6.0 -twine==4.0.2 +psycopg2==2.9.9 +tox==4.18.1 +twine==5.1.1 diff --git a/requirements/testing.txt b/requirements/testing.txt index 99553d6..716aa73 100644 --- a/requirements/testing.txt +++ b/requirements/testing.txt @@ -1,5 +1,5 @@ -black==24.3.0 -coverage==7.2.7 -flake8==6.0.0 -isort==5.12.0 -pipdeptree==2.9.0 +black==24.4.2 +coverage==7.6.1 +flake8==7.1.0 +isort==5.13.2 +pipdeptree==2.23.3 From 96d2168f38873f07c21cbdb2d552302b2d99eb0c Mon Sep 17 00:00:00 2001 From: Alex Tomkins Date: Sat, 27 Jul 2024 21:31:28 +0100 Subject: [PATCH 6/9] Use tox-uv --- .github/workflows/ci.yml | 4 ++-- Makefile | 6 ++++++ requirements/local.txt | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ff87b13..88c87d0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: - name: Run tox id: matrix run: | - pip install $(grep "^tox==" requirements/local.txt) + pip install $(grep -E "^(tox|tox-uv)==" requirements/local.txt) echo "tox_matrix=$(tox -l | fgrep -v coverage | python .github/matrix.py)" >> $GITHUB_OUTPUT outputs: tox_matrix: ${{ steps.matrix.outputs.tox_matrix }} @@ -53,7 +53,7 @@ jobs: TOX_OVERRIDE: "testenv.passenv=PG*" PYTHON_VERSION: ${{ matrix.python }} run: | - pip install $(grep "^tox==" requirements/local.txt) + pip install $(grep -E "^(tox|tox-uv)==" requirements/local.txt) tox -e ${{ matrix.tox_env }} services: postgres: diff --git a/Makefile b/Makefile index 7f6b7e0..3a7f0ba 100644 --- a/Makefile +++ b/Makefile @@ -43,6 +43,9 @@ test: django-test test-report: ## Run and report on unit and integration tests. test-report: coverage-clean test coverage-report +test-lowest: ## Run tox with lowest (oldest) package dependencies. +test-lowest: tox-test-lowest + dist: ## Builds source and wheel package dist: clean build-dist @@ -153,6 +156,9 @@ pipdeptree-check: django-test: PYTHONWARNINGS=all coverage run $$(which django-admin) test --pythonpath $$(pwd) --settings tests.settings tests +tox-test-lowest: + tox --recreate --override testenv.uv_resolution=lowest + # Help help-display: diff --git a/requirements/local.txt b/requirements/local.txt index e49167e..83735e1 100644 --- a/requirements/local.txt +++ b/requirements/local.txt @@ -4,4 +4,5 @@ bump2version==1.0.1 Django>=4.2,<5.0 psycopg2==2.9.9 tox==4.18.1 +tox-uv==1.11.3 twine==5.1.1 From 33d585ffcc98770b6b5fdd08f3321d7e8b3aaaa8 Mon Sep 17 00:00:00 2001 From: Alex Tomkins Date: Sat, 27 Jul 2024 21:39:31 +0100 Subject: [PATCH 7/9] Switch to ruff --- .flake8 | 6 --- .github/matrix.py | 2 +- Makefile | 33 +++++---------- postgres_lock/lock.py | 17 ++++---- .../management/commands/command_lock.py | 2 +- pyproject.toml | 42 +++++++++++++------ requirements/testing.txt | 4 +- tests/settings.py | 2 +- 8 files changed, 51 insertions(+), 57 deletions(-) delete mode 100644 .flake8 diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 8148bef..0000000 --- a/.flake8 +++ /dev/null @@ -1,6 +0,0 @@ -[flake8] -max-line-length = 99 -# F405 - ignore wildcard variable warnings, as F403 (don't use wildcard imports) should show the -# problem anyway. But if we really need wildcard imports - we don't want to noqa every variable. -# W503 - line break before binary operator, considered not PEP 8 compliant by black. -ignore = F405,W503 diff --git a/.github/matrix.py b/.github/matrix.py index e87aa64..17a63d3 100644 --- a/.github/matrix.py +++ b/.github/matrix.py @@ -25,7 +25,7 @@ def main(): } ) - print(json.dumps(actions_matrix)) + print(json.dumps(actions_matrix)) # noqa:T201 if __name__ == "__main__": diff --git a/Makefile b/Makefile index 3a7f0ba..df0e566 100644 --- a/Makefile +++ b/Makefile @@ -32,10 +32,10 @@ check: ## Check for any obvious errors in the project's setup. check: pipdeptree-check format: ## Run this project's code formatters. -format: black-format isort-format +format: ruff-format lint: ## Lint the project. -lint: black-lint isort-lint flake8-lint +lint: ruff-lint test: ## Run unit and integration tests. test: django-test @@ -107,19 +107,6 @@ pip-install-local: venv-check pip install -r requirements/local.txt -# ISort -isort-lint: - isort --check-only --diff postgres_lock tests - -isort-format: - isort postgres_lock tests - - -# Flake8 -flake8-lint: - flake8 postgres_lock - - # Coverage coverage-report: coverage-combine coverage-html coverage-xml coverage report --show-missing @@ -139,17 +126,19 @@ coverage-clean: rm -f .coverage -# Black -black-lint: - black --check postgres_lock tests setup.py +# ruff +ruff-lint: + ruff check + ruff format --check -black-format: - black postgres_lock tests setup.py +ruff-format: + ruff check --fix-only + ruff format -#pipdeptree +# pipdeptree pipdeptree-check: - @pipdeptree --warn fail > /dev/null + pipdeptree --warn fail >/dev/null # Project testing diff --git a/postgres_lock/lock.py b/postgres_lock/lock.py index 094e3be..812f01e 100644 --- a/postgres_lock/lock.py +++ b/postgres_lock/lock.py @@ -26,10 +26,8 @@ def __init__(self, name=None, try_=False, shared=False, using=DEFAULT_DB_ALIAS): else: shared_str = "" - self.lock_function = "pg{try_str}_advisory_lock{shared_str}".format( - try_str=try_str, shared_str=shared_str - ) - self.unlock_function = "pg_advisory_unlock{shared_str}".format(shared_str=shared_str) + self.lock_function = f"pg{try_str}_advisory_lock{shared_str}" + self.unlock_function = f"pg_advisory_unlock{shared_str}" def get_lock_id(self, name): """ @@ -37,14 +35,13 @@ def get_lock_id(self, name): """ # Python 3 crc32 returns an unsigned integer, so we need to ensure we return a signed # integer instead. - lock_id = crc32(name.encode()) & 0xFFFFFFFF - return lock_id + return crc32(name.encode()) & 0xFFFFFFFF def lock(self): self.cursor = self.database_connection.cursor() self.cursor.execute( - "SELECT {lock_function}(%(lock_id)s)".format(lock_function=self.lock_function), - {"lock_function": self.lock_function, "lock_id": self.lock_id}, + f"SELECT {self.lock_function}(%(lock_id)s)", + {"lock_id": self.lock_id}, ) if self.try_lock: @@ -56,8 +53,8 @@ def lock(self): def release(self): self.cursor.execute( - "SELECT {unlock_function}(%(lock_id)s)".format(unlock_function=self.unlock_function), - {"unlock_function": self.unlock_function, "lock_id": self.lock_id}, + f"SELECT {self.unlock_function}(%(lock_id)s)", + {"lock_id": self.lock_id}, ) self.cursor.close() diff --git a/postgres_lock/management/commands/command_lock.py b/postgres_lock/management/commands/command_lock.py index 01e8edf..eea796c 100644 --- a/postgres_lock/management/commands/command_lock.py +++ b/postgres_lock/management/commands/command_lock.py @@ -45,7 +45,7 @@ def execute(self, *args, **options): using=options["database"], ) as acquired: if acquired: - completed = subprocess.run(options["command"]) + completed = subprocess.run(options["command"]) # noqa:S603 # Raise the return code of the child process if an error occurs if completed.returncode != 0: sys.exit(completed.returncode) diff --git a/pyproject.toml b/pyproject.toml index 16dec98..912329c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,15 +1,31 @@ -[tool.black] +[tool.ruff] line-length = 99 -target-version = ['py38'] -exclude = '/migrations/' +target-version = 'py38' -[tool.isort] -combine_as_imports = true -sections = ['FUTURE','STDLIB','DJANGO','THIRDPARTY','FIRSTPARTY','LOCALFOLDER'] -known_django = 'django' -include_trailing_comma = true -float_to_top = true -force_grid_wrap = 0 -line_length = 99 -multi_line_output = 3 -skip_glob = '*/migrations/*.py' +[tool.ruff.lint] +select = [ + 'F', # pyflakes + 'E', # pycodestyle + 'W', # pycodestyle + 'I', # isort + 'N', # pep8-naming + 'UP', # pyupgrade + 'S', # flake8-bandit + 'BLE', # flake8-blind-except + 'C4', # flake8-comprehensions + 'EM', # flake8-errmsg + 'T20', # flake8-print + 'RET', # flake8-return + 'RUF', # ruff +] +ignore = [ + 'EM101', # flake8-errmsg: raw-string-in-exception +] + +[tool.ruff.lint.isort] +combine-as-imports = true + +[tool.ruff.lint.pep8-naming] +extend-ignore-names = [ + 'assert*', +] diff --git a/requirements/testing.txt b/requirements/testing.txt index 716aa73..91e7702 100644 --- a/requirements/testing.txt +++ b/requirements/testing.txt @@ -1,5 +1,3 @@ -black==24.4.2 coverage==7.6.1 -flake8==7.1.0 -isort==5.13.2 pipdeptree==2.23.3 +ruff==0.6.5 diff --git a/tests/settings.py b/tests/settings.py index e1eb2e6..a04f6e4 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -9,6 +9,6 @@ USE_TZ = True -SECRET_KEY = "postgres_lock" +SECRET_KEY = "postgres_lock" # noqa:S105 INSTALLED_APPS = ["postgres_lock", "tests"] From ff707223c1e070319064c020a5bad0ad99d0fe18 Mon Sep 17 00:00:00 2001 From: Alex Tomkins Date: Sat, 14 Sep 2024 11:27:54 +0100 Subject: [PATCH 8/9] Test with psycopg v3 for newer versions of Django --- requirements/local.txt | 2 +- tox.ini | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/requirements/local.txt b/requirements/local.txt index 83735e1..cd771b0 100644 --- a/requirements/local.txt +++ b/requirements/local.txt @@ -2,7 +2,7 @@ bump2version==1.0.1 Django>=4.2,<5.0 -psycopg2==2.9.9 +psycopg==3.2.1 tox==4.18.1 tox-uv==1.11.3 twine==5.1.1 diff --git a/tox.ini b/tox.ini index d0aa199..8067fb7 100644 --- a/tox.ini +++ b/tox.ini @@ -15,7 +15,8 @@ deps = django3.2: Django>=3.2,<4.0 django4.2: Django>=4.2,<5.0 django2.2: psycopg2>=2.8,<2.9 - django3.2,django4.2: psycopg2>=2.9,<2.10 + django3.2: psycopg2>=2.9,<2.10 + django4.2: psycopg<3.3 allowlist_externals = make commands = make test package = editable From 683f505671be120e9cd4d146d664ca1b66ca7152 Mon Sep 17 00:00:00 2001 From: Alex Tomkins Date: Sat, 14 Sep 2024 11:30:32 +0100 Subject: [PATCH 9/9] CI package bump --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 88c87d0..c43dfe9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,7 +6,7 @@ concurrency: jobs: matrix: name: Build test matrix - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 steps: - name: Checkout uses: actions/checkout@v4 @@ -28,7 +28,7 @@ jobs: test: name: Test -- ${{ matrix.tox_env }} - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 needs: matrix strategy: matrix: @@ -57,7 +57,7 @@ jobs: tox -e ${{ matrix.tox_env }} services: postgres: - image: postgres:15-alpine + image: postgres:16-alpine env: POSTGRES_PASSWORD: password ports: