diff --git a/CHANGELOG.md b/CHANGELOG.md index b70e2fcc..c3c03def 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +### Changed + +- Move from deprecated `ruff` config to new in `pyproject.toml`. ## [2024.2] diff --git a/pyproject.toml b/pyproject.toml index c778a7f6..b9dbdc27 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,6 +48,71 @@ norecursedirs = ".* bin build dist *.egg examples htmlcov logs node_modules src python_files = "tests.py test_*.py *_tests.py" testpaths = ["tests"] +[tool.ruff] +# Exclude a variety of commonly ignored directories. +exclude = [ + ".bzr", + ".direnv", + ".eggs", + ".git", + ".github", + ".hg", + ".mypy_cache", + ".ruff_cache", + ".svn", + ".tox", + ".venv", + "__pypackages__", + "_build", + "build", + "dist", + "migrations", + "node_modules", + "venv" +] +extend-include = ["*.pyi?"] +indent-width = 4 +# Same as Black. +line-length = 88 +# Assume Python >3.8. +target-version = "py38" + +[tool.ruff.format] +# Like Black, indent with spaces, rather than tabs. +indent-style = "space" +# Like Black, automatically detect the appropriate line ending. +line-ending = "auto" +# Like Black, use double quotes for strings. +quote-style = "double" + +[tool.ruff.lint] +# Allow unused variables when underscore-prefixed. +dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" +# Allow autofix for all enabled rules (when `--fix`) is provided. +fixable = ["A", "B", "C", "D", "E", "F", "I"] +ignore = ["E501", "E741"] # temporary +select = [ + "B", # flake8-bugbear + "E", # Pycodestyle + "F", # Pyflakes + "I", # isort + "UP" # pyupgrade +] +unfixable = [] + +[tool.ruff.lint.isort] +force-single-line = true +known-first-party = [] +required-imports = ["from __future__ import annotations"] + +[tool.ruff.lint.per-file-ignores] +# Tests can use magic values, assertions, and relative imports +"tests/**/*" = ["PLR2004", "S101", "TID252"] + +[tool.ruff.lint.pyupgrade] +# Preserve types, even if a file imports `from __future__ import annotations`. +keep-runtime-typing = true + [tool.rye] dev-dependencies = [ "bumpver>=2023.1129", diff --git a/src/django_twc_project/pyproject.toml.jinja b/src/django_twc_project/pyproject.toml.jinja index 97942889..aa720612 100644 --- a/src/django_twc_project/pyproject.toml.jinja +++ b/src/django_twc_project/pyproject.toml.jinja @@ -81,8 +81,6 @@ norecursedirs = ".* bin build dist *.egg htmlcov logs node_modules static templa python_files = "tests.py test_*.py *_tests.py" [tool.ruff] -# Allow unused variables when underscore-prefixed. -dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" # Exclude a variety of commonly ignored directories. exclude = [ ".bzr", @@ -91,6 +89,7 @@ exclude = [ ".git", ".github", ".hg", + ".mypy_cache", ".ruff_cache", ".svn", ".tox", @@ -101,24 +100,14 @@ exclude = [ "dist", "migrations", "node_modules", - "static", "venv" ] -# Allow autofix for all enabled rules (when `--fix`) is provided. -fixable = ["A", "B", "C", "D", "E", "F", "I"] -ignore = ["E501", "E741"] # temporary +extend-include = ["*.pyi?"] indent-width = 4 # Same as Black. line-length = 88 -select = [ - "B", # flake8-bugbear - "E", # Pycodestyle - "F", # Pyflakes - "I" # isort -] -# Assume Python {{ python_version }}. +# Assume Python {{ python_version }} target-version = "py{{ python_version | replace('.', '') }}" -unfixable = [] [tool.ruff.format] # Like Black, indent with spaces, rather than tabs. @@ -128,15 +117,30 @@ line-ending = "auto" # Like Black, use double quotes for strings. quote-style = "double" -[tool.ruff.isort] +[tool.ruff.lint] +# Allow unused variables when underscore-prefixed. +dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" +# Allow autofix for all enabled rules (when `--fix`) is provided. +fixable = ["A", "B", "C", "D", "E", "F", "I"] +ignore = ["E501", "E741"] # temporary +select = [ + "B", # flake8-bugbear + "E", # Pycodestyle + "F", # Pyflakes + "I", # isort + "UP" # pyupgrade +] +unfixable = [] + +[tool.ruff.lint.isort] force-single-line = true known-first-party = ["{{ module_name }}"] required-imports = ["from __future__ import annotations"] -[tool.ruff.per-file-ignores] +[tool.ruff.lint.per-file-ignores] # Tests can use magic values, assertions, and relative imports "tests/**/*" = ["PLR2004", "S101", "TID252"] -[tool.ruff.pyupgrade] +[tool.ruff.lint.pyupgrade] # Preserve types, even if a file imports `from __future__ import annotations`. keep-runtime-typing = true diff --git a/tests/__init__.py b/tests/__init__.py index 9628e3ac..2d2276bb 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -2,7 +2,6 @@ import logging - pytest_plugins = [] # type: ignore diff --git a/tests/test_version.py b/tests/test_version.py index 1eeffef8..b9470606 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -1,6 +1,7 @@ from __future__ import annotations from pathlib import Path + import yaml BASE_DIR = Path(__file__).parent.parent