Support click >= 8.2.0#1883
Open
rly wants to merge 1 commit into
Open
Conversation
click 8.2 made Choice generic and, for an Enum, matches on member names instead of values. The (str, Enum) options in the CLI rely on their lowercase values being the accepted tokens, so add an EnumChoice type that keeps choices as the enum member values and returns the corresponding member, and use it for the affected options. This lets the click < 8.2.0 upper bound be removed. Closes dandi#1631 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1883 +/- ##
==========================================
+ Coverage 76.79% 76.86% +0.07%
==========================================
Files 87 88 +1
Lines 12805 12866 +61
==========================================
+ Hits 9833 9890 +57
- Misses 2972 2976 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1631.
Summary
Removes the
click < 8.2.0upper bound so dandi-cli can be installed alongside packages that require newer click (for examplelinkml-runtime >= 1.11, which declaresclick >= 8.2). The bound guarded a behavior change in click 8.2'sChoicerewrite; this PR adapts dandi's enum based options to that change while preserving the existing command line surface.Background
click 8.2 made
Choicegeneric. For anEnum,click.Choice(list(SomeEnum))now matches on the enum member names instead of their values. dandi builds twelve options from(str, Enum)types whose values are the documented lowercase tokens (error,skip,refresh, ...), so under click 8.2+ those options accept--existing SKIPand reject--existing skip, breaking every documented invocation. The 8.2.2 release (referenced in click #2911) only changed how the default is rendered in--help; the matching behavior is unchanged and still reproduces on click 8.4.Changes
EnumChoicetodandi/cli/base.py: aclick.Choicesubclass built from the enum member values that converts the matched value back to the enum member. This keeps the lowercase value tokens on the command line and passes the enum member to the command callback, matching pre 8.2 behavior on every supported click version.click.Choice(list(SomeEnum))options incmd_upload,cmd_download,cmd_organize, andcmd_movetoEnumChoice(SomeEnum).click.Choice(list(dandi_layout_fields))is left as is because it is a dict of strings, unaffected by the enum change.< 8.2.0upper bound inpyproject.toml.dandi/cli/tests/test_base.py.EnumChoicefollows the approach already used for--min-severityincmd_validate.py, which builds itsChoicefrom a list of strings derived fromSeverity([i.name for i in Severity]) rather than from enum members, and is therefore unaffected by the click 8.2 change.EnumChoicegeneralizes that into a reusable type that is value-based and returns the enum member, which the upload, download, organize, and move callbacks expect. (NOTE: there are now two enum-to-Choice idioms in the CLI (value-basedEnumChoicefor str-enums, inline[i.name for i in …]for Severity). I kept the change minimal; happy to unify them in a follow-up if preferred.)Compatibility
--helplists the lowercase values.BaseCommand,MultiCommand, the parser module,split_arg_string,OptionParser).Testing
dandi/cli/tests/test_base.py,test_command.py,test_move.py, and the localorganizechoice mode tests pass on click 8.4.2; the new tests also pass on click 8.1.8.black,isort,flake8, andmypypass on all changed files.upload,download,organize, andmove--helpshows lowercase value choices;--existing skipresolves to the enum member and--existing SKIPis rejected as before.