diff --git a/.flake8 b/.flake8 deleted file mode 100644 index ff29b0b..0000000 --- a/.flake8 +++ /dev/null @@ -1,53 +0,0 @@ -[flake8] -max-line-length = 88 -max-complexity = 8 -# http://flake8.pycqa.org/en/2.5.5/warnings.html#warning-error-codes -ignore = - # pydocstyle - docstring conventions (PEP257) - # Missing docstring in public module - D100 - # Missing docstring in public class - D101 - # Missing docstring in public method - D102 - # Missing docstring in public function - D103 - # Missing docstring in public package - D104 - # Missing docstring in magic method - D105 - # Missing docstring in public nested class - D106 - # Missing docstring in __init__ - D107 - # No blank lines allowed between a section header and its content - D412 - # pycodestyle - style checker (PEP8) - # line break before binary operator - W503 - # the following are ignored in CI using --extend-ignore option: - # [pydocstyle] 1 blank line required between summary line and description - ; D205 - # [pydocstyle] First line should end with a period - ; D400 - # [pydocstyle] First line should be in imperative mood - ; D401 - # [bandit] Use of mark_safe() may expose cross-site scripting vulnerabilities and should be reviewed. - ; S308 - # [bandit] Potential XSS on mark_safe function. - ; S703 - -per-file-ignores = - ; D205 - 1 blank line required between summary line and description - ; D400 - First line should end with a period - ; D401 - First line should be in imperative mood - ; S101 - use of assert - ; S106 - hard-coded password - ; E501 - line-length - ; E731 - assigning a lambda to a variable - *tests/*:D205,D400,D401,S101,S106,E501,E731 - */migrations/*:E501 - ; F403 - unable to detect undefined names - ; F405 - may be undefined, or defined from star imports - */settings.py:F403,F405 - */settings/*:F403,F405 diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index d900b1f..9497167 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -14,15 +14,38 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - toxenv: [fmt, lint, mypy, checks] + toxenv: [fmt, lint, mypy] env: TOXENV: ${{ matrix.toxenv }} steps: - name: Check out the repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - - name: Set up Python 3.11 + - name: Set up Python (3.11) + uses: actions/setup-python@v4 + with: + python-version: "3.11" + + - name: Install and run tox + run: | + pip install tox + tox + + checks: + name: Run Django checks + runs-on: ubuntu-latest + strategy: + matrix: + toxenv: ["django-checks"] + env: + TOXENV: ${{ matrix.toxenv }} + + steps: + - name: Check out the repository + uses: actions/checkout@v4 + + - name: Set up Python (3.11) uses: actions/setup-python@v4 with: python-version: "3.11" @@ -37,15 +60,31 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python: ["3.8", "3.11"] - django: ["32", "41", "main"] + python: ["3.8", "3.9", "3.10", "3.11", "3.12"] + # build LTS version, next version, HEAD + django: ["32", "42", "50", "main"] + exclude: + - python: "3.8" + django: "50" + - python: "3.8" + django: "main" + - python: "3.9" + django: "50" + - python: "3.9" + django: "main" + - python: "3.10" + django: "main" + - python: "3.11" + django: "32" + - python: "3.12" + django: "32" env: - TOXENV: py${{ matrix.python }}-django${{ matrix.django }} + TOXENV: django${{ matrix.django }}-py${{ matrix.python }} steps: - name: Check out the repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python }} uses: actions/setup-python@v4 diff --git a/.isort.cfg b/.isort.cfg deleted file mode 100644 index a32eb71..0000000 --- a/.isort.cfg +++ /dev/null @@ -1,8 +0,0 @@ -[settings] -default_section=THIRDPARTY -indent=' ' -sections=FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,TESTS,LOCALFOLDER -multi_line_output=3 -line_length=88 -include_trailing_comma=True -use_parentheses=True diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 09b0c57..def9258 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,36 +1,20 @@ repos: - # python import sorting - will amend files - - repo: https://github.com/pre-commit/mirrors-isort - rev: v5.10.1 - hooks: - - id: isort - # python code formatting - will amend files - repo: https://github.com/ambv/black - rev: 22.10.0 + rev: 23.10.1 hooks: - id: black - - repo: https://github.com/asottile/pyupgrade - rev: v3.2.0 - hooks: - - id: pyupgrade - - # Flake8 includes pyflakes, pycodestyle, mccabe, pydocstyle, bandit - - repo: https://gitlab.com/pycqa/flake8 - rev: 3.9.2 + - repo: https://github.com/charliermarsh/ruff-pre-commit + # Ruff version. + rev: "v0.1.5" hooks: - - id: flake8 - additional_dependencies: - - flake8-bandit - - flake8-blind-except - - flake8-docstrings - - flake8-logging-format - - flake8-print + - id: ruff + args: [--fix, --exit-non-zero-on-fix] # python static type checking - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.982 + rev: v1.7.0 hooks: - id: mypy args: @@ -40,4 +24,3 @@ repos: - --no-implicit-optional - --ignore-missing-imports - --follow-imports=silent - exclude: ^tests diff --git a/.ruff.toml b/.ruff.toml new file mode 100644 index 0000000..ccc1947 --- /dev/null +++ b/.ruff.toml @@ -0,0 +1,66 @@ +line-length = 88 +ignore = [ + "D100", # Missing docstring in public module + "D101", # Missing docstring in public class + "D102", # Missing docstring in public method + "D103", # Missing docstring in public function + "D104", # Missing docstring in public package + "D105", # Missing docstring in magic method + "D106", # Missing docstring in public nested class + "D107", # Missing docstring in __init__ + "D203", # 1 blank line required before class docstring + "D212", # Multi-line docstring summary should start at the first line + "D213", # Multi-line docstring summary should start at the second line + "D404", # First word of the docstring should not be "This" + "D405", # Section name should be properly capitalized + "D406", # Section name should end with a newline + "D407", # Missing dashed underline after section + "D410", # Missing blank line after section + "D411", # Missing blank line before section + "D412", # No blank lines allowed between a section header and its content + "D416", # Section name should end with a colon + "D417", + "D417", # Missing argument description in the docstring +] +select = [ + "A", # flake8 builtins + "C9", # mcabe + "D", # pydocstyle + "E", # pycodestyle (errors) + "F", # Pyflakes + "I", # isort + "S", # flake8-bandit + "T2", # flake8-print + "W", # pycodestype (warnings) +] + +[isort] +combine-as-imports = true + +[mccabe] +max-complexity = 8 + +[per-file-ignores] +"*tests/*" = [ + "D205", # 1 blank line required between summary line and description + "D400", # First line should end with a period + "D401", # First line should be in imperative mood + "D415", # First line should end with a period, question mark, or exclamation point + "E501", # Line too long + "E731", # Do not assign a lambda expression, use a def + "S101", # Use of assert detected + "S105", # Possible hardcoded password + "S106", # Possible hardcoded password + "S113", # Probable use of requests call with timeout set to {value} +] +"*/migrations/*" = [ + "E501", # Line too long +] +"*/settings.py" = [ + "F403", # from {name} import * used; unable to detect undefined names + "F405", # {name} may be undefined, or defined from star imports: +] +"*/settings/*" = [ + "F403", # from {name} import * used; unable to detect undefined names + "F405", # {name} may be undefined, or defined from star imports: +] diff --git a/pyproject.toml b/pyproject.toml index a0a3a69..df48370 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "django-side-effects" -version = "2.0.b4" +version = "2.0" description = "Django app for managing external side effects." license = "MIT" authors = ["YunoJuno "] @@ -13,35 +13,32 @@ classifiers = [ "Framework :: Django :: 3.2", "Framework :: Django :: 4.0", "Framework :: Django :: 4.1", + "Framework :: Django :: 4.2", + "Framework :: Django :: 5.0", "Operating System :: OS Independent", "Programming Language :: Python :: 3 :: Only", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", ] packages = [{ include = "side_effects" }] [tool.poetry.dependencies] python = "^3.8" -django = "^3.2 || ^4.0" +django = "^3.2 || ^4.0 || ^5.0 " [tool.poetry.dev-dependencies] -black = {version = "*", allow-prereleases = true} +black = "*" coverage = "*" -flake8 = "*" -flake8-bandit = "*" -flake8-blind-except = "*" -flake8-docstrings = "*" -flake8-logging-format = "*" -flake8-print = "*" freezegun = "*" -isort = "*" mypy = "*" pre-commit = "*" pytest = "*" pytest-cov = "*" pytest-django = "*" +ruff = "*" tox = "*" [build-system] diff --git a/side_effects/apps.py b/side_effects/apps.py index 67aba33..e631df7 100644 --- a/side_effects/apps.py +++ b/side_effects/apps.py @@ -8,7 +8,6 @@ class SideEffectsConfig(AppConfig): - name = "side_effects" verbose_name = "External Side Effects" diff --git a/side_effects/management/commands/display_side_effects.py b/side_effects/management/commands/display_side_effects.py index 57e0891..3daf80d 100644 --- a/side_effects/management/commands/display_side_effects.py +++ b/side_effects/management/commands/display_side_effects.py @@ -31,8 +31,7 @@ def sort_events( class Command(BaseCommand): - - help = "Displays project side_effects." + help = "Displays project side_effects." # noqa: A003 def __init__(self, *args: Any, **kwargs: Any) -> None: self.missing_docstrings: List[str] = [] @@ -160,7 +159,7 @@ def print_missing(self) -> None: else: self.stdout.write("\nAll registered functions have docstrings") - def exit(self) -> None: + def exit(self) -> None: # noqa: A003 """ Exit based on whether there are any missing docstrings. diff --git a/tests/__init__.py b/tests/__init__.py index 6ee8be2..6447de8 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -4,19 +4,19 @@ @has_side_effects("foo") def origin(message: str) -> str: - print(f"origin: {message}") # noqa: T001 + print(f"origin: {message}") # noqa: T201 return f"Message received: {message}" @is_side_effect_of("foo") def no_docstring(message: str) -> None: - print(f"side-effect.1: message={message}") # noqa: T001 + print(f"side-effect.1: message={message}") # noqa: T201 @is_side_effect_of("foo") def one_line_docstring(message: str) -> None: """This is a one-line docstring.""" - print(f"side-effect.2: message={message}") # noqa: T001 + print(f"side-effect.2: message={message}") # noqa: T201 @is_side_effect_of("foo") @@ -27,6 +27,6 @@ def multi_line_docstring(message: str, return_value: str) -> None: It has more information here. """ - print( # noqa: T001 + print( # noqa: T201 f"Side-effect.3: message={message}, return_value={return_value}" ) diff --git a/tests/test_decorators.py b/tests/test_decorators.py index 64b86b2..a741ef1 100644 --- a/tests/test_decorators.py +++ b/tests/test_decorators.py @@ -31,6 +31,7 @@ def test_http_response_check(self): @mock.patch("side_effects.decorators.registry") def test_has_side_effects(self, mock_registry): """Decorated functions should call run_side_effects.""" + # call the decorator directly - then call the decorated function # as the action takes places post-function call. def test_func(arg1: int): @@ -71,7 +72,6 @@ def test_func(arg1, arg2): @decorators.disable_side_effects() def test_disable_side_effects(self, events): - # simple func that calls the side-effect 'foo' def test_func(): registry.run_side_effects("foo") diff --git a/tox.ini b/tox.ini index 46e0089..4c663f9 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,15 @@ [tox] isolated_build = True -envlist = fmt, lint, mypy, checks, py{3.8,3.9,3.10,3.11}-django{32,40,41,main} +envlist = + fmt, lint, mypy, + django-checks, + ; https://docs.djangoproject.com/en/5.0/releases/ + django32-py{38,39,310} + django40-py{38,39,310} + django41-py{38,39,310,311} + django42-py{38,39,310,311} + django50-py{310,311,312} + djangomain-py{311,312} [testenv] deps = @@ -11,12 +20,14 @@ deps = django32: Django>=3.2,<3.3 django40: Django>=4.0,<4.1 django41: Django>=4.1,<4.2 + django42: Django>=4.2,<4.3 + django50: https://github.com/django/django/archive/stable/5.0.x.tar.gz djangomain: https://github.com/django/django/archive/main.tar.gz commands = - pytest --cov=side_effects tests + pytest --cov=side_effects --verbose tests/ -[testenv:checks] +[testenv:django-checks] description = Django system checks and missing migrations deps = Django commands = @@ -24,29 +35,23 @@ commands = python manage.py makemigrations --dry-run --check --verbosity 3 [testenv:fmt] -description = 'Source file formatting' +description = Python source code formatting (black) deps = - isort black commands = - isort --check-only side_effects black --check side_effects [testenv:lint] -description = 'Source file linting' +description = Python source code linting (ruff) deps = - flake8 - flake8-bandit - flake8-blind-except - flake8-docstrings - flake8-logging-format - flake8-print + ruff commands = - flake8 side_effects + ruff side_effects [testenv:mypy] +description = Python source code type hints (mypy) deps = mypy