Skip to content
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

Ensure that -list-labels is the last argument that is parsed #3864

Merged
merged 3 commits into from Aug 24, 2022

Conversation

joshuacwnewton
Copy link
Member

Description

sct_extract_metric -list-labels is a way to display the info_label.txt file contained within the folder pointed to by -f:

file_label = os.path.join(namespace.f, Param().file_info_label)

However, if the user specifies a new -f, then the order of parsing starts to matter:

  • If sct_extract_metric -f <directory> -list-labels is used, then -f will be updated first, and -list-labels will display correctly.
  • If sct_extract_metric -list-labels -f <directory> is used instead, then -list-labels will be parsed before -f can be updated, and it will either crash, or display the wrong info_label.txt file.

To make sure that -list-labels always works as expected, we need to parse it last in the list of arguments, hence this PR.

Linked issues

Fixes #3634.

This ensures that other arguments are parsed first, so that `-list-labels` can see those parsed values.

Conversely, if `-list-labels` were to be parsed first instead, then it wouldn't see any of the updates
to default argument values.
@joshuacwnewton joshuacwnewton added bug category: fixes an error in the code sct_extract_metric context: labels Aug 19, 2022
@joshuacwnewton joshuacwnewton added this to the 5.8 milestone Aug 19, 2022
@joshuacwnewton joshuacwnewton self-assigned this Aug 19, 2022
Copy link
Member

@mguaypaq mguaypaq left a comment

Choose a reason for hiding this comment

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

At first I thought this fix didn't feel right (messing around with the strings in argv), and that -list-labels should just have been processed once all arguments are parsed. But as documented in _ListLabelsAction (yay docs!), parsing would fail first because of a missing mandatory argument -i. (And a custom action that calls parser.exit() is how argparse itself handles the --help argument, so that has to be acceptable.)

Which is a long-winded way of saying that this is fine! Thanks for the fix.

@mguaypaq mguaypaq merged commit b72ad50 into master Aug 24, 2022
@mguaypaq mguaypaq deleted the jn/3634-ensure-list-labels-uses-f-flag branch August 24, 2022 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug category: fixes an error in the code sct_extract_metric context:
Projects
None yet
Development

Successfully merging this pull request may close these issues.

-list-labels crashes when pointing to another non-default atlas location
2 participants