Skip to content

Use argument-list subprocess calls for NiftyReg commands#267

Merged
IgorTatarnikov merged 6 commits intobrainglobe:mainfrom
AlgoFoe:bug-fix
Jan 6, 2026
Merged

Use argument-list subprocess calls for NiftyReg commands#267
IgorTatarnikov merged 6 commits intobrainglobe:mainfrom
AlgoFoe:bug-fix

Conversation

@AlgoFoe
Copy link
Contributor

@AlgoFoe AlgoFoe commented Jan 2, 2026

Description

What is this PR

  • Bug fix
  • Addition of a new feature
  • Other

Why is this PR needed?

  • NiftyReg commands in brainreg are currently constructed as shell strings, which can be fragile when file paths contain spaces and lead to platform-dependent behavior.

What does this PR do?

  • It updates all NiftyReg command invocations to use argument-list based subprocess execution instead of shell-based string commands. This removes the need for manual quoting and safely handles paths with spaces on all platforms.

References

How has this PR been tested?

  • Tested locally on Windows with input, output, and install paths containing spaces.

Is this a breaking change?

  • No.

Does this PR require an update to the documentation?

  • No.

Checklist:

  • The code has been tested locally
  • Tests have been added to cover all new functionality (unit & integration)
  • The documentation has been updated to reflect any changes
  • The code has been formatted with pre-commit

@AlgoFoe
Copy link
Contributor Author

AlgoFoe commented Jan 5, 2026

I think the CI failure may be due to NiftyReg argument ordering. Moving to list-based execution seems to expose that -ref / -flo need to appear before other flags for reg_aladin and reg_f3d.
I have a possible fix that reorders the command construction, happy to push it if that makes sense.

@AlgoFoe
Copy link
Contributor Author

AlgoFoe commented Jan 5, 2026

I think the CI failure may be due to NiftyReg argument ordering. Moving to list-based execution seems to expose that -ref / -flo need to appear before other flags for reg_aladin and reg_f3d. I have a possible fix that reorders the command construction, happy to push it if that makes sense.

Reference Image:
image

I had a closer look at reg_aladin.cpp, and it looks like -ref and -flo are expected early in the argument list.

@IgorTatarnikov
Copy link
Member

I have a feeling this error will be resolved when we use the new version of brainglobe-utils. Based on my testing, if subprocess.check_call is passed a list as the cmd and shell=True (the current behaviour of brainglobe-utils) only the first element of the list is passed to the command line (i.e. it's as if it's only calling the binary with no other arguments).

@AlgoFoe
Copy link
Contributor Author

AlgoFoe commented Jan 5, 2026

Got it, thanks for clarifying! I’ll hold off on changing the argument order and let this resolve once brainreg is using the updated brainglobe-utils

Copy link
Member

@IgorTatarnikov IgorTatarnikov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to add a test in tests/tests/test_integration/test_registration.py that uses an output path with a space in it. There would be no need to compare the output to the regression data, just ensuring that the files are created.

@IgorTatarnikov IgorTatarnikov linked an issue Jan 6, 2026 that may be closed by this pull request
@AlgoFoe
Copy link
Contributor Author

AlgoFoe commented Jan 6, 2026

Would it be possible to add a test in tests/tests/test_integration/test_registration.py that uses an output path with a space in it. There would be no need to compare the output to the regression data, just ensuring that the files are created.

Yes, that makes sense. I will update _prepare_openmp_thread_flag to store the flag as a list and also add a test.
I will push the update shortly.

@AlgoFoe
Copy link
Contributor Author

AlgoFoe commented Jan 6, 2026

Would it be possible to add a test in tests/tests/test_integration/test_registration.py that uses an output path with a space in it. There would be no need to compare the output to the regression data, just ensuring that the files are created.

Yes, that makes sense. I will update _prepare_openmp_thread_flag to store the flag as a list and also add a test. I will push the update shortly.

I have pushed the update and also added a missing SegmentationError raise.

@AlgoFoe
Copy link
Contributor Author

AlgoFoe commented Jan 6, 2026

I think codecov seems to be failing because the new raise SegmentationError line isn’t covered by tests. I can add a small test to cover this if that’s okay.

@IgorTatarnikov
Copy link
Member

That would be great!

@AlgoFoe
Copy link
Contributor Author

AlgoFoe commented Jan 6, 2026

That would be great!

Added the missing SegmentationError tests and pushed the update.

Copy link
Member

@IgorTatarnikov IgorTatarnikov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, this is almost ready to go! Could you pin brainglobe-utils >= 0.10.0 in pyproject.toml.

Copy link
Member

@IgorTatarnikov IgorTatarnikov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

Thank you @AlgoFoe

@IgorTatarnikov IgorTatarnikov merged commit 73385b3 into brainglobe:main Jan 6, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] NiftyReg doesn't deal with spaces in file names

2 participants