Skip to content

Commit

Permalink
Replace black with ruff format (#101)
Browse files Browse the repository at this point in the history
* use ruff as formatter
* remove black config
  • Loading branch information
fpgmaas committed Dec 14, 2023
1 parent 73e88fc commit 6c546b5
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 32 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ This is a modern Cookiecutter template that can be used to initiate a Python pro
- CI/CD with [GitHub Actions](https://github.com/features/actions)
- Pre-commit hooks with [pre-commit](https://pre-commit.com/)
- Code quality with:
- [black](https://pypi.org/project/black/)
- [ruff](https://github.com/charliermarsh/ruff)
- [mypy](https://mypy.readthedocs.io/en/stable/)
- [deptry](https://github.com/fpgmaas/deptry/)
Expand Down
17 changes: 1 addition & 16 deletions docs/features/linting.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,9 @@ Note that this requires the pre-commit hooks to be installed.

This command will run the following tools:

## black

[black](https://pypi.org/project/black/) is used to format the code, and it is configured through `pyproject.toml`:

```toml
[tool.black]
line-length = 120
include = '\.pyi?$'
target-version = ['py39']
fast = true
```

To exclude directories or files, add an `exclude` argument to `pre-commit-config.yaml`. Note that adding an `exclude` argument to `pyproject.toml`
will not work, see also [here](https://stackoverflow.com/a/61046953/8037249).

## ruff

[ruff](https://github.com/charliermarsh/ruff) is used to check the code style, and it is configured through `pyproject.toml`:
[ruff](https://github.com/charliermarsh/ruff) is used to lint and format the code, and it is configured through `pyproject.toml`:

```
[tool.ruff]
Expand Down
2 changes: 1 addition & 1 deletion docs/features/makefile.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ available:

```
install Install the poetry environment and install the pre-commit hooks
check Lint and check code by running black, ruff, mypy and deptry.
check Lint and check code by running ruff, mypy and deptry.
test Test the code with pytest
build Build wheel file using poetry
clean-build clean build artifacts
Expand Down
7 changes: 5 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ This is a modern Cookiecutter template that can be used to initiate a Python pro
- [Poetry](https://python-poetry.org/) for dependency management
- CI/CD with [GitHub Actions](https://github.com/features/actions)
- Pre-commit hooks with [pre-commit](https://pre-commit.com/)
- Code quality with [black](https://pypi.org/project/black/), [ruff](https://github.com/charliermarsh/ruff), [mypy](https://mypy.readthedocs.io/en/stable/), and [deptry](https://github.com/fpgmaas/deptry/)
- Code quality with:
- [ruff](https://github.com/charliermarsh/ruff)
- [mypy](https://mypy.readthedocs.io/en/stable/)
- [deptry](https://github.com/fpgmaas/deptry/)
- [prettier](https://prettier.io/)
- Publishing to [Pypi](https://pypi.org) or [Artifactory](https://jfrog.com/artifactory) by creating a new release on GitHub
- Testing and coverage with [pytest](https://docs.pytest.org/en/7.1.x/) and [codecov](https://about.codecov.io/)
- Documentation with [MkDocs](https://www.mkdocs.org/)
- Compatibility testing for multiple versions of Python with [Tox](https://tox.wiki/en/latest/)
- Containerization with [Docker](https://www.docker.com/)
- Development environment with [VSCode devcontainers](https://code.visualstudio.com/docs/remote/containers)

An example of a repository generated with this package can be found [here](https://github.com/fpgmaas/cookiecutter-poetry-example).

Expand Down
11 changes: 4 additions & 7 deletions {{cookiecutter.project_name}}/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.230"
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.1.6"
hooks:
- id: ruff

- repo: https://github.com/psf/black
rev: "22.8.0"
hooks:
- id: black
args: [--exit-non-zero-on-fix]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.0.3"
Expand Down
8 changes: 3 additions & 5 deletions {{cookiecutter.project_name}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ mkdocstrings = {extras = ["python"], version = "^0.23.0"}
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.black]
line-length = 120
target-version = ['py37']
preview = true

[tool.mypy]
files = ["{{cookiecutter.project_slug}}"]
disallow_untyped_defs = "True"
Expand Down Expand Up @@ -97,6 +92,9 @@ ignore = [
"E731",
]

[tool.ruff.format]
preview = true

{% if cookiecutter.codecov == "y"-%}
[tool.coverage.report]
skip_empty = true
Expand Down

0 comments on commit 6c546b5

Please sign in to comment.