Skip to content

Commit df9c400

Browse files
authored
Merge pull request #2114 from effigies/sty/ruff
chore(schemacode): Switch from black/isort/flake8 to ruff
2 parents ff60d64 + ea70321 commit df9c400

25 files changed

+179
-226
lines changed

.github/workflows/validation.yml

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -37,62 +37,33 @@ jobs:
3737
runs-on: ubuntu-latest
3838
steps:
3939
- uses: actions/checkout@v4
40-
- uses: actions/setup-python@v5
41-
with:
42-
python-version: 3
43-
- name: Install dependencies
44-
run: pip install yamllint
40+
- uses: actions/setup-uv@v6
4541
- name: Lint yml files in src/schema
46-
run: yamllint -f standard src/schema/ -c .yamllint.yml
42+
run: uvx yamllint -f standard src/schema/ -c .yamllint.yml
4743

4844
# Python best practices
4945
python-style:
5046
runs-on: ubuntu-latest
5147
steps:
5248
- uses: actions/checkout@v4
53-
- uses: actions/setup-python@v5
54-
with:
55-
python-version: 3
56-
- run: python -m pip install --upgrade flake8 black isort[colors]
57-
- run: black --diff --color --check tools/schemacode
58-
- run: isort --diff --color --check tools/schemacode
59-
- run: flake8
60-
working-directory: tools/schemacode
49+
- uses: actions/setup-uv@v6
50+
- run: uvx ruff format --diff
51+
- run: uvx ruff check
6152

6253
# Avoid Latin phrases to improve readability
6354
latin-phrases:
6455
runs-on: ubuntu-latest
6556
steps:
6657
- uses: actions/checkout@v4
67-
- uses: actions/setup-python@v5
68-
with:
69-
python-version: 3
70-
- name: Install dependencies
71-
run: |
72-
python -m pip install --upgrade pip
73-
python -m pip install -r tools/requirements.txt
74-
- name: Run Python script to check for Latin phrases - Master
75-
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
76-
run: |
77-
python no-bad-latin.py
78-
working-directory: tools
79-
- name: Run Python script to check for Latin phrases - Pull Request
80-
if: github.event.pull_request
81-
run: |
82-
python no-bad-latin.py
83-
working-directory: tools
58+
- uses: actions/setup-uv@v6
59+
- name: Check for Latin phrases
60+
run: uv run tools/no-bad-latin.py
8461

8562
# Validate CITATION.cff
8663
validate_cff:
8764
runs-on: ubuntu-latest
8865
steps:
89-
- uses: actions/checkout@v4
90-
- uses: actions/setup-python@v5
91-
with:
92-
python-version: 3
93-
- name: Install dependencies
94-
run: |
95-
python -m pip install --upgrade pip setuptools
96-
pip3 install cffconvert
97-
- name: Validate CITATION.cff
98-
run: make validate_citation_cff
66+
- uses: actions/checkout@v4
67+
- uses: actions/setup-uv@v6
68+
- name: Validate CITATION.cff
69+
run: uvx cffconvert --validate

.pre-commit-config.yaml

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ci:
55
exclude: 'tools/schemacode/src/bidsschematools/tests/data/broken_dataset_description.json'
66
repos:
77
- repo: https://github.com/pre-commit/pre-commit-hooks
8-
rev: v4.6.0
8+
rev: v5.0.0
99
hooks:
1010
- id: trailing-whitespace
1111
- id: end-of-file-fixer
@@ -15,7 +15,7 @@ repos:
1515
- id: check-added-large-files
1616
- id: check-case-conflict
1717
- repo: https://github.com/python-jsonschema/check-jsonschema
18-
rev: 0.29.2
18+
rev: 0.33.0
1919
hooks:
2020
- id: check-dependabot
2121
- id: check-github-workflows
@@ -24,50 +24,33 @@ repos:
2424
files: src/metaschema.json
2525
- id: check-readthedocs
2626
files: readthedocs.yml
27-
- repo: https://github.com/psf/black
28-
rev: 24.8.0
27+
- repo: https://github.com/astral-sh/ruff-pre-commit
28+
rev: v0.11.9
2929
hooks:
30-
- id: black
31-
files: ^tools/(?!schemacode)
32-
args: ["--verbose"]
33-
- id: black
34-
name: "black bidsschematools"
35-
files: tools/schemacode
36-
args: ["--config", "tools/schemacode/pyproject.toml", "--verbose"]
37-
- repo: https://github.com/pyCQA/isort
38-
rev: 5.13.2
39-
hooks:
40-
- id: isort
41-
files: ^tools/(?!schemacode)
42-
args: ["--profile", "black"]
43-
- id: isort
44-
name: "isort bidsschematools"
45-
files: tools/schemacode
46-
args: ["--settings-file", "tools/schemacode/pyproject.toml"]
47-
- repo: https://github.com/pyCQA/flake8
48-
rev: 7.1.1
49-
hooks:
50-
- id: flake8
51-
args: [--config=tools/schemacode/setup.cfg]
30+
- id: ruff
31+
args: [--fix]
32+
- id: ruff-format
33+
- id: ruff
34+
args: [--select, ISC001, --fix]
5235
- repo: https://github.com/pre-commit/mirrors-prettier
5336
rev: v4.0.0-alpha.8
5437
hooks:
5538
- id: prettier
5639
entry: env PRETTIER_LEGACY_CLI=1 prettier # temporary fix for https://github.com/prettier/prettier/issues/15742
5740
files: src/schema/.*/.*\.yaml
5841
- repo: https://github.com/adrienverge/yamllint
59-
rev: v1.35.1
42+
rev: v1.37.1
6043
hooks:
6144
- id: yamllint
6245
args: [-f=standard, -c=.yamllint.yml]
6346
files: src/schema/.*/.*\.yaml
6447
- repo: https://github.com/codespell-project/codespell
65-
rev: v2.3.0
48+
rev: v2.4.1
6649
hooks:
6750
- id: codespell
6851
args: ["--config=.codespellrc", "--dictionary=-", "--dictionary=.codespell_dict"]
6952
- repo: https://github.com/pre-commit/mirrors-mypy
70-
rev: v1.11.2
53+
rev: v1.15.0
7154
hooks:
7255
- id: mypy
7356
# Sync with project.optional-dependencies.typing

pdf_build_src/check_pandoc_log.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# go through the logs (list of dicts)
1414
duplicate_link_refs = []
1515
for log_dict in logs:
16-
1716
# Check for DuplicateLinkReference
1817
logtype = log_dict.get("type", None)
1918
logverbosity = log_dict.get("verbosity", None)

pdf_build_src/pandoc_script.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def _flatten_values(lst):
6666
# appendices/ as a resource-path so that the relative files can
6767
# be found.
6868
build_root = HERE.parent
69-
cmd += [f'--resource-path=.:{build_root / "appendices"}']
69+
cmd += [f"--resource-path=.:{build_root / 'appendices'}"]
7070

7171
# Add input files to command
7272
# The filenames in `markdown_list` will ensure correct order when sorted

pdf_build_src/process_markdowns.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ def remove_internal_links_reference(root_path):
158158
# first find, which links need to be remove by scanning the
159159
# references, and remove the reference
160160
for ind, line in enumerate(data):
161-
162161
match = pattern_ref.search(line)
163162

164163
if match:
@@ -175,7 +174,6 @@ def remove_internal_links_reference(root_path):
175174
# link
176175
pattern = re.compile(r"\[([^\]]+)\]\[" + f"{link}" + r"\]")
177176
for ind, line in enumerate(data):
178-
179177
match = pattern.search(line)
180178

181179
if match:
@@ -256,7 +254,6 @@ def assert_no_multiline_links(root_path):
256254
code_context = False
257255
macro_context = False
258256
for ind, line in enumerate(data):
259-
260257
# do not check "code blocks" or "macros"
261258
if line.strip().startswith("```"):
262259
code_context = not code_context
@@ -277,8 +274,7 @@ def assert_no_multiline_links(root_path):
277274

278275
if len(problems) > 0:
279276
msg = (
280-
"Found multiline markdown links! Please reformat as single"
281-
" line links.\n\n"
277+
"Found multiline markdown links! Please reformat as single line links.\n\n"
282278
)
283279
msg += json.dumps(problems, indent=4)
284280
raise AssertionError(msg)
@@ -378,7 +374,6 @@ def correct_table(table, offset=[0.0, 0.0], debug=False):
378374
# correct alignment of fences and populate the new table (A List of str)
379375
new_table = []
380376
for i, row in enumerate(table):
381-
382377
if i == 1:
383378
str_format = " {:-{align}{width}} "
384379
else:
@@ -678,7 +673,6 @@ def process_macros(duplicated_src_dir_path):
678673

679674

680675
if __name__ == "__main__":
681-
682676
duplicated_src_dir_path = "src_copy/src"
683677

684678
# make a copy of the src directory in the current directory

pdf_build_src/remove_admonitions.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@
1616
def remove_admonitions(
1717
input_folder: str | Path, output_folder: str | Path, indent: str = None
1818
):
19-
2019
if indent is None:
2120
indent = INDENT
2221

2322
md_files = Path(input_folder).glob("**/*.md")
2423

2524
for file in md_files:
26-
2725
with open(file, "r", encoding="utf8") as f:
2826
content = f.readlines()
2927

@@ -32,11 +30,9 @@ def remove_admonitions(
3230
print(f"processing: {file}\n to: {output_file}")
3331

3432
with open(output_file, "w", encoding="utf8") as f:
35-
3633
is_admonition = False
3734
counter = 0
3835
for line in content:
39-
4036
if any(line.startswith(x) for x in ADMONITION_DELIMITERS):
4137
is_admonition = True
4238
counter = 0

pdf_build_src/test_remove_admonitions.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ def test_remove_admonitions(tmp_path):
1212
generated_files = list(tmp_path.glob("**/*.md"))
1313

1414
for file in generated_files:
15-
1615
expected = expected_folder / file.relative_to(tmp_path)
1716

1817
with open(expected, "r", encoding="utf8") as f:

src/schema/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ arrays or objects:
439439
| `properties` | The object described has a given set of fields; the values of these fields may be constrained |
440440
| `additionalProperties` | The object described has constraints on its values, but not the names |
441441

442-
### On re-used objects with different definitions
442+
### On reused objects with different definitions
443443

444444
In a few cases, two objects with the same name appear multiple times in the specification.
445445
When this happens, it is preferred to find a common definition, and clarify it in the rules (see below).

src/schema/objects/metadata.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ ContinuousHeadLocalization:
523523
name: ContinuousHeadLocalization
524524
display_name: Continuous Head Localization
525525
description: |
526-
`true` or `false` value indicating whether continuous head localisation
526+
`true` or `false` value indicating whether continuous head localization
527527
was performed.
528528
type: boolean
529529
ContrastBolusIngredient:
@@ -1469,7 +1469,7 @@ HeadCoilFrequency:
14691469
name: HeadCoilFrequency
14701470
display_name: Head Coil Frequency
14711471
description: |
1472-
List of frequencies (in Hz) used by the head localisation coils
1472+
List of frequencies (in Hz) used by the head localization coils
14731473
('HLC' in CTF systems, 'HPI' in Neuromag/Elekta/MEGIN, 'COH' in BTi/4D)
14741474
that track the subject's head position in the MEG helmet
14751475
(for example, `[293, 307, 314, 321]`).
@@ -2130,7 +2130,7 @@ MaxMovement:
21302130
display_name: Max Movement
21312131
description: |
21322132
Maximum head movement (in mm) detected during the recording,
2133-
as measured by the head localisation coils (for example, `4.8`).
2133+
as measured by the head localization coils (for example, `4.8`).
21342134
type: number
21352135
unit: mm
21362136
MeasurementToolMetadata:

0 commit comments

Comments
 (0)