Skip to content

Conversation

@joshuastorck
Copy link

Fixes #1264

@jcrotts
Copy link
Contributor

jcrotts commented May 31, 2019

Could you add an entry to the changelog for this, and it might be good to add a note to the docs about the change.

@joshuastorck
Copy link
Author

What section would you recommend that I add the docs to?

@jcrotts
Copy link
Contributor

jcrotts commented Jun 1, 2019

Good question, I think it makes sense to add a section to https://click.palletsprojects.com/en/7.x/parameters/ since your change applies to everything that inherits from BaseCommand.

@joshuastorck
Copy link
Author

joshuastorck commented Jun 1, 2019

Maybe it makes more sense to put it in the advanced.rst file? The parameters.rst file is pretty small and the concepts around contexts, environment variables and default values are in the options.rst, arguments.rst, and commands.rst files, which come after the parameters.rst file in the documentation.

@jcrotts
Copy link
Contributor

jcrotts commented Jun 1, 2019

That sounds good to me, it is a little to specific to go into the parameters section.

…_MAP as a source and added unit tests for it.
@joshuastorck
Copy link
Author

@jcrotts, docs have been added and tests are passing. Please let me know if there are any other changes you want.

Copy link
Contributor

@jab jab left a comment

Choose a reason for hiding this comment

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

Awesome @joshuastorck, I've been wanting this – thanks for submitting! A few suggestions – what do you think? Psyched to get this landed!


return sorted(declaration_order, key=sort_key)

class ParameterSource(object):
Copy link
Contributor

@jab jab Jun 1, 2019

Choose a reason for hiding this comment

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

nit: Should this be named OptionSource? Positional arguments can't be set via the environment, can't have default values, etc. so this is only relevant for options. I think this was the intention since the docstring says "indicates the source of a command line option" already. https://click.palletsprojects.com/en/7.x/parameters/#differences

Copy link
Author

Choose a reason for hiding this comment

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

https://click.palletsprojects.com/en/7.x/arguments/#environment-variables states that arguments can be set via the environment, will change the docs to parameter from option.

Copy link
Contributor

Choose a reason for hiding this comment

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

@joshuastorck Sounds like the docs are incorrect then? https://click.palletsprojects.com/en/7.x/parameters/#differences says "The following features are only available for options: ... option values can be pulled from environment variables, arguments can not". If so then I agree it makes sense to leave this named ParameterSource but I wonder if it's worth at least a comment mentioning that the source of an argument can never be e.g. DEFAULT, if not actually asserting that in the validate logic?

Joshua Storck added 4 commits June 2, 2019 08:31
…tead of 'option'. Removed emphasis of the word source in Context.get_parameter_source. Changed ParameterSource.VALUE to a set instead of list. Fixed bugs in ParameterSource.validate and added unit test for it. Changed Context.get_parameter_source to return a KeyError when an invalid parameter name is specified.
@joshuastorck
Copy link
Author

@jab, I think I've addressed all of your comments. Please take another look.

Copy link
Contributor

@jab jab left a comment

Choose a reason for hiding this comment

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

Thanks @joshuastorck, looking great, just a couple last things and then I think this should be ready to merge!


return sorted(declaration_order, key=sort_key)

class ParameterSource(object):
Copy link
Contributor

Choose a reason for hiding this comment

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

@joshuastorck Sounds like the docs are incorrect then? https://click.palletsprojects.com/en/7.x/parameters/#differences says "The following features are only available for options: ... option values can be pulled from environment variables, arguments can not". If so then I agree it makes sense to leave this named ParameterSource but I wonder if it's worth at least a comment mentioning that the source of an argument can never be e.g. DEFAULT, if not actually asserting that in the validate logic?

… value. Changing Context._sources_by_paramname to Context._source_by_paramname. Renaming ParameterSource.validate clz arg to cls and removing doc for that argument in the docstring
Copy link
Contributor

@jab jab left a comment

Choose a reason for hiding this comment

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

💯

@davidism davidism added this to the 8.0 milestone Jun 3, 2019
@davidism
Copy link
Member

davidism commented Jun 3, 2019

Looks good, thanks!

@davidism davidism merged commit 91e5bc3 into pallets:master Jun 3, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Differentiate defaults from explicitly passed values

4 participants