Skip to content

Commit

Permalink
Merge branch 'trs/fix-help-all-on-≥3.10'
Browse files Browse the repository at this point in the history
  • Loading branch information
tsibley committed Feb 28, 2023
2 parents 2d458c5 + ee4f170 commit b6596a2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ development source code and as such may not be routinely kept up to date.
`{files}`.
([#260](https://github.com/nextstrain/cli/pull/260))

* When running on Python ≥3.10, the `--help` output of `nextstrain build`,
`nextstrain view`, and `nextstrain shell` once again shows just the most
common options. All options are still shown with `--help-all`. A regression
since Python 3.10 meant that `--help` acted the same as `--help-all` before
this fix. This affected any installation on Python ≥3.10, including
standalone installations, since the standalone binaries bundle Python 3.10.
([#259](https://github.com/nextstrain/cli/pull/259))


# 6.1.0.post1 (18 January 2023)

Expand Down
11 changes: 8 additions & 3 deletions nextstrain/cli/argparse.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Custom helpers for extending the behaviour of argparse standard library.
"""
import sys
from argparse import Action, ArgumentDefaultsHelpFormatter, ArgumentTypeError, SUPPRESS
from itertools import takewhile
from textwrap import indent
Expand Down Expand Up @@ -113,9 +114,13 @@ def __call__(self, parser, namespace, values, option_string = None):

def truncate_help(self, full_help):
"""
Truncate the full help after the standard "optional arguments" listing
and before any custom argument groups.
Truncate the full help after the standard "options" (or "optional
arguments") listing and before any custom argument groups.
"""
# See <https://github.com/python/cpython/pull/23858>
# and <https://bugs.python.org/issue9694>.
heading = "options:\n" if sys.version_info >= (3, 10) else "optional arguments:\n"

seen_optional_arguments_heading = False

def before_extra_argument_groups(line):
Expand All @@ -127,7 +132,7 @@ def before_extra_argument_groups(line):
nonlocal seen_optional_arguments_heading

if not seen_optional_arguments_heading:
if line == "optional arguments:\n":
if line == heading:
seen_optional_arguments_heading = True

return not seen_optional_arguments_heading \
Expand Down

0 comments on commit b6596a2

Please sign in to comment.