Skip to content

Commit

Permalink
- update tox for newer version of python and packages.
Browse files Browse the repository at this point in the history
- removed redundant package versions.
- moved to ruff, ran on all files, and fixed all errors.
- removed isort, flake8, and black
- added docker-compose.yml to create a redis server for running tox tests.
- Updated CHANGES.md with what we have done.
- Update makefile and added some new commands.
- Updated README.md
  • Loading branch information
DelboyJay committed Dec 10, 2024
1 parent 4716bbb commit 1f39c41
Show file tree
Hide file tree
Showing 25 changed files with 263 additions and 318 deletions.
16 changes: 0 additions & 16 deletions .flake8

This file was deleted.

8 changes: 1 addition & 7 deletions .github/actions/tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,7 @@ runs:
- name: Start Redis
uses: supercharge/[email protected]

- name: tox tests for python 3.7
- name: tox tests
shell: bash
if: ${{inputs.python-version == '3.7'}}
run: tox -e py37-django22-drf38,py37-django22-drf39,py37-django22-drf310,py37-django22-drf311,py37-django22-drf312,py37-django22-drf313,py37-django32-drf311,py37-django32-drf312,py37-django32-drf313

- name: tox tests for python >= 3.8
shell: bash
if: ${{inputs.python-version != '3.7'}}
run: |
tox
2 changes: 1 addition & 1 deletion .github/workflows/continuous_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
fail-fast: false
steps:
- name: Check out repository
Expand Down
9 changes: 0 additions & 9 deletions .isort.cfg

This file was deleted.

71 changes: 36 additions & 35 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.2
hooks:
- id: ruff
alias: autoformat
args: [--fix]
language_version: python3.9
- id: ruff-format
language_version: python3.9

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black

- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies: [flake8-bugbear]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-byte-order-marker
- id: check-case-conflict
- id: check-json
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: detect-private-key
- id: end-of-file-fixer
- id: fix-encoding-pragma
args: [--remove]
- id: forbid-new-submodules
- id: mixed-line-ending
args: [--fix=lf]
- id: trailing-whitespace
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-ast
language_version: python3.12
- id: check-byte-order-marker
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-json
- id: check-symlinks
- id: check-toml
- id: check-vcs-permalinks
- id: check-xml
- id: check-yaml
- id: debug-statements
language_version: python3.9
- id: detect-private-key
- id: end-of-file-fixer
- id: fix-encoding-pragma
args: [--remove]
- id: forbid-new-submodules
- id: mixed-line-ending
args: [--fix=lf]
- id: no-commit-to-branch
args: [--branch=master]
- id: trailing-whitespace
40 changes: 40 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# https://docs.astral.sh/ruff/tutorial/#configuration
# https://docs.astral.sh/ruff/settings/
# Set the maximum line length to 88.
line-length = 88
indent-width = 4
target-version="py39"

[lint]
select = [
"B", # flake8-bugbear
"C",
"DJ", # flake8-django
"E", # pycodestyle
"F", # Pyflakes
"I", # isort
"PL", # pylint
"UP", # pyupgrade
"W",
"B9"
]
ignore = ["E203", "B904", "DJ001", "DJ006", "W191"]


# Add the `line-too-long` rule to the enforced rule set. By default, Ruff omits rules that
# overlap with the use of a formatter, like Black, but we can override this behavior by
# explicitly adding the rule.
extend-select = ["E501"]

[format]
quote-style = "double"
indent-style = "space"

[lint.isort]
known-first-party = ["deployer"]

[lint.mccabe] # DO NOT INCREASE THIS VALUE
max-complexity = 18 # default: 10

[lint.pylint]
max-args = 10
14 changes: 14 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ updating.

**[Breaking changes]** - There are changes that break existing compatibility.

---
# 1.4.0
**[Dropped support]**
- Python 3.7 and 3.8
- Django 2.2

**[Added support]**
- Python 3.12 & 3.13
- Django 5.0 & 5.1

**[Security updates]**
-

---
# 1.3.0
**[Dropped support]**
Expand All @@ -28,6 +41,7 @@ updating.
- Added support for Django 4.1 and Django 4.2
- Added HTTP_AUTHORIZATION header when generating encoded key for extra security. (Submitted by Artem)

---
# 1.2.0
**[Dropped support]**

Expand Down
49 changes: 28 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,51 +1,54 @@
.PHONY: build
build: clean database

.PHONY: lint
lint:
poetry run pre-commit run --all-files

.PHONY: clean
clean:
rm -rf .tox/ .pytest_cache/ dist/ htmlcov/ .coverage coverage.xml db.sqlite3
find . -type f -name "*.pyc" -delete

.PHONY: database
database:
psql -lqt | cut -d \| -f 1 | grep -wq idempotency-key || createdb idempotency-key
poetry run ./manage.py migrate

static_analysis: pep8 xenon black

black:
@echo "Running black over codebase"
black .

pep8:
@echo "Running flake8 over codebase"
flake8 --ignore=E501,W391,F999 --exclude=migrations idempotency_key/

xenon:
@echo "Running xenon over codebase"
poetry run xenon --max-absolute C --max-modules B --max-average A --exclude test_*.py idempotency_key/

test: static_analysis coverage
.PHONY: test
test: coverage
# ensure that `docker compose up` is running to start the redis server before
# running these tests.
poetry run tox $(pytest_args)

coverage:
.PHONY: coverage
coverage: lint
poetry run py.test --cov=idempotency_key tests/ --cov-report html
@echo Access the report here:
@echo file://${PWD}/htmlcov/index.html

bundle: static_analysis coverage
.PHONY: bundle
bundle: coverage
rm -r ./dist/ || true
poetry build

.PHONY: release-test
release-test:
poetry run twine upload --repository-url https://test.pypi.org/legacy/ dist/django_idempotency_key-1.3.0.tar.gz

release: static_analysis coverage
.PHONY: release
release: coverage
poetry run twine upload dist/*

.PHONY: bump-major
bump-major:
poetry run bump2version major

.PHONY: bump-minor
bump-minor:
poetry run bump2version minor

.PHONY: bump-patch
bump-patch:
poetry run bump2version patch

Expand All @@ -57,6 +60,10 @@ install-poetry:
uninstall-poetry:
curl -sSL https://install.python-poetry.org | python3 - --uninstall

.PHONY: bump-major bump-minor bump-patch bundle clean coverage database pep8 black
.PHONY: release release-test static_analysis test virtualenv xenon
.PHONY: install-poetry uninstall-poetry
.PHONY: tree
tree:
tree -I __pycache__ -I *.pyc 2>/dev/null

.PHONY: showoutdatedpackages
showoutdatedpackages:
poetry show --outdated -T
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,21 @@ nothing new is created.

Django idempotency key requires the following:

Python (3.7 to 3.11)
Python (3.9 to 3.13)

Django (2.2, 3.2, 4.0, 4.1, 4.2)
Django (3.2, 4.0, 4.1, 4.2)

The following is a list of Django versions and the respective
DjangoRestFramework and python versions that it supports.

Python | Django | DRF
--------|--------|--------
\>=3.7 | 2.2 | \>=3.8
\>=3.7 | 3.2 | \>=3.11
\>=3.8 | 4.0 | \>=3.13
\>=3.8 | 4.1 | \>=3.14
\>=3.8 | 4.2 | \>=3.14
Python | Django | DRF
---------|--------|--------
\>=3.9 | 3.2 | \>=3.11
\>=3.9 | 4.0 | \>=3.13
\>=3.9 | 4.1 | \>=3.14
\>=3.9 | 4.2 | \>=3.14
\>=3.10 | 5.0 | \>=3.15
\>=3.10 | 5.1 | \>=3.15

## Installation

Expand Down
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3.8'

services:
redis:
image: redis:7 # Use the desired Redis version
container_name: redis_local
ports:
- "6379:6379" # Maps host port 6379 to container port 6379
command: ["redis-server", "--appendonly", "yes"] # Enables persistence
volumes:
- redis_data:/data # Persist data

volumes:
redis_data:
driver: local
2 changes: 1 addition & 1 deletion idempotency_key/encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from idempotency_key.exceptions import MissingIdempotencyKeyError


class IdempotencyKeyEncoder(object):
class IdempotencyKeyEncoder:
@abc.abstractmethod
def encode_key(self, request, key):
raise NotImplementedError
Expand Down
8 changes: 4 additions & 4 deletions idempotency_key/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ def _set_flags_from_callback(self, request, callback):
if idempotency_key and idempotency_key_exempt:
raise DecoratorsMutuallyExclusiveError(
"@idempotency_key and @idempotency_key_exempt decorators are mutually "
'exclusive for function "{}"'.format(func_name)
f'exclusive for function "{func_name}"'
)

if idempotency_key_manual and idempotency_key_exempt:
raise DecoratorsMutuallyExclusiveError(
"@idempotency_key_manual and @idempotency_key_exempt decorators are "
'mutually exclusive for function "{}"'.format(func_name)
f'mutually exclusive for function "{func_name}"'
)

request.idempotency_key_optional = idempotency_key_optional
Expand Down Expand Up @@ -235,13 +235,13 @@ def _set_flags_from_callback(self, request, callback):
if idempotency_key and idempotency_key_exempt:
raise DecoratorsMutuallyExclusiveError(
"@idempotency_key and @idempotency_key_exempt decorators are mutually "
'exclusive for function "{}"'.format(func_name)
f'exclusive for function "{func_name}"'
)

if idempotency_key_manual and idempotency_key_exempt:
raise DecoratorsMutuallyExclusiveError(
"@idempotency_key_manual and @idempotency_key_exempt decorators are "
'mutually exclusive for function "{}"'.format(func_name)
f'mutually exclusive for function "{func_name}"'
)

request.idempotency_key_optional = idempotency_key_optional
Expand Down
Loading

0 comments on commit 1f39c41

Please sign in to comment.