Skip to content

Reorganize repository to match sMRIPrep and NiPost#1624

Open
tsalo wants to merge 16 commits into
mainfrom
nipost-refactor
Open

Reorganize repository to match sMRIPrep and NiPost#1624
tsalo wants to merge 16 commits into
mainfrom
nipost-refactor

Conversation

@tsalo

@tsalo tsalo commented May 29, 2026

Copy link
Copy Markdown
Member

Closes #1329.

Changes proposed in this pull request

  • Shift from flat layout to src layout.

tsalo added 3 commits May 29, 2026 12:38
Move xcp_d/ -> src/xcp_d/ and xcp_d/tests/ -> test/ to follow the
fMRIPost/smriprep convention. Updates hatch build config, pytest
testpaths, ruff ignores, coverage paths, CircleCI path filters,
and Sphinx config to match the new layout. All moves done via git mv
to preserve rename history.

Also adds pythonpath=["."] to pytest config and updates all
xcp_d.tests.* imports to test.* to reflect the new uninstalled
test package location.

Closes #1329
…move

Update the pytest target in continue_config.yml from xcp_d to test
(the tests directory moved from xcp_d/tests/ to test/ in the src-layout
restructure). Update conftest.py default paths from the old installed-
package location to the CircleCI source-tree location (/tmp/src/xcp_d).
@tsalo tsalo added the refactor Changes to the codebase that don't impact workflow inputs or outputs. label May 29, 2026
tsalo and others added 13 commits May 29, 2026 12:55
Extract mock_config, get_nodes, chdir, modified_environ,
get_cpu_count, and update_resources from test/tests.py and
test/utils.py into a new src/xcp_d/_testing.py module.

This eliminates imports from the test/ package in both test files
and workflow docstrings, and makes these utilities available as
part of the installed package under xcp_d._testing. Delete
test/tests.py now that all its content has moved.
Move download_test_data, get_test_data_path, check_generated_files,
check_affines, run_command, reorder_expected_outputs, and list_files
from test/utils.py into src/xcp_d/_testing.py. Delete test/utils.py.

Update get_test_data_path to compute test/data/ relative to the new
location of _testing.py (src/xcp_d/ -> up 2 levels -> test/data/).
Replace hardcoded /tmp/src/xcp_d paths with a dynamically computed
default so local runs find test/data/test_data/ at the project root
rather than a CircleCI-only path.
Avoids a ModuleNotFoundError when conftest.py is loaded in a CI
environment where the installed xcp_d predates _testing.py.
With src on pythonpath, pytest finds xcp_d from src/xcp_d/ rather than
the installed package, making xcp_d._testing available even when the
installed package predates the module.
Not needed: pytest's package import mode adds the project root to
sys.path automatically (test/__init__.py is present), and xcp_d._testing
is part of the installed package once the Docker image is rebuilt.
=== Do not change lines below ===
{
 "chain": [],
 "cmd": "bash -lc 'if pixi lock --check; then echo '\"'\"'Lockfile up to date'\"'\"'; else pixi lock; fi'",
 "exit": 0,
 "extra_inputs": [],
 "inputs": [
  "pixi.lock",
  "pyproject.toml"
 ],
 "outputs": [
  "pixi.lock"
 ],
 "pwd": "."
}
^^^ Do not change lines above ^^^
When _testing.py is installed, __file__ points to site-packages, not
the source tree. test/data/ is not installed with the package, so the
path must be computed from the working directory, which pytest always
sets to the project root via testpaths.
get_test_data_path() cannot live in the installed package because
test/data/ is source-tree-only infrastructure. Any __file__- or cwd-
based computation in an installed module is fragile when the module is
loaded from site-packages in a Docker container.

Fix: expose test/data/ as a test_data_path pytest fixture in conftest.py,
using Path(__file__) which is always the source-tree path since conftest
is discovered and loaded from the filesystem (never from site-packages).

- Remove get_test_data_path() from src/xcp_d/_testing.py
- Add test_data_path session fixture to test/conftest.py
- Thread test_data_path into all integration test functions and
  _run_and_generate in test/test_cli.py
- Make download_test_data() require data_dir explicitly (no default)
- Make reorder_expected_outputs() accept test_data_path as a parameter
When the package is installed to site-packages, coverage records paths
like */site-packages/xcp_d/. The coverage.paths mapping tells combine
these are equivalent to src/xcp_d/ in the source tree.
=== Do not change lines below ===
{
 "chain": [],
 "cmd": "bash -lc 'if pixi lock --check; then echo '\"'\"'Lockfile up to date'\"'\"'; else pixi lock; fi'",
 "exit": 0,
 "extra_inputs": [],
 "inputs": [
  "pixi.lock",
  "pyproject.toml"
 ],
 "outputs": [
  "pixi.lock"
 ],
 "pwd": "."
}
^^^ Do not change lines above ^^^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Changes to the codebase that don't impact workflow inputs or outputs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reorganize package following fMRIPost structure

2 participants