Skip to content

Commit

Permalink
chore: replace black with ruff as the formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
wood-push-melon committed May 22, 2024
1 parent 6ad21ce commit 074560a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
5 changes: 1 addition & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion fmt-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
black
ruff
2 changes: 0 additions & 2 deletions lint-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
black
codespell
pre-commit
ruff
28 changes: 19 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
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",
Expand All @@ -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"
Expand Down
13 changes: 5 additions & 8 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 074560a

Please sign in to comment.