Skip to content

Commit adbddce

Browse files
authored
Merge pull request #168 from scipp/switch-to-ruff
Switch to ruff for formatting and static analysis (for real)
2 parents f895f63 + 76b7c84 commit adbddce

File tree

7 files changed

+48
-40
lines changed

7 files changed

+48
-40
lines changed

template/.pre-commit-config.yaml

+8-21
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,21 @@ repos:
1313
- id: trailing-whitespace
1414
args: [ --markdown-linebreak-ext=md ]
1515
exclude: '\.svg'
16-
- repo: https://github.com/pycqa/isort
17-
rev: 5.12.0
18-
hooks:
19-
- id: isort
20-
name: isort (python)
21-
- repo: https://github.com/psf/black-pre-commit-mirror
22-
rev: 23.11.0
23-
hooks:
24-
- id: black
2516
- repo: https://github.com/kynan/nbstripout
2617
rev: 0.6.0
2718
hooks:
2819
- id: nbstripout
2920
types: [ "jupyter" ]
3021
args: [ "--drop-empty-cells",
3122
"--extra-keys 'metadata.language_info.version cell.metadata.jp-MarkdownHeadingCollapsed cell.metadata.pycharm'" ]
32-
- repo: https://github.com/pycqa/flake8
33-
rev: 6.1.0
34-
hooks:
35-
- id: flake8
36-
types: ["python"]
37-
additional_dependencies: ["flake8-bugbear==23.9.16"]
38-
- repo: https://github.com/pycqa/bandit
39-
rev: 1.7.5
40-
hooks:
41-
- id: bandit
42-
additional_dependencies: ["bandit[toml]"]
43-
args: ["-c", "pyproject.toml"]
23+
- repo: https://github.com/astral-sh/ruff-pre-commit
24+
rev: v0.4.1
25+
hooks:
26+
- id: ruff
27+
args: [ --fix ]
28+
types_or: [ python, pyi, jupyter ]
29+
- id: ruff-format
30+
types_or: [ python, pyi ]
4431
- repo: https://github.com/codespell-project/codespell
4532
rev: v2.2.6
4633
hooks:

template/docs/conf.py.jinja

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ from importlib.metadata import version as get_version
88
sys.path.insert(0, os.path.abspath('.'))
99

1010
# General information about the project.
11-
project = u'{{prettyname}}'
12-
copyright = u'{{year}} Scipp contributors'
13-
author = u'Scipp contributors'
11+
project = '{{prettyname}}'
12+
copyright = '{{year}} Scipp contributors'
13+
author = 'Scipp contributors'
1414

1515
html_show_sourcelink = True
1616

@@ -32,6 +32,7 @@ extensions = [
3232
{% if orgname == 'scipp' %}
3333
try:
3434
import sciline.sphinxext.domain_types # noqa: F401
35+
3536
extensions.append('sciline.sphinxext.domain_types')
3637
except ModuleNotFoundError:
3738
pass

template/docs/developer/coding-conventions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Code formatting
44

5-
There are no explicit code formatting conventions since we use `black` to enforce a format.
5+
There are no explicit code formatting conventions since we use `ruff` to enforce a format.
66

77
## Docstring format
88

template/pyproject.toml.jinja

+33-9
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,41 @@ filterwarnings = [
5555
"error",
5656
]
5757

58-
[tool.bandit]
59-
# Excluding tests because bandit doesn't like `assert`.
60-
exclude_dirs = ["docs/conf.py", "tests"]
58+
[tool.ruff]
59+
line-length = 88
60+
extend-include = ["*.ipynb"]
61+
extend-exclude = [
62+
".*", "__pycache__", "build", "dist", "install",
63+
]
64+
65+
[tool.ruff.lint]
66+
# See https://docs.astral.sh/ruff/rules/
67+
select = ["B", "C4", "DTZ", "E", "F", "G", "I", "PERF", "PGH", "PT", "PYI", "RUF", "S", "T20", "W"]
68+
ignore = [
69+
# Conflict with ruff format, see
70+
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
71+
"COM812", "COM819", "D206", "D300", "E111", "E114", "E117", "ISC001", "ISC002", "Q000", "Q001", "Q002", "Q003", "W191",
72+
]
73+
fixable = ["I001", "B010"]
74+
isort.known-first-party = ["{{projectname}}"]
75+
pydocstyle.convention = "numpy"
6176

62-
[tool.black]
63-
skip-string-normalization = true
77+
[tool.ruff.lint.per-file-ignores]
78+
# those files have an increased risk of relying on import order
79+
"__init__.py" = ["I"]
80+
"tests/*" = [
81+
"S101", # asserts are fine in tests
82+
"B018", # 'useless expressions' are ok because some tests just check for exceptions
83+
]
84+
"*.ipynb" = [
85+
"E501", # longer lines are sometimes more readable
86+
"I", # we don't collect imports at the top
87+
"S101", # asserts are used for demonstration and are safe in notebooks
88+
"T201", # printing is ok for demonstration purposes
89+
]
6490

65-
[tool.isort]
66-
skip_gitignore = true
67-
profile = "black"
68-
known_first_party = ["{{projectname}}"]
91+
[tool.ruff.format]
92+
quote-style = "preserve"
6993

7094
[tool.mypy]
7195
strict = true

template/setup.cfg.jinja

-4
This file was deleted.

template/src/{% if namespace_package %}{{namespace_package}}{% endif %}/{{ projectname.removeprefix(namespace_package) }}/__init__.py.jinja

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22
# Copyright (c) {{year}} {{orgname|capitalize}} contributors (https://github.com/{{orgname}})
3+
# ruff: noqa: E402, F401
34

4-
# flake8: noqa
55
import importlib.metadata
66

77
try:

template/src/{% if not namespace_package %}{{projectname}}{% endif %}/__init__.py.jinja

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22
# Copyright (c) {{year}} {{orgname|capitalize}} contributors (https://github.com/{{orgname}})
3+
# ruff: noqa: E402, F401
34

4-
# flake8: noqa
55
import importlib.metadata
66

77
try:

0 commit comments

Comments
 (0)