Skip to content

Commit

Permalink
New Ruff (#177)
Browse files Browse the repository at this point in the history
* chore: remove Black

* chore: update Ruff and use to format

* chore: fix new Ruff
  • Loading branch information
MicaelJarniac authored Jul 19, 2024
1 parent cb061d8 commit b12f286
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ on:

env:
FORCE_COLOR: 1
CLICOLOR_FORCE: 1 # https://github.com/astral-sh/ruff/issues/5499
PRE_COMMIT_COLOR: "always" # https://github.com/pre-commit/pre-commit/issues/2918

jobs:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.0.272'
# Ruff version.
rev: 'v0.5.0'
hooks:
# Run the linter.
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]
- repo: https://github.com/psf/black
rev: '23.3.0'
hooks:
- id: black
types_or: [ python, pyi, jupyter ]
args: [ --fix ]
# Run the formatter.
- id: ruff-format
types_or: [ python, pyi, jupyter ]
- repo: https://github.com/python-poetry/poetry
rev: '1.5.1'
hooks:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ It can be run on demand with `pre-commit run`, and optionally on all files with

### Lint

This repository uses [Ruff](https://beta.ruff.rs/docs) for linting and [black](https://black.readthedocs.io) for formatting. black formatting will be automatically verified and fixed.
This repository uses [Ruff](https://beta.ruff.rs/docs) for linting and formatting.

**Tips**:
- [Set up your editor](#set-up-your-editor) to see linting errors directly in your editor and automatically fix them on save.
Expand Down
6 changes: 2 additions & 4 deletions {{cookiecutter.project_distribution_name}}/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
| ![Build][label-build] | [![Nox][badge-actions]][actions] [![semantic-release][badge-semantic-release]][semantic-release] [![PyPI][badge-pypi]][pypi] [![Read the Docs][badge-docs]][docs] |
| ![Tests][label-tests] | [![coverage][badge-coverage]][coverage] [![pre-commit][badge-pre-commit]][pre-commit] [![asv][badge-asv]][asv] |
| ![Standards][label-standards] | [![SemVer 2.0.0][badge-semver]][semver] [![Conventional Commits][badge-conventional-commits]][conventional-commits] |
| ![Code][label-code] | [![Poetry][badge-poetry]][poetry] [![Code style: black][badge-black]][Black] [![Ruff][badge-ruff]][ruff] [![Checked with mypy][badge-mypy]][mypy] |
| ![Code][label-code] | [![Poetry][badge-poetry]][poetry] [![Ruff][badge-ruff]][ruff] [![Checked with mypy][badge-mypy]][mypy] |
| ![Repo][label-repo] | [![GitHub issues][badge-issues]][issues] [![GitHub stars][badge-stars]][stars] [![GitHub license][badge-license]][license] [![All Contributors][badge-all-contributors]][contributors] [![Contributor Covenant][badge-code-of-conduct]][code-of-conduct] |
</div>

Expand Down Expand Up @@ -56,9 +56,7 @@
<!-- Code -->
[badge-poetry]: {{cookiecutter.shields_url}}/endpoint?url=https://python-poetry.org/badge/v0.json&style=flat-square
[poetry]: https://python-poetry.org
[badge-black]: {{ cookiecutter.shields_url }}/badge/code%20style-black-black?style=flat-square
[Black]: https://github.com/psf/black
[badge-ruff]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json&style=flat-square
[badge-ruff]: {{cookiecutter.shields_url}}/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json&style=flat-square
[ruff]: https://github.com/astral-sh/ruff
[badge-mypy]: {{ cookiecutter.shields_url }}/badge/mypy-checked-2A6DB2?style=flat-square
[mypy]: http://mypy-lang.org
Expand Down
5 changes: 0 additions & 5 deletions {{cookiecutter.project_distribution_name}}/docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

- Tools
- Formatting
- [Black][black] <sup>[config][pyproject_toml]</sup>
- [Compatible configs][black_cc]
- [Ruff][ruff] <sup>[config][pyproject_toml]</sup>
- Linting
- [Ruff][ruff] <sup>[config][pyproject_toml]</sup>
Expand All @@ -13,7 +11,6 @@
<summary>Hooks</summary>

- [`ruff`][ruff]
- [`black`][black]
- [`poetry`][poetry]
- `poetry-check`
- `poetry-lock`
Expand Down Expand Up @@ -88,8 +85,6 @@
[docs_wordlist_txt]: ./wordlist.txt
[noxfile_py]: ../noxfile.py

[black]: https://github.com/psf/black
[black_cc]: https://black.readthedocs.io/en/stable/compatible_configs.html
[ruff]: https://github.com/astral-sh/ruff
[pre-commit]: https://github.com/pre-commit/pre-commit
[pre-commit-hooks]: https://github.com/pre-commit/pre-commit-hooks
Expand Down
13 changes: 9 additions & 4 deletions {{cookiecutter.project_distribution_name}}/noxfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
"""Nox file for automation."""

from typing import Iterable, Optional
from __future__ import annotations

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from collections.abc import Iterable

import nox

Expand All @@ -13,7 +18,7 @@ def install(
*,
groups: Iterable[str],
root: bool = True,
only: Optional[bool] = None,
only: bool | None = None,
extras: bool = False,
) -> None:
"""Install the dependency groups using Poetry."""
Expand Down Expand Up @@ -57,8 +62,8 @@ def lint_files(session: nox.Session) -> None:
@nox.session(python=python_versions[-1], venv_params=venv_params)
def format_files(session: nox.Session) -> None:
"""Format files."""
install(session, groups=["formatting"], root=False)
session.run("black", ".")
install(session, groups=["linting"], root=False)
session.run("ruff", "format")


@nox.session(python=python_versions, venv_params=venv_params)
Expand Down
32 changes: 11 additions & 21 deletions {{cookiecutter.project_distribution_name}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ pytest = "^7.4.0"
pytest-benchmark = "^4.0.0"

[tool.poetry.group.linting.dependencies]
ruff = "^0.0.275"

[tool.poetry.group.formatting.dependencies]
black = "^23.3.0"
ruff = "^0.5.0"

[tool.poetry.group.pre-commit.dependencies]
pre-commit = "^3.3.3"
Expand All @@ -70,36 +67,29 @@ python-semantic-release = "^8.0.2"
[tool.ruff]
# https://beta.ruff.rs/docs/rules
line-length = 88 # Default
force-exclude = true
src = ["src"]
target-version = "py38"

[tool.ruff.lint]
select = ["ALL"]
ignore = [
"D203",
"D213",
"ANN101",
"ANN102",
]
unfixable = ["ERA001"]
force-exclude = true
src = ["src"]
target-version = "py38"

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"tests/*" = ["S101"]

[tool.ruff.flake8-builtins]
[tool.ruff.lint.flake8-builtins]
builtins-ignorelist = ["id", "type"]

[tool.ruff.pydocstyle]
[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.black]
line-length = 88 # Default
include = '\.pyi?$'
extend-exclude = '''
/(
\.git
| _build
)/
'''
[tool.ruff.format]
docstring-code-format = true

[tool.mypy]
files = ["src", "docs", "tests", "noxfile.py"]
Expand Down

0 comments on commit b12f286

Please sign in to comment.