click-contrib / click_params Goto Github PK
View Code? Open in Web Editor NEWBunch of click parameters to use
License: Apache License 2.0
Bunch of click parameters to use
License: Apache License 2.0
Hi, what is the procedure for updating the conda-forge recipe? The latest version is not available there.
When ListParamType
try to convert an empty string it creates a list with one empty item.
The more logical use case is that empty string should be converted to an empty list.
import click
import click_params
my_list = click.prompt(
"Strings list",
default="",
type=click_params.StringListParamType(),
show_default=False,
)
print(my_list)
Output:
Strings list:
['']
I would like to suggest a boolean parameter for ListParamType
called ignore_empty
that will do just that, handle empty string as empty list. This parameter will be false by default in order to keep backward compatibility.
In the example above, the code will be changed to:
my_list = click.prompt(
"Strings list",
default="",
type=click_params.StringListParamType(ignore_empty=True),
show_default=False,
)
print(my_list)
And the output will be:
Strings list:
[]
On December 23rd 2021 Python 3.6 has reach its End-of-Life date.
Therefore click-params should no longer support that version.
Hi, can you please add support for Click 8.x?
This is maybe already supported, but the https://github.com/click-contrib/click_params/blob/master/pyproject.toml#L29 points to only 7.x.
Thank you
Dear all, dear @lewoudar ,
this issue is meant to show some issue that we ran into within our test suite for wetterdienst at [1].
The test suite also tests our click based cli, which also leverages click_params StringListParamType
at multiple points. We noticed that when running the cli with multiple pytest parametrized arguments, the first run/test may succeed but the second/third/... run would fail. This is because the cli is instantiated once and then uses the same instance of StringListParamType
. There however at
click_params/click_params/base.py
Lines 114 to 129 in daf87d9
This should not effect the cli in running environment because there we only call the cli once, the cli is instantiated and afterwards it is shut down. However in the testing environment this may not be the case as multiple args could be tested against the same cli option/argument.
An example PR #23 (that atm fails as the current behaviour of StringListParamType is not adapted) shows this issue quite well.
We propose the following change for the above shown attribute:
def convert(self, value, param, ctx):
if isinstance(value, list):
return value
if self._ignore_empty and value == "":
return []
value = self._strip_separator(value)
errors, converted_list = self._convert_expression_to_list(value)
if errors:
self.fail(self._error_message.format(errors=errors), param, ctx)
return converted_list
isinstance
would recognize if instead of a string a list would be passedPlease let us know what you think about this adaption!
Sincerely,
Benjamin
/CC @amotl
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.