Skip to content

Commit 7c3439a

Browse files
authored
Cleanup (#55)
Code cleanup: Harmonized imports across the package, replaced NamedTuple and SimpleNamespace usage, and enforced consistent naming conventions. Refactored utilities: Renamed utils.py to fileops.py to better reflect its scope; extracted NIfTI helpers into a dedicated nifti.py module. Improved project config: Expanded Ruff lint rules, added norecursedirs for test data. Docstring improvements: Added and expanded docstrings throughout core modules.
1 parent a277c68 commit 7c3439a

40 files changed

Lines changed: 749 additions & 753 deletions

.github/workflows/test.yaml

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ on:
1111
pull_request:
1212
workflow_dispatch:
1313
inputs:
14-
slow:
15-
description: Run slow tests
16-
required: false
17-
default: false
18-
type: boolean
1914
e2e:
2015
description: Run end-to-end tests
2116
required: false
@@ -58,18 +53,6 @@ jobs:
5853
--log-level=DEBUG \
5954
--verbose
6055
61-
- name: Run slow tests
62-
if: matrix.os == 'ubuntu-latest' && github.event_name == 'workflow_dispatch' && inputs.slow == true
63-
shell: bash
64-
run: >
65-
uv run pytest \
66-
-m "slow" \
67-
--runner=docker \
68-
--junitxml=pytest-slow.xml \
69-
--cov=src tests \
70-
--cov-append \
71-
--verbose
72-
7356
- name: Run full pipeline tests
7457
if: matrix.os == 'ubuntu-latest' && github.event_name == 'workflow_dispatch' && inputs.e2e == true
7558
shell: bash
@@ -102,6 +85,17 @@ jobs:
10285
pytest-xml-coverage-path: ./coverage.xml
10386
junitxml-path: ./pytest.xml
10487

88+
codegen:
89+
runs-on: ubuntu-latest
90+
steps:
91+
- uses: actions/checkout@v6
92+
- name: Setup venv
93+
uses: ./.github/actions/setup-venv
94+
- name: Check generated files are up-to-date
95+
run: |
96+
uv run scripts/generate_bids_tools.py
97+
git diff --exit-code || (echo "Generated files are out of date. Run: uv run scripts/generate_bids_tools.py" && exit 1)
98+
10599
ruff:
106100
runs-on: ubuntu-latest
107101
steps:

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,6 @@ cython_debug/
164164
# and can be added to the global gitignore or merged into this file. For a more nuclear
165165
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
166166
.idea/
167+
168+
.claude
169+
/nul

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ The pipeline requires the following neuroimaging tools:
4343
from rbc.workflows import anatomical, functional
4444

4545
# Anatomical preprocessing
46-
anatomical.single_session(
46+
anatomical.single_session_preprocess(
4747
in_t1w="sub-01_T1w.nii.gz",
4848
output_dir="derivatives/rbc"
4949
)
5050

5151
# Functional preprocessing (in development)
52-
functional.single_session(
52+
functional.single_session_preprocess(
5353
in_bold="sub-01_task-rest_bold.nii.gz",
5454
in_t1w="sub-01_T1w.nii.gz",
5555
output_dir="derivatives/rbc"

pyproject.toml

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ license = "MIT"
77
readme = "README.md"
88
requires-python = ">=3.12"
99
dependencies = [
10-
"bids2table>=2.1.2",
1110
"nibabel>=5.3.3",
12-
"niwrap>=0.8.3",
13-
"niwrap-helper>=0.7.0",
11+
"niwrap>=0.8.3"
1412
]
1513

1614
[dependency-groups]
@@ -27,11 +25,14 @@ docs = ["pdoc>=15.0.0"]
2725
[tool.pytest.ini_options]
2826
pythonpath = ["src"]
2927
testpaths = ["tests"]
28+
norecursedirs = [
29+
"tests/data"
30+
]
3031
markers = [
3132
"unit: Fast (<1s) unit tests (e.g. utilities, BIDS parsing, file operations)",
32-
"integration: Medium (1-5 min) integration tests with small/downsampled data",
33-
"slow: Long (30+ min) tests; skip on CI",
34-
"full_pipeline: End-to-end workflow tests; skip on CI"
33+
"integration: Integration tests with real data",
34+
"slow: Long-running tests (manual marker on individual tests)",
35+
"full_pipeline: End-to-end workflow tests"
3536
]
3637

3738
[tool.coverage.report]
@@ -50,39 +51,45 @@ extend-exclude = ["src/rbc/core/bids.py", "tests/unit/test_bids.py"]
5051

5152
[tool.ruff.lint]
5253
select = [
53-
"ANN", # flake8-annotations
54-
"ARG", # flake8-unused-arguments
55-
"B", # flake8-bugbear
56-
"C4", # flake8-comprehensions
57-
"C90", # mccabe
58-
"D", # pydocstyle
59-
"E", # pycodestyle errors
60-
"ERA", # eradicate
61-
"F", # Pyflakes
62-
"FA", # flake8-future-annotations
63-
"FBT", # flake8-boolean-trap
64-
"FURB", # refurb
65-
"I", # isort
66-
"N", # pep8-naming
67-
"NPY", # NumPy-specific rules
68-
"PD", # pandas-vet
69-
"PERF", # Perflint
70-
"PIE", # flake8-pie
71-
"PT", # flake8-pytest-style
72-
"PTH", # flake8-use-pathlib
73-
"Q", # flake8-quotes
74-
"RET", # flake8-return
75-
"RUF", # Ruff-specific rules
76-
"S", # flake8-bandit
77-
"SIM", # flake8-simplify
78-
"T20", # flake8-print
79-
"TCH", # flake8-type-checking
80-
"UP", # pyupgrade
54+
"ANN", # flake8-annotations
55+
"ARG", # flake8-unused-arguments
56+
"B", # flake8-bugbear
57+
"C4", # flake8-comprehensions
58+
"C90", # mccabe
59+
"D", # pydocstyle
60+
"E", # pycodestyle errors
61+
"ERA", # eradicate
62+
"F", # Pyflakes
63+
"FA", # flake8-future-annotations
64+
"FBT", # flake8-boolean-trap
65+
"FURB", # refurb
66+
"I", # isort
67+
"N", # pep8-naming
68+
"NPY", # NumPy-specific rules
69+
"PD", # pandas-vet
70+
"PERF", # Perflint
71+
"PIE", # flake8-pie
72+
"PT", # flake8-pytest-style
73+
"PTH", # flake8-use-pathlib
74+
"Q", # flake8-quotes
75+
"RET", # flake8-return
76+
"RUF", # Ruff-specific rules
77+
"S", # flake8-bandit
78+
"SIM", # flake8-simplify
79+
"T20", # flake8-print
80+
"TID", # flake8-tidy-imports
81+
"TCH", # flake8-type-checking
82+
"UP" # pyupgrade
8183
]
8284
ignore = []
8385
fixable = ["ALL"]
8486
unfixable = []
8587

88+
[tool.ruff.lint.flake8-tidy-imports.banned-api]
89+
"bids2table.format_bids_path".msg = "Prefer rbc.core.bids.bids_path / rbc.core.bids.bids_name"
90+
"bids2table.parse_bids_entities".msg = "Prefer rbc.core.bids.parse_bids_name"
91+
"types.SimpleNamespace".msg = "Prefer NamedTuple"
92+
8693
[tool.ruff.lint.pydocstyle]
8794
convention = "google"
8895

scripts/generate_bids_tools.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,6 @@ def w(s: str = "") -> None:
419419
w()
420420

421421
# ---- TestBidsName ----
422-
w("@pytest.mark.unit")
423422
w("class TestBidsName:")
424423
w(' """Tests for bids_name."""')
425424
w()
@@ -593,7 +592,6 @@ def w(s: str = "") -> None:
593592
w()
594593

595594
# ---- TestBidsPath ----
596-
w("@pytest.mark.unit")
597595
w("class TestBidsPath:")
598596
w(' """Tests for bids_path."""')
599597
w()
@@ -641,7 +639,6 @@ def w(s: str = "") -> None:
641639
w()
642640

643641
# ---- TestParseBidsName ----
644-
w("@pytest.mark.unit")
645642
w("class TestParseBidsName:")
646643
w(' """Tests for parse_bids_name."""')
647644
w()
@@ -724,7 +721,6 @@ def w(s: str = "") -> None:
724721
w()
725722

726723
# ---- TestConstants ----
727-
w("@pytest.mark.unit")
728724
w("class TestConstants:")
729725
w(' """Tests for namespace constant classes."""')
730726
w()

src/rbc/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
""".. include:: ../../README.md""" # noqa: D415
2+
3+
from __future__ import annotations

src/rbc/cli/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
"""Command line interface.
1+
"""Command-line interface for the RBC pipeline.
22
3-
This module handles CLI entry points for the RBC pipeline.
4-
5-
Parses arguments, validates BIDS inputs, and dispatches to workflow modules.
6-
Subcommands are defined in rbc.cli.* modules.
3+
Entry point that parses arguments, validates BIDS inputs, and dispatches to
4+
the appropriate workflow. Each subcommand (``anatomical``, ``functional``,
5+
``derivatives``, ``longitudinal``, ``qc``) is defined in its own submodule
6+
under ``rbc.cli``.
77
"""
8+
9+
from __future__ import annotations

src/rbc/cli/anatomical.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"""Anatomical preprocessing CLI.
1+
"""CLI subcommand for anatomical processing."""
22

3-
Command-line interface for anatomical preprocessing workflows.
4-
Calls into rbc.workflows.anatomical.
5-
"""
3+
from __future__ import annotations

src/rbc/cli/derivatives.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
"""Derivative computations CLI.
1+
"""CLI subcommand for derivative computation.
22
3-
Command-line interface for computing derivatives (ALFF/fALFF, ReHo, network
4-
centrality, atlas-based timeseries) from preprocessed data.
3+
Runs post-preprocessing analyses on cleaned BOLD data: ALFF/fALFF (amplitude
4+
of low-frequency fluctuations), ReHo (regional homogeneity), network
5+
centrality, and atlas-based timeseries extraction.
56
"""
7+
8+
from __future__ import annotations

src/rbc/cli/functional.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
"""Functional preprocessing CLI.
1+
"""CLI subcommand for functional processing.
22
3-
Command-line interface for functional preprocessing workflows.
4-
Requires anatomical preprocessing to have been run first.
3+
Parses subject/session/task arguments and delegates to
4+
``rbc.workflows.functional.single_session_preprocess``, which runs the functional
5+
stream (reorientation -> TR truncation -> motion correction). Anatomical
6+
preprocessing must be completed first since coregistration and template
7+
warping depend on the anatomical outputs.
58
"""
9+
10+
from __future__ import annotations

0 commit comments

Comments
 (0)