Skip to content

Commit

Permalink
✨ adopt ruff formatter (#464)
Browse files Browse the repository at this point in the history
## Description

This PR adopts ruff's new formatter as a drop-in replacement for black.
See https://astral.sh/blog/the-ruff-formatter for a nice introduction.
It's faster, allows us to drop a dependency and reduces configuration.

## Checklist:

<!---
This checklist serves as a reminder of a couple of things that ensure
your pull request will be merged swiftly.
-->

- [x] The pull request only contains commits that are related to it.
- [x] I have added appropriate tests and documentation.
- [x] I have made sure that all CI jobs on GitHub pass.
- [x] The pull request introduces no new warnings and follows the
project's style guidelines.
  • Loading branch information
burgholzer authored Oct 27, 2023
1 parent be7c5ec commit 295698a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
11 changes: 3 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ repos:

# Python linting using ruff
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.1
rev: v0.1.3
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
- id: ruff-format

# Static type checking using mypy
- repo: https://github.com/pre-commit/mirrors-mypy
Expand All @@ -68,18 +69,12 @@ repos:
additional_dependencies:
- pytest

# Run code formatting with Black
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.10.0 # Keep in sync with blacken-docs
hooks:
- id: black-jupyter

# Also run Black on examples in the documentation
- repo: https://github.com/adamchainz/blacken-docs
rev: 1.16.0
hooks:
- id: blacken-docs
additional_dependencies: [black==23.10.0] # Keep in sync with blacken-docs
additional_dependencies: [black==23.*]

# Clang-format the C++ part of the code base automatically
- repo: https://github.com/pre-commit/mirrors-clang-format
Expand Down
20 changes: 9 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,6 @@ ENABLE_IPO = "ON"
write_to = "src/mqt/core/_version.py"


[tool.black]
line-length = 120


[tool.pytest.ini_options]
minversion = "7.0"
addopts = ["-ra", "--strict-markers", "--strict-config"]
Expand Down Expand Up @@ -168,8 +164,12 @@ module = ["qiskit.*", "matplotlib.*"]
ignore_missing_imports = true

[tool.ruff]
include = ["*.py", "*.pyi", "**/pyproject.toml", "*.ipynb"]
select = [
line-length = 120
extend-include = ["*.ipynb"]
src = ["src"]

[tool.ruff.lint]
extend-select = [
"E", "F", "W", # flake8
"A", # flake8-builtins
"ANN", # flake8-annotations
Expand Down Expand Up @@ -207,17 +207,15 @@ select = [
"UP", # pyupgrade
"YTT", # flake8-2020
]
extend-ignore = [
ignore = [
"E501", # Line too long (Black is enough)
"PLR", # Design related pylint codes
]
typing-modules = ["mqt.core._compat.typing"]
src = ["src"]
flake8-unused-arguments.ignore-variadic-names = true
isort.required-imports = ["from __future__ import annotations"]
line-length = 120

[tool.ruff.flake8-tidy-imports.banned-api]
[tool.ruff.lint.flake8-tidy-imports.banned-api]
"typing.Callable".msg = "Use collections.abc.Callable instead."
"typing.Iterator".msg = "Use collections.abc.Iterator instead."
"typing.Mapping".msg = "Use collections.abc.Mapping instead."
Expand All @@ -229,7 +227,7 @@ line-length = 120
"importlib.resources".msg = "Use scikit_build_core._compat.importlib.resources instead."
"importlib_resources".msg = "Use scikit_build_core._compat.importlib.resources instead."

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"*.pyi" = ["D"] # pydocstyle
"*.ipynb" = [
"D", # pydocstyle
Expand Down

0 comments on commit 295698a

Please sign in to comment.