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

Use ExtendOverwriteDefault for all multi-value options #1709

Merged
merged 8 commits into from
Jan 14, 2025

Conversation

victorlin
Copy link
Member

@victorlin victorlin commented Jan 8, 2025

Description of proposed changes

This is largely a follow-up to #1445 which in hindsight was not done properly. See commits for details.

Related issue(s)

#1707

89fbda2 closes #1706 (no longer necessary)

Checklist

@victorlin victorlin self-assigned this Jan 8, 2025
Copy link

codecov bot commented Jan 8, 2025

Codecov Report

Attention: Patch coverage is 95.69892% with 4 lines in your changes missing coverage. Please review.

Project coverage is 72.90%. Comparing base (1843a9b) to head (28e6e8c).
Report is 9 commits behind head on master.

Files with missing lines Patch % Lines
augur/argparse_.py 86.66% 1 Missing and 1 partial ⚠️
augur/export_v2.py 85.71% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1709      +/-   ##
==========================================
+ Coverage   72.72%   72.90%   +0.17%     
==========================================
  Files          79       79              
  Lines        8287     8299      +12     
  Branches     1697     1694       -3     
==========================================
+ Hits         6027     6050      +23     
+ Misses       1972     1961      -11     
  Partials      288      288              

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

@tsibley
Copy link
Member

tsibley commented Jan 8, 2025

Ideally, there should be a way to enforce that if nargs="+"/"*" is used, it must be paired with ExtendOverwriteDefault. A note in the dev docs doesn't seem useful enough, but I'm not sure how to do enforce automatically in PR checks.

I'll contribute a test file for this shortly.

@tsibley
Copy link
Member

tsibley commented Jan 8, 2025

See 8f6f145.

@victorlin
Copy link
Member Author

Amazing!

=================================== FAILURES ===================================
_ test_ExtendOverwriteDefault[augur curate transform-strain-name --backup-fields] _
tests/test_argparse_linting.py:26: in test_ExtendOverwriteDefault
    assert isinstance(action, ExtendOverwriteDefault)
E   assert False
E    +  where False = isinstance(_StoreAction(option_strings=['--backup-fields'], dest='backup_fields', nargs='*', const=None, default=[], type=None, choices=None, required=False, help="List of backup fields to use as strain name if the value in 'strain' does not match the strain regex pattern. If multiple fields are provided, will use the first field that has a non-empty string.", metavar=None), ExtendOverwriteDefault)
        action     = _StoreAction(option_strings=['--backup-fields'], dest='backup_fields', nargs='*', const=None, default=[], type=None, choices=None, required=False, help="List of backup fields to use as strain name if the value in 'strain' does not match the strain regex pattern. If multiple fields are provided, will use the first field that has a non-empty string.", metavar=None)

@victorlin victorlin force-pushed the victorlin/ExtendOverwriteDefault-everwhere branch from 8f6f145 to db14caf Compare January 8, 2025 21:02
@victorlin victorlin force-pushed the victorlin/ExtendOverwriteDefault-everwhere branch 2 times, most recently from f37ce4f to 38233fd Compare January 11, 2025 01:15
@victorlin victorlin force-pushed the victorlin/ExtendOverwriteDefault-everwhere branch from 38233fd to 89950c8 Compare January 13, 2025 19:17
victorlin and others added 4 commits January 13, 2025 14:56
This simplifies the logic since 'extend' directly handles a one-to-many
relationship (e.g. --maintainers a b c) instead of using a nested list.
These should have been a part of "Allow repeating an option that takes
multiple values" (adf1e78).
This is more in line with the behavior of extending rather than
overriding these values. Help text for the command line option has also
been reworded.

Co-authored-by: Jover Lee <[email protected]>
The distinction that this sought to make is no longer necessary after
removing the last usage of action='extend' with a non-empty default
list.

Commits were:

- "Use custom help formatter class" (7540a1b)
- "Add help text to clarify extend actions" (6f6d1a9)
Copy link
Contributor

@joverlee521 joverlee521 left a comment

Choose a reason for hiding this comment

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

Thanks @victorlin! Sorry for the inconsistent usage of ExtendOverwriteDefault 🙏

augur/curate/format_dates.py Outdated Show resolved Hide resolved
CHANGES.md Show resolved Hide resolved
victorlin and others added 4 commits January 14, 2025 10:31
nargs="+"/"*" without any action allows overriding the defaults but does
not allow multiple of the same option flag.

Adding action="extend" allows multiple of the same option flag but
removes the ability to override defaults.

The custom action=ExtendOverwriteDefault allows the best of both worlds.

---

This was partially applied in "Allow repeating an option that takes
multiple values" (adf1e78). At the time I chose to only use
ExtendOverwriteDefault for options that had a non-empty default list.
This was done by manually inspecting each argument that used
nargs="+"/"*" at the time, a process prone to future misalignment.

Now, I am applying it to all other usage of nargs="+"/"*" to
future-proof for any default value changes that could cause
action="extend" to behave different than originally intended.
This prevents poor rendering on reStructuredText docs.
@victorlin victorlin force-pushed the victorlin/ExtendOverwriteDefault-everwhere branch from 49568ad to 28e6e8c Compare January 14, 2025 18:33
@victorlin victorlin merged commit 5555d65 into master Jan 14, 2025
33 checks passed
@victorlin victorlin deleted the victorlin/ExtendOverwriteDefault-everwhere branch January 14, 2025 18:48
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.

Help text injected by CustomHelpFormatter is not included in rendered docs
4 participants