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

augur curate --help raises ValueError #1753

Closed
joverlee521 opened this issue Feb 11, 2025 · 7 comments · Fixed by #1755
Closed

augur curate --help raises ValueError #1753

joverlee521 opened this issue Feb 11, 2025 · 7 comments · Fixed by #1755
Labels
bug Something isn't working

Comments

@joverlee521
Copy link
Contributor

augur curate --help raises a ValueError:

$ augur curate --help
Traceback (most recent call last):
  File "/usr/local/bin/augur", line 33, in <module>
    sys.exit(load_entry_point('nextstrain-augur', 'console_scripts', 'augur')())
  File "/nextstrain/augur/augur/__main__.py", line 30, in main
    return augur.run( argv[1:] )
  File "/nextstrain/augur/augur/__init__.py", line 68, in run
    args = make_parser().parse_args(argv)
  File "/usr/local/lib/python3.10/argparse.py", line 1833, in parse_args
    args, argv = self.parse_known_args(args, namespace)
  File "/usr/local/lib/python3.10/argparse.py", line 1866, in parse_known_args
    namespace, args = self._parse_known_args(args, namespace)
  File "/usr/local/lib/python3.10/argparse.py", line 2061, in _parse_known_args
    positionals_end_index = consume_positionals(start_index)
  File "/usr/local/lib/python3.10/argparse.py", line 2038, in consume_positionals
    take_action(action, args)
  File "/usr/local/lib/python3.10/argparse.py", line 1943, in take_action
    action(self, namespace, argument_values, option_string)
  File "/usr/local/lib/python3.10/argparse.py", line 1221, in __call__
    subnamespace, arg_strings = parser.parse_known_args(arg_strings, None)
  File "/usr/local/lib/python3.10/argparse.py", line 1866, in parse_known_args
    namespace, args = self._parse_known_args(args, namespace)
  File "/usr/local/lib/python3.10/argparse.py", line 2079, in _parse_known_args
    start_index = consume_optional(start_index)
  File "/usr/local/lib/python3.10/argparse.py", line 2019, in consume_optional
    take_action(action, args, option_string)
  File "/usr/local/lib/python3.10/argparse.py", line 1943, in take_action
    action(self, namespace, argument_values, option_string)
  File "/usr/local/lib/python3.10/argparse.py", line 1106, in __call__
    parser.print_help()
  File "/usr/local/lib/python3.10/argparse.py", line 2567, in print_help
    self._print_message(self.format_help(), file)
  File "/usr/local/lib/python3.10/argparse.py", line 2551, in format_help
    return formatter.format_help()
  File "/usr/local/lib/python3.10/argparse.py", line 283, in format_help
    help = self._root_section.format_help()
  File "/usr/local/lib/python3.10/argparse.py", line 214, in format_help
    item_help = join([func(*args) for func, args in self.items])
  File "/usr/local/lib/python3.10/argparse.py", line 214, in <listcomp>
    item_help = join([func(*args) for func, args in self.items])
  File "/usr/local/lib/python3.10/argparse.py", line 214, in format_help
    item_help = join([func(*args) for func, args in self.items])
  File "/usr/local/lib/python3.10/argparse.py", line 214, in <listcomp>
    item_help = join([func(*args) for func, args in self.items])
  File "/usr/local/lib/python3.10/argparse.py", line 553, in _format_action
    parts.append(self._format_action(subaction))
  File "/usr/local/lib/python3.10/argparse.py", line 540, in _format_action
    help_text = self._expand_help(action)
  File "/usr/local/lib/python3.10/argparse.py", line 637, in _expand_help
    return self._get_help_string(action) % params
ValueError: unsupported format character 'Y' (0x59) at index 198
@joverlee521 joverlee521 added the bug Something isn't working label Feb 11, 2025
@joverlee521
Copy link
Contributor Author

Tracked down first bad commit to 3401422, which updates the docstring for curate/format_dates.py. I can run augur curate format-dates -h without any issues 🤔

@joverlee521
Copy link
Contributor Author

From python/cpython#60027 (comment):

The problem is the timeformat. % codes are used to include data into the strings, so if you want a literal % in the help string, you need to double it.

This makes me even more confused why augur curate format-dates -h doesn't raise an error...


I don't think we want to double % in this case because then the rendered docs will have %%Y instead of %Y.

joverlee521 added a commit that referenced this issue Feb 12, 2025
Limit the `format-dates` help to the first line, which does not
include the `%Y` bit that was causing the error.

Resolves <#1753>
@victorlin
Copy link
Member

I don't think we want to double % in this case because then the rendered docs will have %%Y instead of %Y.

I'd think that formatting should be prioritized for the CLI help text, and that we should somehow work around the %% in the docs rendering.

@joverlee521 joverlee521 mentioned this issue Feb 12, 2025
4 tasks
@joverlee521
Copy link
Contributor Author

This makes me even more confused why augur curate format-dates -h doesn't raise an error...

Ah, the %Y is in the description for augur curate format-dates -h, but is in the help message for augur curate -h resulting in the error.

I've worked around this for now in #1755 to only include the first line as the help message.

@joverlee521
Copy link
Contributor Author

I'd think that formatting should be prioritized for the CLI help text, and that we should somehow work around the %% in the docs rendering.

I'm going to push back here because I just realized the %%Y shows up in the description for the subcommand 🤦‍♀

Image

So I think the correct solution is to exclude the % from the first line of the docstring which is used in the help message. It then shows up correctly in the CLI description.

@victorlin
Copy link
Member

%%Y renders differently in augur curate -h and augur curate format-dates -h? This sounds like an argparse bug... but I think what you have in the PR now is looking good.

@joverlee521
Copy link
Contributor Author

%%Y renders differently in augur curate -h and augur curate format-dates -h? This sounds like an argparse bug...

It's the different treatment of the string in help (augur curate -h) vs description (augur curate format-dates -h).

We are automatically adding the description to the subparsers in Augur:

augur/augur/argparse_.py

Lines 67 to 68 in e6df775

if not subparser.description and command.__doc__:
subparser.description = command.__doc__

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants