Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
* filter: Improved the speed and memory usage of subsampling with `--group-by` and `--subsample-max-sequences` by caching each record's group during the first pass instead of reading the metadata a second time. [#2018][] @trvrb
* filter: Improved the speed of computing groups for `--group-by` subsampling by replacing a row-wise pandas apply with a vectorized operation. [#2018][] @trvrb
* filter: Improved the speed of writing `--output-metadata` by streaming rows instead of building a dictionary per row. [#2018][] @trvrb
* Improved the error message for unrecognized arguments. [#2028][] @victorlin

[#2014]: https://github.com/nextstrain/augur/issues/2014
[#2018]: https://github.com/nextstrain/augur/pull/2018
[#2025]: https://github.com/nextstrain/augur/pull/2025
[#2028]: https://github.com/nextstrain/augur/issues/2028

## 34.0.0 (7 July 2026)

Expand Down
15 changes: 13 additions & 2 deletions augur/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .debug import DEBUGGING
from .errors import AugurError
from .io.print import print_err
from .argparse_ import HelpFormatter, add_command_subparsers, add_default_command
from .argparse_ import HelpFormatter, add_command_subparsers, add_default_command, SUBPARSER_ATTRIBUTE

DEFAULT_AUGUR_RECURSION_LIMIT = 10000
sys.setrecursionlimit(int(os.environ.get("AUGUR_RECURSION_LIMIT") or DEFAULT_AUGUR_RECURSION_LIMIT))
Expand Down Expand Up @@ -68,7 +68,18 @@ def make_parser():


def run(argv):
args = make_parser().parse_args(argv)
parser = make_parser()
args, extras = parser.parse_known_args(argv)

# Workaround for <https://github.com/python/cpython/issues/78660>
if extras:
# Message format copied from ArgumentParser.parse_args()
msg = "unrecognized arguments: %s" % " ".join(extras)
if subparser := getattr(args, SUBPARSER_ATTRIBUTE, None):
subparser.error(msg)
else:
parser.error(msg)

try:
return args.__command__.run(args)
except AugurError as e:
Expand Down
8 changes: 6 additions & 2 deletions augur/argparse_.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ def add_subparser(parent_subparsers: _SubParsersAction, *args, **kwargs) -> Argu
return parent_subparsers.add_parser(*args, **kwargs)


SUBPARSER_ATTRIBUTE = '__subparser__'

def add_command_subparsers(subparsers, commands, command_attribute='__command__'):
"""
Add subparsers for each command module.
Expand All @@ -109,8 +111,10 @@ def add_command_subparsers(subparsers, commands, command_attribute='__command__'
subparser = command.register_parser(subparsers)

# Add default attribute for command module
if command_attribute:
subparser.set_defaults(**{command_attribute: command})
subparser.set_defaults(**{command_attribute: command})

# Add a reference to the subparser
subparser.set_defaults(**{SUBPARSER_ATTRIBUTE: subparser})
Comment thread
huddlej marked this conversation as resolved.

# Use the same formatting class for every command for consistency.
# Set here to avoid repeating it in every command's register_parser().
Expand Down
Loading