Skip to content

Commit

Permalink
Merge pull request #43 from woltapp/introduce-ruff
Browse files Browse the repository at this point in the history
Introduce ruff, ditch flake8, black and friends
  • Loading branch information
jerry-git authored Mar 14, 2024
2 parents 095a9cd + f25dccf commit f84c02c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 84 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ A [cookiecutter](https://cookiecutter.readthedocs.io/en/latest/README.html) (pro
* [Poetry](https://python-poetry.org/docs/) for managing dependencies and packaging
* [pre-commit](https://pre-commit.com/) for running all the goodies listed below
* [mypy](https://flake8.pycqa.org/en/latest/) for static type checking
* [flake8](https://flake8.pycqa.org/en/latest/) (with multiple plugins) for linting (e.g. style and complexity checks, commented code, etc.)
* [black](https://black.readthedocs.io/en/stable/) for auto-formatting the code
* [isort](https://pycqa.github.io/isort/) for auto-sorting imports
* [autoflake](https://github.com/myint/autoflake) for auto-removing unused imports
* [ruff](https://beta.ruff.rs/docs/) for automatic formatting, linting and automatically fixing some linting errors

#### Automation

Expand Down
32 changes: 10 additions & 22 deletions {{cookiecutter.project_slug}}/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,26 @@ repos:
- id: mixed-line-ending
- repo: local
hooks:
- id: autoflake
name: autoflake
entry: poetry run autoflake -r -i --remove-all-unused-imports --remove-unused-variables
- id: ruff-format
name: ruff-format
entry: poetry run ruff format
require_serial: true
language: system
types: [ python ]
- id: isort
name: isort
entry: poetry run isort
language: system
types: [python]
- id: black
name: black
entry: poetry run black
language: system
types: [python]
- id: pyupgrade
name: pyupgrade
entry: poetry run pyupgrade --py37-plus
- id: ruff
name: ruff
# Add --fix, in case you want it to autofix when this hook runs
entry: poetry run ruff check --force-exclude
require_serial: true
language: system
types: [python]
types: [ python ]
- id: mypy
name: mypy
entry: poetry run mypy .
require_serial: true
language: system
types: [python]
pass_filenames: false
- id: flake8
name: flake8
entry: poetry run flake8
language: system
types: [python]
- id: kacl-verify
name: kacl-verify
entry: poetry run kacl-cli verify
Expand Down
2 changes: 1 addition & 1 deletion {{cookiecutter.project_slug}}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Find the draft release from the

### Pre-commit

Pre-commit hooks run all the auto-formatters (e.g. `black`, `isort`), linters (e.g. `mypy`, `flake8`), and other quality
Pre-commit hooks run all the auto-formatting (`ruff format`), linters (e.g. `ruff` and `mypy`), and other quality
checks to make sure the changeset is in good shape before a commit/push happens.

You can install the hooks with (runs for each commit):
Expand Down
49 changes: 30 additions & 19 deletions {{cookiecutter.project_slug}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,40 +35,51 @@ packages = [
python = ">=3.8.1, <4.0"

[tool.poetry.dev-dependencies]
autoflake = "*"
black = "*"
flake8 = "*"
flake8-bugbear = "*"
flake8-builtins = "*"
flake8-comprehensions = "*"
flake8-debugger = "*"
flake8-eradicate = "*"
flake8-logging-format = "*"
isort = "*"
mkdocstrings = {version = ">=0.23", extras = ["python"]}
mkdocs-material = "*"
mypy = "*"
pep8-naming = "*"
pre-commit = "*"
pymdown-extensions = "*"
pytest = "*"
pytest-github-actions-annotate-failures = "*"
pytest-cov = "*"
python-kacl = "*"
pyupgrade = "*"
tryceratops = "*"
ruff = ">=0.2.0"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.isort]
profile = "black"
src_paths = ["src", "tests"]
[tool.ruff]
target-version = "py38" # The lowest supported version

[tool.black]
target-version = ["py38", "py39", "py310", "py311", "py312"]
include = '\.pyi?$'
[tool.ruff.lint]
# By default, enable all the lint rules.
# Add to the ignore list below if you don't want some rules.
# If you need some ignores for certain modules, see tool.ruff.lint.per-file-ignores below.
# For individual ignore cases, prefer inline `# noqa`s within the code.
select = ["ALL"]
ignore = [
"ANN", # Type hints related, let mypy handle these.
"D", # Docstrings related, way too strict to our taste
]

[tool.ruff.lint.per-file-ignores]
"tests/**" = [
"S101", # "Use of `assert` detected"
"ARG", # "Unused function argument". Fixtures are often unused.
"S105", # "Possible hardcoded password".
]

[tool.ruff.lint.mccabe]
max-complexity = 10

[tool.ruff.lint.pep8-naming]
classmethod-decorators = [
"classmethod",
"pydantic.validator",
"pydantic.root_validator",
]

[tool.pytest.ini_options]
addopts = """\
Expand Down
38 changes: 0 additions & 38 deletions {{cookiecutter.project_slug}}/setup.cfg

This file was deleted.

0 comments on commit f84c02c

Please sign in to comment.