Skip to content

Commit e63bb8d

Browse files
committed
Bump styxcache to 0.2.0 and restore session-wide wrap
styxcache 0.2.0 persists stdout/stderr on cache hits (styx-api#5), so tools like ants.print_header that convey data via stdout work through the cache. The narrowing workaround in pipeline_data can revert to the session-wide wrap in _niwrap_session_runner, which also lets integration tests sharing an xdist worker benefit from cached tool outputs.
1 parent c206a37 commit e63bb8d

3 files changed

Lines changed: 36 additions & 51 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ dev = [
2929
"ruff>=0.8.1",
3030
"deptry>=0.23.0",
3131
"pytest-xdist[psutil]>=3.8.0",
32-
"styxcache>=0.1.0"
32+
"styxcache>=0.2.0,<0.3"
3333
]
3434
docs = ["pdoc>=15.0.0"]
3535

tests/full_pipeline/conftest.py

Lines changed: 31 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,22 @@ def _niwrap_session_runner(
8686
runner.data_dir = data_dir
8787
logger = logging.getLogger(runner.logger_name)
8888
logger.setLevel(logging.DEBUG)
89-
return runner
90-
9189

92-
def _runner_kind(runner: niwrap.Runner) -> str:
93-
return type(runner).__name__.lower().replace("runner", "")
90+
cache_dir = os.environ.get("RBC_STYXCACHE_DIR")
91+
if cache_dir and runner_type in {"docker", "podman"}:
92+
resolver = (
93+
docker_digest_resolver
94+
if runner_type == "docker"
95+
else podman_digest_resolver
96+
)
97+
wrapped = _AttrProxyCachingRunner(
98+
base=runner,
99+
cache_dir=cache_dir,
100+
policy=CachePolicy(image_digest=resolver),
101+
)
102+
niwrap.set_global_runner(wrapped)
103+
return wrapped
104+
return runner
94105

95106

96107
@pytest.fixture(scope="session")
@@ -116,48 +127,22 @@ def pipeline_data(
116127
_niwrap_session_runner: niwrap.Runner,
117128
manifest: dict[str, object],
118129
) -> PipelineData:
119-
"""Run anatomical and functional preprocessing once for all e2e tests.
120-
121-
The styxcache wrap is scoped to this fixture's computation only.
122-
Integration/unit tests that share the worker see the base runner so
123-
they don't risk cache hits on tool calls whose semantics exceed what
124-
styxcache persists (e.g. stdout-returning tools like ants.print_header).
125-
"""
126-
base = _niwrap_session_runner
127-
cache_dir = os.environ.get("RBC_STYXCACHE_DIR")
128-
kind = _runner_kind(base)
129-
wrapped: niwrap.Runner | None = None
130-
if cache_dir and kind in {"docker", "podman"}:
131-
resolver = (
132-
docker_digest_resolver if kind == "docker" else podman_digest_resolver
133-
)
134-
wrapped = _AttrProxyCachingRunner(
135-
base=base,
136-
cache_dir=cache_dir,
137-
policy=CachePolicy(image_digest=resolver),
138-
)
139-
niwrap.set_global_runner(wrapped)
140-
try:
141-
anat = anatomical_preprocess(test_subject.t1w)
142-
func_metadata = FunctionalMetadata.load(test_subject.bold)
143-
func = functional_preprocess(
144-
in_bold=test_subject.bold,
145-
t1w_brain=anat.brain,
146-
wm_bbr_mask=anat.wm_bbr_mask,
147-
brain_mask=anat.brain_mask,
148-
csf_mask=anat.csf_mask,
149-
wm_mask=anat.wm_mask,
150-
anat_to_template=anat.anat_to_template_xfm,
151-
metadata=func_metadata,
152-
)
153-
template_brain_mask = _warp_mask_to_template(
154-
anat.brain_mask,
155-
REGISTRATION_TEMPLATES.brain_2mm,
156-
anat.anat_to_template_xfm,
157-
)
158-
finally:
159-
if wrapped is not None:
160-
niwrap.set_global_runner(base)
130+
"""Run anatomical and functional preprocessing once for all e2e tests."""
131+
anat = anatomical_preprocess(test_subject.t1w)
132+
func_metadata = FunctionalMetadata.load(test_subject.bold)
133+
func = functional_preprocess(
134+
in_bold=test_subject.bold,
135+
t1w_brain=anat.brain,
136+
wm_bbr_mask=anat.wm_bbr_mask,
137+
brain_mask=anat.brain_mask,
138+
csf_mask=anat.csf_mask,
139+
wm_mask=anat.wm_mask,
140+
anat_to_template=anat.anat_to_template_xfm,
141+
metadata=func_metadata,
142+
)
143+
template_brain_mask = _warp_mask_to_template(
144+
anat.brain_mask, REGISTRATION_TEMPLATES.brain_2mm, anat.anat_to_template_xfm
145+
)
161146
manifest["anat"] = _to_dict(anat)
162147
manifest["func"] = _to_dict(func)
163148
manifest["template_brain_mask"] = str(template_brain_mask)

uv.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)