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
interface: Allow positional arguments with underscores #5525
Conversation
When processing its add_args value, update_docstring_with_parameters() assumes getargspec returns a tuple for "defaults", but it returns None when there are no optional arguments. This doesn't matter in practice for DataLad commands because they all have optional arguments.
It doesn't functionally matter, but go with the PEP-recommended variant.
This ends up as --exclude-autometa on the command line because Interface.setup_parser() maps this to a dash, so it's confusing to use an underscore here. (And this is the only option in the code base that uses an underscore in an `args` value.)
Some interface/parser logic expects these common options to be present, which makes testing it more cumbersome. Move the code for adding these options out of main.setup_parser() so that tests can more easily use it.
Interface.setup_parser() assumes that argparse replaces all dashes in the argument's name with underscores. However, argparse leaves dashes in positional arguments untouched. This results in an error when positional arguments specified via Parameter() use names with underscores (in the Python variant) and dashes (in the command-line variant). Trying to work around this by using Parameter(..., dest=...) just leads to a different error because Interface.setup_parser() doesn't account for the fact that argparse.add_argument() treats `dest` differently depending on whether the argument is a positional argument or an optional one. Teach setup_parser() to 1) leave positional arguments untouched and 2) not pass `dest` as a keyword argument to add_argument() when adding a positional parameter. Parameter names for positional argument can now include underscores, either inferred from the parameter name or explicitly specified via `args`. If the caller wants the dashed form to show up in the command-line output, `metavar` can be specified. Closes datalad#2269.
Codecov Report
@@ Coverage Diff @@
## maint #5525 +/- ##
==========================================
- Coverage 90.19% 89.58% -0.62%
==========================================
Files 296 296
Lines 41989 42020 +31
==========================================
- Hits 37871 37642 -229
- Misses 4118 4378 +260
Continue to review full report at Codecov.
|
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.
This LGTM, and thx much for the batch of clean-ups on the side!
ok_, | ||
patch_config, | ||
with_tempfile, | ||
) |
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.
T H A N K Y O U !
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.
It looks like there may be only four files left that use a star import :)
This series updates the argument parsing logic so that parameter names for positional options can use underscores. The third commit contains a fix for a type bug that I ran into while testing this. The last commit contains the main fix.
Closes #2269.
cc @christian-monch