Hi, With the new-style click-based dev.py, what is the way to spell a command-line argument which counts, e.g. the usual way of increasing the verbosity via `-v`, `-vv`, `-vvv` etc? IOW, what would be an analog of argparse's parser.add_argument('-v', '--verbose', action='count', default=0, help='print verbose (`-v`) or very verbose (`-vv`) ' ? For context, I'm plumbing the argparse-based helper script CLI through dev.py in https://github.com/scipy/scipy/pull/16391, the relevant head-scratcher is at https://github.com/scipy/scipy/pull/16391/files#diff-e42998d51257e6f84aa51ff... Searching around seems to suggest that the right click incantation is verbose = Option(['--verbose', '-v'], count=True, default=0, help="verbosity") But actually trying it in gh-16391 leads to $ python dev.py doctest -s linalg -v Traceback (most recent call last): File "dev.py", line 985, in <module> class Doctest(Task): File "/home/br/.virtualenvs/scipy-dev/lib/python3.8/site-packages/pydevtool/cli.py", line 184, in __new__ params.append(param_click2doit(attr_name, val)) File "/home/br/.virtualenvs/scipy-dev/lib/python3.8/site-packages/pydevtool/cli.py", line 140, in param_click2doit 'type': param_type_map[val.type.name], # FIXME: add all types KeyError: 'integer range' Help, suggestions or pointers would be much appreciated. Evgeni
Hi Evgeni, I have no experience with this library but it seems in dev.py 'verbose' translate to adding -vvv to cmd so is there a need for a counter based approach ? I have checked out your branch and tried the following in Doctest which worked (although it is not count based): verbose = Option( ['--verbose', '-v'], default=False, is_flag=True, help="verbosity") It's probably the first thing you tried though, sorry for being of little help. Kind regards, Arnaud Le dim. 26 juin 2022 à 19:04, Evgeni Burovski <evgeny.burovskiy@gmail.com> a écrit :
Hi,
With the new-style click-based dev.py, what is the way to spell a command-line argument which counts, e.g. the usual way of increasing the verbosity via `-v`, `-vv`, `-vvv` etc? IOW, what would be an analog of argparse's
parser.add_argument('-v', '--verbose', action='count', default=0, help='print verbose (`-v`) or very verbose (`-vv`) '
?
For context, I'm plumbing the argparse-based helper script CLI through dev.py in https://github.com/scipy/scipy/pull/16391, the relevant head-scratcher is at
https://github.com/scipy/scipy/pull/16391/files#diff-e42998d51257e6f84aa51ff...
Searching around seems to suggest that the right click incantation is
verbose = Option(['--verbose', '-v'], count=True, default=0, help="verbosity")
But actually trying it in gh-16391 leads to
$ python dev.py doctest -s linalg -v Traceback (most recent call last): File "dev.py", line 985, in <module> class Doctest(Task): File "/home/br/.virtualenvs/scipy-dev/lib/python3.8/site-packages/pydevtool/cli.py", line 184, in __new__ params.append(param_click2doit(attr_name, val)) File "/home/br/.virtualenvs/scipy-dev/lib/python3.8/site-packages/pydevtool/cli.py", line 140, in param_click2doit 'type': param_type_map[val.type.name], # FIXME: add all types KeyError: 'integer range'
Help, suggestions or pointers would be much appreciated.
Evgeni _______________________________________________ SciPy-Dev mailing list -- scipy-dev@python.org To unsubscribe send an email to scipy-dev-leave@python.org https://mail.python.org/mailman3/lists/scipy-dev.python.org/ Member address: arnaud.baguet@gmail.com
Does this help? https://click.palletsprojects.com/en/8.1.x/options/#counting It seems the list isn’t needed, *args is parsed directly. Best regards, Hameer Abbasi Von meinem iPhone gesendet
Am 27.06.2022 um 01:02 schrieb Evgeni Burovski <evgeny.burovskiy@gmail.com>:
Hi,
With the new-style click-based dev.py, what is the way to spell a command-line argument which counts, e.g. the usual way of increasing the verbosity via `-v`, `-vv`, `-vvv` etc? IOW, what would be an analog of argparse's
parser.add_argument('-v', '--verbose', action='count', default=0, help='print verbose (`-v`) or very verbose (`-vv`) '
?
For context, I'm plumbing the argparse-based helper script CLI through dev.py in https://github.com/scipy/scipy/pull/16391, the relevant head-scratcher is at https://github.com/scipy/scipy/pull/16391/files#diff-e42998d51257e6f84aa51ff...
Searching around seems to suggest that the right click incantation is
verbose = Option(['--verbose', '-v'], count=True, default=0, help="verbosity")
But actually trying it in gh-16391 leads to
$ python dev.py doctest -s linalg -v Traceback (most recent call last): File "dev.py", line 985, in <module> class Doctest(Task): File "/home/br/.virtualenvs/scipy-dev/lib/python3.8/site-packages/pydevtool/cli.py", line 184, in __new__ params.append(param_click2doit(attr_name, val)) File "/home/br/.virtualenvs/scipy-dev/lib/python3.8/site-packages/pydevtool/cli.py", line 140, in param_click2doit 'type': param_type_map[val.type.name], # FIXME: add all types KeyError: 'integer range'
Help, suggestions or pointers would be much appreciated.
Evgeni _______________________________________________ SciPy-Dev mailing list -- scipy-dev@python.org To unsubscribe send an email to scipy-dev-leave@python.org https://mail.python.org/mailman3/lists/scipy-dev.python.org/ Member address: einstein.edison@gmail.com
Thanks Hameer, that's exactly where the OP spelling, `Option(['--verbose', '-v'], count=True, default=0, help="verbosity")` came from. But then it fails somewhere in the bowels of something called `pydevtool/cli.py` with the traceback line which has a FIXME comment. Any idea about that? Evgeni P.S. Incidentally, it might be that I'm misusing the thing on a more fundamental level. Somehow when I'm trying to add a new Task with a cmdline argument, https://github.com/scipy/scipy/pull/16391/files#diff-e42998d51257e6f84aa51ff..., dev.py fails for a *different* task: https://github.com/scipy/scipy/runs/7070762014?check_suite_focus=true Basically, I'm trying to add $ python dev.py doctest -t path/to/file the "doctest" Task depends on the Build task. When the project is already built, it works. On a fresh build, e.g. on the CI, $ python dev.py build fails with the error saying that the Build task does not have the -t Option. Indeed, it shouldn't have, that Option is for a different task! On Mon, Jun 27, 2022 at 1:27 PM <einstein.edison@gmail.com> wrote:
Does this help?
https://click.palletsprojects.com/en/8.1.x/options/#counting
It seems the list isn’t needed, *args is parsed directly.
Best regards, Hameer Abbasi Von meinem iPhone gesendet
Am 27.06.2022 um 01:02 schrieb Evgeni Burovski <evgeny.burovskiy@gmail.com>:
Hi,
With the new-style click-based dev.py, what is the way to spell a command-line argument which counts, e.g. the usual way of increasing the verbosity via `-v`, `-vv`, `-vvv` etc? IOW, what would be an analog of argparse's
parser.add_argument('-v', '--verbose', action='count', default=0, help='print verbose (`-v`) or very verbose (`-vv`) '
?
For context, I'm plumbing the argparse-based helper script CLI through dev.py in https://github.com/scipy/scipy/pull/16391, the relevant head-scratcher is at https://github.com/scipy/scipy/pull/16391/files#diff-e42998d51257e6f84aa51ff...
Searching around seems to suggest that the right click incantation is
verbose = Option(['--verbose', '-v'], count=True, default=0, help="verbosity")
But actually trying it in gh-16391 leads to
$ python dev.py doctest -s linalg -v Traceback (most recent call last): File "dev.py", line 985, in <module> class Doctest(Task): File "/home/br/.virtualenvs/scipy-dev/lib/python3.8/site-packages/pydevtool/cli.py", line 184, in __new__ params.append(param_click2doit(attr_name, val)) File "/home/br/.virtualenvs/scipy-dev/lib/python3.8/site-packages/pydevtool/cli.py", line 140, in param_click2doit 'type': param_type_map[val.type.name], # FIXME: add all types KeyError: 'integer range'
Help, suggestions or pointers would be much appreciated.
Evgeni _______________________________________________ SciPy-Dev mailing list -- scipy-dev@python.org To unsubscribe send an email to scipy-dev-leave@python.org https://mail.python.org/mailman3/lists/scipy-dev.python.org/ Member address: einstein.edison@gmail.com
_______________________________________________ SciPy-Dev mailing list -- scipy-dev@python.org To unsubscribe send an email to scipy-dev-leave@python.org https://mail.python.org/mailman3/lists/scipy-dev.python.org/ Member address: evgeny.burovskiy@gmail.com
On 26/06/2022 23:09, Evgeni Burovski wrote:
Hi,
With the new-style click-based dev.py, what is the way to spell a command-line argument which counts, e.g. the usual way of increasing the verbosity via `-v`, `-vv`, `-vvv` etc? IOW, what would be an analog of argparse's
parser.add_argument('-v', '--verbose', action='count', default=0, help='print verbose (`-v`) or very verbose (`-vv`) '
?
For context, I'm plumbing the argparse-based helper script CLI through dev.py in https://github.com/scipy/scipy/pull/16391, the relevant head-scratcher is at https://github.com/scipy/scipy/pull/16391/files#diff-e42998d51257e6f84aa51ff...
Searching around seems to suggest that the right click incantation is
verbose = Option(['--verbose', '-v'], count=True, default=0, help="verbosity")
But actually trying it in gh-16391 leads to
$ python dev.py doctest -s linalg -v Traceback (most recent call last): File "dev.py", line 985, in <module> class Doctest(Task): File "/home/br/.virtualenvs/scipy-dev/lib/python3.8/site-packages/pydevtool/cli.py", line 184, in __new__ params.append(param_click2doit(attr_name, val)) File "/home/br/.virtualenvs/scipy-dev/lib/python3.8/site-packages/pydevtool/cli.py", line 140, in param_click2doit 'type': param_type_map[val.type.name], # FIXME: add all types KeyError: 'integer range'
This looks like a bug in pydevtool. This works just fine: import click @click.command() def log(verbose): click.echo(f"Verbosity: {verbose}") log.params.append(click.Option(['-v', '--verbose'], count=True, help='Increase verbosity.')) if __name__ == '__main__': log() As a possible work around, try specifying type=int to the Option constructor. Cheers, Dan
participants (4)
-
Arnaud Baguet -
Daniele Nicolodi -
einstein.edison@gmail.com -
Evgeni Burovski