Skip to content

Commit d5338cf

Browse files
committed
add cursor rules
1 parent ebb148a commit d5338cf

File tree

3 files changed

+111
-1
lines changed

3 files changed

+111
-1
lines changed

.cursor/rules/pennlinc-shared.mdc

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
alwaysApply: true
3+
---
4+
# PennLINC BIDS App Shared Conventions
5+
6+
This project is one of four PennLINC BIDS Apps (qsiprep, qsirecon, xcp_d, aslprep) sharing
7+
the same architecture and conventions. See [AGENTS.md](mdc:AGENTS.md) for full details.
8+
9+
## Architecture
10+
11+
- CLI in `xcp_d/cli/` (parser.py, run.py, workflow.py, version.py)
12+
- Singleton config in [config.py](mdc:xcp_d/config.py) with sections: environment, execution, workflow, nipype, seeds
13+
- Workflows in `xcp_d/workflows/` using Nipype's `pe.Workflow`, `pe.Node`, `pe.MapNode`
14+
- Interfaces in `xcp_d/interfaces/` following Nipype patterns
15+
- Tests in `xcp_d/tests/` with pytest; integration tests gated by markers
16+
17+
## Workflow Rules
18+
19+
- Name all workflow factory functions `init_<name>_wf`; return a Workflow object
20+
- Use `LiterateWorkflow` from `niworkflows.engine.workflows`
21+
- Define `inputnode` and `outputnode` as `niu.IdentityInterface` nodes
22+
- Use `workflow.connect([(src, dst, [('out', 'in')])])` syntax with `# fmt:skip` on multi-line connects
23+
- Read global settings from `config` module, not function parameters
24+
25+
## Interface Rules
26+
27+
- Use Nipype traits for input/output specs (`File`, `traits.Bool`, etc.)
28+
- Implement `_run_interface(self, runtime)`, return `runtime`
29+
- Set outputs via `self._results['field'] = value`
30+
31+
## Code Style
32+
33+
- Linter: `ruff check`; Formatter: `ruff format`
34+
- Import sorting via ruff (isort-compatible)
35+
- Add `# fmt:skip` after multi-line `workflow.connect()` calls
36+
37+
## Testing
38+
39+
- Unit tests in `test_*.py` -- no external data or network access required
40+
- Integration tests use `@pytest.mark.<marker>` and are excluded by default
41+
- Fixtures: `data_dir`, `working_dir`, `output_dir` in conftest.py
42+
43+
## BIDS
44+
45+
- Outputs must conform to BIDS Derivatives specification
46+
- Use `pybids.BIDSLayout` for input queries
47+
- Use `DerivativesDataSink` for writing BIDS-compliant outputs

.cursor/rules/xcp_d.mdc

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
globs: "*.py"
3+
---
4+
# XCP-D Project Rules
5+
6+
## Project Identity
7+
8+
- Package: `xcp_d` -- fMRI postprocessing BIDS App
9+
- Default branch: `main`
10+
- Entry point: [xcp_d/cli/run.py](mdc:xcp_d/cli/run.py)
11+
12+
## Linting & Formatting
13+
14+
- Linter/formatter: ruff ~= 0.15.0
15+
- Config: [pyproject.toml](mdc:pyproject.toml) under `[tool.ruff]`
16+
- Pre-commit: [.pre-commit-config.yaml](mdc:.pre-commit-config.yaml) with ruff v0.6.2
17+
- Black is disabled (`[tool.black] exclude = ".*"`)
18+
- **Cleanest ignore list** of all four repos: only S105, S311, S603
19+
20+
## Version Management
21+
22+
- Uses `__about__.py` pattern: [xcp_d/__about__.py](mdc:xcp_d/__about__.py)
23+
- Exports `__version__`, `__packagename__`, `__copyright__`, `__credits__`
24+
- `_version.py` is auto-generated by hatch-vcs; `__about__.py` imports from it
25+
26+
## `fill_doc` Decorator
27+
28+
Use `@fill_doc` (from `xcp_d.utils.doc`) on workflow init functions to inject shared
29+
parameter documentation. The decorator fills `%(parameter_name)s` placeholders in docstrings.
30+
31+
## Config Hashing
32+
33+
`config.hash_config()` creates unique identifiers for pipeline configurations.
34+
Used to detect when outputs need regeneration due to parameter changes.
35+
See `DEFAULT_CONFIG_HASH_FIELDS` in [xcp_d/config.py](mdc:xcp_d/config.py).
36+
37+
## Ingression Modules
38+
39+
`xcp_d/ingression/` adapts non-BIDS input formats:
40+
- `abcdbids.py`: ABCD-BIDS format
41+
- `hcpya.py`: HCP Young Adult format
42+
- `ukbiobank.py`: UK Biobank format
43+
When adding new input formats, create a module in this directory.
44+
45+
## Executive Summary Reports
46+
47+
HTML reports generated via Jinja2 templates in `xcp_d/data/executive_summary_templates/`.
48+
Interface: `xcp_d/interfaces/execsummary.py`; utils: `xcp_d/utils/execsummary.py`.
49+
50+
## Key Module Paths
51+
52+
- BOLD workflows: `xcp_d/workflows/bold/` (cifti, nifti, concatenation)
53+
- Anatomical workflows: `xcp_d/workflows/anatomical/` (surface, volume, parcellation)
54+
- Parcellation: [xcp_d/workflows/parcellation.py](mdc:xcp_d/workflows/parcellation.py)
55+
- Bundled atlases: `xcp_d/data/atlases/` (Glasser, Gordon, HCP, Tian, MIDB, MyersLabonte)
56+
- Nuisance configs: `xcp_d/data/nuisance/` (YAML strategy files)
57+
- Config: [xcp_d/config.py](mdc:xcp_d/config.py)
58+
59+
## Testing
60+
61+
- Test extras: `tests` in pyproject.toml
62+
- Parallel test execution supported via `pytest-xdist`
63+
- Integration test markers defined in `[tool.pytest.ini_options]`
64+
- `mock_config` context manager in `xcp_d/tests/tests.py` for workflow unit tests

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ xcp_d/tests/pytests
33
xcp_d/tests/test_data
44
xcp_d/tests/data/test_data
55
.circleci/local_xcpd_path.txt
6-
.cursor
76

87
# setuptools-scm
98
xcp_d/_version.py

0 commit comments

Comments
 (0)