diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 46717c2b..b90210b9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,10 +13,7 @@ repos: hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] -- repo: https://github.com/psf/black - rev: 24.4.1 - hooks: - - id: black + - id: ruff-format - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.9.0 hooks: diff --git a/fmt-requirements.txt b/fmt-requirements.txt index dc109e20..af3ee576 100644 --- a/fmt-requirements.txt +++ b/fmt-requirements.txt @@ -1,2 +1 @@ -black ruff diff --git a/lint-requirements.txt b/lint-requirements.txt index 0a78334f..8fde0d33 100644 --- a/lint-requirements.txt +++ b/lint-requirements.txt @@ -1,4 +1,2 @@ -black codespell -pre-commit ruff diff --git a/pyproject.toml b/pyproject.toml index 57f8f7e9..8bc1e6c4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,21 +22,24 @@ show_missing = true minversion = "6.0" log_cli_level = "INFO" -# Formatting tools configuration -[tool.black] -line-length = 99 -target-version = ["py38"] - -# Linting tools configuration +# Linting and formatting tools configuration [tool.ruff] +# Default settings: https://docs.astral.sh/ruff/configuration/ +# Settings: https://docs.astral.sh/ruff/settings/ line-length = 99 include = ["pyproject.toml", "src/**/*.py", "tests/**/*.py", "lib/charms/glauth_k8s/**/.py"] extend-exclude = ["__pycache__", "*.egg_info"] [too.ruff.lint] +# Rules: https://docs.astral.sh/ruff/rules/ select = ["E", "W", "F", "C", "N", "D", "I001"] -ignore = ["D100", "D101", "D102", "D103", "D105", "D107", "E501", "N818"] -extend-ignore = [ +ignore = [ + "D100", + "D101", + "D102", + "D103", + "D105", + "D107", "D203", "D204", "D213", @@ -48,15 +51,22 @@ extend-ignore = [ "D408", "D409", "D413", + "E501", + "N818" ] per-file-ignores = {"tests/*" = ["D100","D101","D102","D103","D104"]} +[too.ruff.lint.flake8-copyright] +author = "Canonical Ltd." +notice-rgx = "Copyright\\s\\d{4}([-,]\\d{4})*\\s+%(author)s" + [tool.ruff.lint.mccabe] max-complexity = 10 [tool.ruff.lint.pydocstyle] convention = "google" +# Type checking tools configuration [tool.mypy] pretty = true mypy_path = "./src:./lib/:./tests" diff --git a/tox.ini b/tox.ini index 41cd3619..b448623b 100644 --- a/tox.ini +++ b/tox.ini @@ -28,16 +28,17 @@ deps = pre-commit mypy types-PyYAML + -r{toxinidir}/fmt-requirements.txt + -r{toxinidir}/lint-requirements.txt commands = pre-commit install -t commit-msg [testenv:fmt] -description = Apply coding style standards to code +description = Apply coding style standards deps = -r{toxinidir}/fmt-requirements.txt commands = - black {[vars]all_path} - ruff check --fix {[vars]all_path} + ruff format {[vars]all_path} [testenv:lint] description = Check code against coding style standards @@ -54,11 +55,7 @@ commands = --skip {toxinidir}/.mypy_cache \ --skip {toxinidir}/icon.svg - ruff check {[vars]all_path} - black --check --diff {[vars]all_path} - - pre-commit install - pre-commit autoupdate + ruff check --diff {[vars]all_path} [testenv:unit] description = Run unit tests