Skip to content

Commit 1963ba3

Browse files
authored
chore: Configure ruff in its own file, add precommit hooks (#72)
1 parent 878d57d commit 1963ba3

6 files changed

Lines changed: 91 additions & 63 deletions

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ repos:
66
rev: v6.0.0
77
hooks:
88
- id: trailing-whitespace
9+
exclude: .gitignore
910
- id: end-of-file-fixer
1011
- id: check-yaml
1112
- id: check-json

pyproject.toml

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -99,61 +99,12 @@ exclude_lines = [
9999
[tool.black]
100100
exclude = ".*"
101101

102-
[tool.ruff]
103-
line-length = 99
104-
extend-exclude = [
105-
"_version.py",
106-
"tests/data",
107-
]
108-
109-
[tool.ruff.lint]
110-
extend-select = [
111-
"F",
112-
"E",
113-
"W",
114-
"I",
115-
"D",
116-
"UP",
117-
"YTT",
118-
"S",
119-
"BLE",
120-
"B",
121-
"A",
122-
# "CPY",
123-
"C4",
124-
"DTZ",
125-
"T10",
126-
# "EM",
127-
"EXE",
128-
"ISC",
129-
"ICN",
130-
"PT",
131-
"Q",
132-
]
133-
ignore = [
134-
"ISC001",
135-
"D105",
136-
"D107",
137-
"D203",
138-
"D213",
139-
]
140-
141-
[tool.ruff.lint.flake8-quotes]
142-
inline-quotes = "single"
143-
144-
[tool.ruff.lint.extend-per-file-ignores]
145-
"setup.py" = ["D"]
146-
"*/test_*.py" = [
147-
"S101",
148-
"D",
149-
]
150-
151-
[tool.ruff.format]
152-
quote-style = "single"
102+
# Ruff configured in ruff.toml
153103

154104
[dependency-groups]
155105
dev = [
156106
"ipython>=8.37.0",
107+
"ruff>=0.15.5",
157108
]
158109
test = [
159110
"pytest >=8",

ruff.toml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
line-length = 99
2+
extend-exclude = [
3+
"_version.py", # Auto-generated
4+
"tests/data", # Submodules
5+
]
6+
7+
[format]
8+
quote-style = "single"
9+
line-ending = "lf"
10+
docstring-code-format = true
11+
12+
[lint]
13+
extend-select = [
14+
"F", # pyflakes
15+
"E", # pycodestyle errors
16+
"W", # pycodestyle warnings
17+
"I", # isort
18+
"D", # pydocstyle
19+
"UP", # pyupgrade
20+
"YTT", # flake8-2020
21+
"S", # bandit
22+
"BLE", # blind-except
23+
"B", # bugbear
24+
"A", # builtins
25+
"C4", # comprehensions
26+
"DTZ", # datetimez
27+
"T10", # debugger
28+
# "EM", # errmsg
29+
"EXE", # executable
30+
"ISC", # implicit-str-concat
31+
"ICN", # import-conventions
32+
"PT", # pytest-style
33+
"Q", # quotes
34+
]
35+
ignore = [
36+
"D105", # undocumented-magic-method
37+
"D107", # undocumented __init__
38+
"D203", # blank line before class docstring
39+
"D213", # multi-line-summary-first-line
40+
"Q000", # double quotes
41+
"Q003", # avoidable-escaped-quote
42+
]
43+
44+
[lint.extend-per-file-ignores]
45+
"setup.py" = ["D"]
46+
"*/test_*.py" = [
47+
"S101", # assert
48+
"D",
49+
]

src/bids_validator/bids_validator.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,16 @@ def parse(cls, path: str) -> dict[str, str]:
136136
--------
137137
>>> from bids_validator import BIDSValidator
138138
>>> validator = BIDSValidator()
139-
>>> validator.parse("/sub-01/anat/sub-01_rec-CSD_T1w.nii.gz")
139+
>>> validator.parse('/sub-01/anat/sub-01_rec-CSD_T1w.nii.gz')
140140
{'subject': '01', 'datatype': 'anat', 'reconstruction': 'CSD', 'suffix': 'T1w',
141141
'extension': '.nii.gz'}
142-
>>> validator.parse("/sub-01/anat/sub-01_acq-23_rec-CSD_T1w.exe")
142+
>>> validator.parse('/sub-01/anat/sub-01_acq-23_rec-CSD_T1w.exe')
143143
{}
144-
>>> validator.parse("home/username/my_dataset/participants.tsv")
144+
>>> validator.parse('home/username/my_dataset/participants.tsv')
145145
Traceback (most recent call last):
146146
...
147147
ValueError: Path must be relative to root of a BIDS dataset, ...
148-
>>> validator.parse("/participants.tsv")
148+
>>> validator.parse('/participants.tsv')
149149
{'stem': 'participants', 'extension': '.tsv'}
150150
151151
"""
@@ -196,10 +196,10 @@ def is_bids(cls, path: str) -> bool:
196196
>>> from bids_validator import BIDSValidator
197197
>>> validator = BIDSValidator()
198198
>>> filepaths = [
199-
... "/sub-01/anat/sub-01_rec-CSD_T1w.nii.gz",
200-
... "/sub-01/anat/sub-01_acq-23_rec-CSD_T1w.exe", # wrong extension
201-
... "home/username/my_dataset/participants.tsv", # not relative to root
202-
... "/participants.tsv",
199+
... '/sub-01/anat/sub-01_rec-CSD_T1w.nii.gz',
200+
... '/sub-01/anat/sub-01_acq-23_rec-CSD_T1w.exe', # wrong extension
201+
... 'home/username/my_dataset/participants.tsv', # not relative to root
202+
... '/participants.tsv',
203203
... ]
204204
>>> for filepath in filepaths:
205205
... print(validator.is_bids(filepath))

src/bids_validator/test_bids_validator.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,7 @@ def test_is_session_level(validator: BIDSValidator, fname: str) -> None:
204204
'/sub-01/sub-01_acq_dwi.bval', # missed suffix value
205205
'/sub-01/sub-01_acq-23-singleband_dwi.bvec', # redundant -23-
206206
'/sub-01/anat/sub-01_acq-singleband_dwi.json', # redundant /anat/
207-
(
208-
'/sub-01/sub-01_recrod-record_acq-singleband_run-01_dwi.bval'
209-
), # redundant record-record_
207+
'/sub-01/sub-01_recrod-record_acq-singleband_run-01_dwi.bval', # redundant record-record_
210208
'/sub_01/sub-01_acq-singleband_run-01_dwi.bvec', # wrong /sub_01/
211209
'/sub-01/sub-01_acq-singleband__run-01_dwi.json', # wrong __
212210
'/sub-01/ses-test/sub-01_ses_test_dwi.bval', # wrong ses_test

uv.lock

Lines changed: 30 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)