-
Notifications
You must be signed in to change notification settings - Fork 0
Python Command Line Changes #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
Created custom callable classes for handling different datatypes for positional and optional arguments on the command line. Used ArgumentTypeError for exception management instead of ValueError since the former allows allows adding custom error messages.
Added newly defined callables (in app.py) for each positional and optional command line argument of mrtrix_cleanup and dwicat
|
Is the use syntax definitely " |
lib/mrtrix3/app.py
Outdated
| class TypeOutputDirectory: | ||
| def __call__(self, input_value): | ||
| return input_value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a number of output types, check:
https://github.com/MRtrix3/mrtrix3/blob/3.0.4/core/app.cpp#L1181-L1235
From memory, when the -force option is used, there's a global "output files will be overwritten", but I think that in some instances there can be individual error messages of "this specific file / directory already exists, and will be overwritten at command completion"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean a warning message needs to be added? The value of --force isn't going to be accessible to the output directory type is it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Sorry yes, individual warning messages for individual items, not errors.
- In some cases we do issue an error; specifically attempting to overwrite a pre-existing fixel directory using
-force. Can lead to unexpected behaviour, so we forbid it. - Regarding knowledge of the force-overwrite status, this I don't know. It depends on the internals of
argparse. But normally I'd read fromapp.FORCE_OVERWRITEin that case, which only gets set afterargparse.parse_args()is finished, which means it probably will never be set when those callables are invoked.
Better, which bears some relation to ENH Warn on unused options MRtrix3/mrtrix3#1975, would be for the callable to yield some class for which a pre-existing file at that path could be checked at the first instance at which the executing script reads from that path. - Pretty sure that the situation where individual warning messages for overwriting individual files is specific to the Python scripts and doesn't happen in the C++ binaries. So if that no longer happens as a natural consequence of these changes, it's not the end of the world, especially given that up to this point it had to be hard-coded on a per-case basis.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you won't be able to get it to work from inside the type callable. You would need to add some code to the app I think to loop through all types and find the file/directory types
Updated the logic for TypeBoolean class for consistency with C++ command-line behaviour Added new checks in TypeInputTractogram class for file validation
Added callables for each positional and optional command line argument in dwifslpreproc, dwigradcheck, dwishellmath, labelsgmfix, mask2glass, population_template and responsemean
|
Preferable for class names to echo those used in C++ code: |
Co-authored-by: Ankita Sanil <ankitasanil@gmail.com>
Used the new syntax as "type=app.Parser.TypeInputImage()" across all Python API commands
Replaced the traditional for loop with list comprehension in TypeIntegerSequence and TypeFloatSequence classes
|
While in cd33930 for |
Applies to both population-template and mrregister. Makes "none" a valid selection of robust estimator in both cases.
Updated class names across all commands to be in sync with C++ code
|
From a few different sources, it looks like custom Actions should derive from |
Implemented class inheritance to avoid duplicate checks for tractogram input files. Instead, reused the checks from ArgFileIn type via inheritance.
Changes for handling piped images in the Python API scripts. However, this implementation does not include deletion of the temp/piped images at the end of the command execution.
The current implementation is temporary since it doesn't cover all the use-cases. However, it supports a working scenario.
Looks ok to me. |
|
@Lestropie , just trying to work out what is necessary to finish off this PR. Is it just a few stylistic changes you want first? |
Could they even mirror them more closely by using snake_case, e.g. |
which are the custom Actions? |
This might be a red herring on my part. I may have temporarily mixed up types and actions. Though it also depends on the most appropriate way to handle image piping. |
Would it be possible to split them up if there are other issues in MRtrix3#1392 that prove tricky?
Personally I find pylint pretty annoying (flake8 is more reasonable IMO), and in such cases where the user doesn't need to know whether it is a class or function there isn't much benefit trying to stick to the convention.
Yeah, I think actions are for different use cases |
Definitely don't want to skip over the piping; appreciate that in your scenario you're invested in typed arguments, but from our perspective that was actually just a means to an end, so stopping short of that mark would be kind of unusual. And wouldn't want to split for the sake of having typed arguments for Pydra if it then turned out that we need to make further backward-incompatible back-end changes to facilitate the piping. The other stuff should not be terribly difficult. Using |
ok, fair enough. Let me know if there is anything I can do to push it along |
|
Given you're active and eager, I'll pull these commits over to a branch on the main repo, try to make the primary up-front changes I'd want to make, and then we can see what's left from there. |
These changes are relevant to the issue
#1392 (MRtrix3#1392) and include below modifications:@Lestropie - Please review these changes