Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ repos:
rev: v6.0.0
hooks:
- id: trailing-whitespace
exclude: .gitignore
- id: end-of-file-fixer
- id: check-yaml
- id: check-json
Expand Down
53 changes: 2 additions & 51 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,61 +99,12 @@ exclude_lines = [
[tool.black]
exclude = ".*"

[tool.ruff]
line-length = 99
extend-exclude = [
"_version.py",
"tests/data",
]

[tool.ruff.lint]
extend-select = [
"F",
"E",
"W",
"I",
"D",
"UP",
"YTT",
"S",
"BLE",
"B",
"A",
# "CPY",
"C4",
"DTZ",
"T10",
# "EM",
"EXE",
"ISC",
"ICN",
"PT",
"Q",
]
ignore = [
"ISC001",
"D105",
"D107",
"D203",
"D213",
]

[tool.ruff.lint.flake8-quotes]
inline-quotes = "single"

[tool.ruff.lint.extend-per-file-ignores]
"setup.py" = ["D"]
"*/test_*.py" = [
"S101",
"D",
]

[tool.ruff.format]
quote-style = "single"
# Ruff configured in ruff.toml

[dependency-groups]
dev = [
"ipython>=8.37.0",
"ruff>=0.15.5",
]
test = [
"pytest >=8",
Expand Down
49 changes: 49 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
line-length = 99
extend-exclude = [
"_version.py", # Auto-generated
"tests/data", # Submodules
]

[format]
quote-style = "single"
line-ending = "lf"
docstring-code-format = true

[lint]
extend-select = [
"F", # pyflakes
"E", # pycodestyle errors
"W", # pycodestyle warnings
"I", # isort
"D", # pydocstyle
"UP", # pyupgrade
"YTT", # flake8-2020
"S", # bandit
"BLE", # blind-except
"B", # bugbear
"A", # builtins
"C4", # comprehensions
"DTZ", # datetimez
"T10", # debugger
# "EM", # errmsg
"EXE", # executable
"ISC", # implicit-str-concat
"ICN", # import-conventions
"PT", # pytest-style
"Q", # quotes
]
ignore = [
"D105", # undocumented-magic-method
"D107", # undocumented __init__
"D203", # blank line before class docstring
"D213", # multi-line-summary-first-line
"Q000", # double quotes
"Q003", # avoidable-escaped-quote
]

[lint.extend-per-file-ignores]
"setup.py" = ["D"]
"*/test_*.py" = [
"S101", # assert
"D",
]
16 changes: 8 additions & 8 deletions src/bids_validator/bids_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,16 @@ def parse(cls, path: str) -> dict[str, str]:
--------
>>> from bids_validator import BIDSValidator
>>> validator = BIDSValidator()
>>> validator.parse("/sub-01/anat/sub-01_rec-CSD_T1w.nii.gz")
>>> validator.parse('/sub-01/anat/sub-01_rec-CSD_T1w.nii.gz')
{'subject': '01', 'datatype': 'anat', 'reconstruction': 'CSD', 'suffix': 'T1w',
'extension': '.nii.gz'}
>>> validator.parse("/sub-01/anat/sub-01_acq-23_rec-CSD_T1w.exe")
>>> validator.parse('/sub-01/anat/sub-01_acq-23_rec-CSD_T1w.exe')
{}
>>> validator.parse("home/username/my_dataset/participants.tsv")
>>> validator.parse('home/username/my_dataset/participants.tsv')
Traceback (most recent call last):
...
ValueError: Path must be relative to root of a BIDS dataset, ...
>>> validator.parse("/participants.tsv")
>>> validator.parse('/participants.tsv')
{'stem': 'participants', 'extension': '.tsv'}

"""
Expand Down Expand Up @@ -196,10 +196,10 @@ def is_bids(cls, path: str) -> bool:
>>> from bids_validator import BIDSValidator
>>> validator = BIDSValidator()
>>> filepaths = [
... "/sub-01/anat/sub-01_rec-CSD_T1w.nii.gz",
... "/sub-01/anat/sub-01_acq-23_rec-CSD_T1w.exe", # wrong extension
... "home/username/my_dataset/participants.tsv", # not relative to root
... "/participants.tsv",
... '/sub-01/anat/sub-01_rec-CSD_T1w.nii.gz',
... '/sub-01/anat/sub-01_acq-23_rec-CSD_T1w.exe', # wrong extension
... 'home/username/my_dataset/participants.tsv', # not relative to root
... '/participants.tsv',
... ]
>>> for filepath in filepaths:
... print(validator.is_bids(filepath))
Expand Down
4 changes: 1 addition & 3 deletions src/bids_validator/test_bids_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,7 @@ def test_is_session_level(validator: BIDSValidator, fname: str) -> None:
'/sub-01/sub-01_acq_dwi.bval', # missed suffix value
'/sub-01/sub-01_acq-23-singleband_dwi.bvec', # redundant -23-
'/sub-01/anat/sub-01_acq-singleband_dwi.json', # redundant /anat/
(
'/sub-01/sub-01_recrod-record_acq-singleband_run-01_dwi.bval'
), # redundant record-record_
'/sub-01/sub-01_recrod-record_acq-singleband_run-01_dwi.bval', # redundant record-record_
'/sub_01/sub-01_acq-singleband_run-01_dwi.bvec', # wrong /sub_01/
'/sub-01/sub-01_acq-singleband__run-01_dwi.json', # wrong __
'/sub-01/ses-test/sub-01_ses_test_dwi.bval', # wrong ses_test
Expand Down
31 changes: 30 additions & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading