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

Register subparsers recursively #1640

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

victorlin
Copy link
Member

@victorlin victorlin commented Sep 24, 2024

Description of proposed changes

Motivated by the desire to set a non-default formatter for all parsers including the top-level parser and subparsers.

Related issue(s)

Checklist

  • Add back create_shared_parser to fix augur curate
  • Automated checks pass
  • Check if you need to add a changelog message
  • Check if you need to add tests
  • Check if you need to update docs

@victorlin victorlin self-assigned this Sep 24, 2024
@victorlin victorlin mentioned this pull request Sep 24, 2024
5 tasks
@victorlin victorlin force-pushed the victorlin/argparse-register-commands branch 2 times, most recently from 51f7dca to 710f804 Compare September 25, 2024 23:11
Comment on lines +71 to +75
# Recursively register any subcommands
if getattr(subparser, "subcommands", None):
register_commands(subparser, subparser.subcommands)
Copy link
Member Author

Choose a reason for hiding this comment

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

This breaks augur curate subcommands

$ cat records.ndjson | augur curate passthru
Traceback (most recent call last):
  File "…/augur/__init__.py", line 72, in run
    return args.__command__.run(args)
TypeError: run() missing 1 required positional argument: 'records'

because each subcommand's run function is expected to be called through augur curate's own run function, but it is now called directly at the top level.

Maybe recursively registering subcommands is not the right thing to do in this codebase.

Copy link
Contributor

Choose a reason for hiding this comment

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

I remember having to work around the top level run when initially adding the augur curate subcommand.

# Using a subcommand attribute so subcommands are not directly
# run by top level Augur. Process I/O in `curate`` so individual
# subcommands do not have to worry about it.
add_command_subparsers(subparsers, SUBCOMMANDS, SUBCOMMAND_ATTRIBUTE)

Would it be weird to keep augur curate as a special case?

Copy link
Member

Choose a reason for hiding this comment

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

Two options:

  1. Further adapt how augur curate commands share functionality so calling their run() from the top-level works. This could be done relatively straightforwardly.
  2. Don't recursively register subcommands; leave the pattern of commands with subcommands invoking register_commands(…) themselves.

I don't think either gets the way of the functional improvements we want to make? So it's a matter of preference.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the input – I'll try option 1 above to align with Nextstrain CLI code.

This is necessary to register subparsers recursively.
This is necessary to register subparsers recursively.
This information will be lost when registering subparsers recursively.
Keeps consistent with Nextstrain CLI.
@victorlin victorlin force-pushed the victorlin/argparse-register-commands branch from 710f804 to f5e9472 Compare October 31, 2024 23:59
Copy link

codecov bot commented Nov 1, 2024

Codecov Report

Attention: Patch coverage is 95.34884% with 6 lines in your changes missing coverage. Please review.

Project coverage is 72.36%. Comparing base (c0bccdf) to head (a4ee061).

Files with missing lines Patch % Lines
augur/curate/_shared.py 92.40% 5 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1640      +/-   ##
==========================================
+ Coverage   72.26%   72.36%   +0.10%     
==========================================
  Files          79       80       +1     
  Lines        8271     8294      +23     
  Branches     1691     1691              
==========================================
+ Hits         5977     6002      +25     
+ Misses       2009     2008       -1     
+ Partials      285      284       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants