-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement counter actions * ruff * Add counter test, sync docs * Special-case for Python 3.7 * Formatting
- Loading branch information
Showing
6 changed files
with
159 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
.. Comment: this file is automatically generated by `update_example_docs.py`. | ||
It should not be modified manually. | ||
Counters | ||
========================================== | ||
|
||
|
||
Repeatable 'counter' arguments can be specified via :data:`tyro.conf.UseCounterAction`. | ||
|
||
|
||
|
||
.. code-block:: python | ||
:linenos: | ||
from typing_extensions import Annotated | ||
import tyro | ||
from tyro.conf import UseCounterAction | ||
def main( | ||
verbosity: UseCounterAction[int], | ||
aliased_verbosity: Annotated[UseCounterAction[int], tyro.conf.arg(aliases=["-v"])], | ||
) -> None: | ||
"""Example showing how to use counter actions. | ||
Args: | ||
verbosity: Verbosity level. | ||
aliased_verbosity: Same as above, but can also be specified with -v, -vv, -vvv, etc. | ||
""" | ||
print("Verbosity level:", verbosity) | ||
print("Verbosity level (aliased):", aliased_verbosity) | ||
if __name__ == "__main__": | ||
tyro.cli(main) | ||
------------ | ||
|
||
.. raw:: html | ||
|
||
<kbd>python 04_additional/12_counters.py --help</kbd> | ||
|
||
.. program-output:: python ../../examples/04_additional/12_counters.py --help | ||
|
||
------------ | ||
|
||
.. raw:: html | ||
|
||
<kbd>python 04_additional/12_counters.py --verbosity</kbd> | ||
|
||
.. program-output:: python ../../examples/04_additional/12_counters.py --verbosity | ||
|
||
------------ | ||
|
||
.. raw:: html | ||
|
||
<kbd>python 04_additional/12_counters.py --verbosity --verbosity</kbd> | ||
|
||
.. program-output:: python ../../examples/04_additional/12_counters.py --verbosity --verbosity | ||
|
||
------------ | ||
|
||
.. raw:: html | ||
|
||
<kbd>python 04_additional/12_counters.py -vvv</kbd> | ||
|
||
.. program-output:: python ../../examples/04_additional/12_counters.py -vvv |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""Counters | ||
Repeatable 'counter' arguments can be specified via :data:`tyro.conf.UseCounterAction`. | ||
Usage: | ||
`python ./12_counters.py --help` | ||
`python ./12_counters.py --verbosity` | ||
`python ./12_counters.py --verbosity --verbosity` | ||
`python ./12_counters.py -vvv` | ||
""" | ||
|
||
from typing_extensions import Annotated | ||
|
||
import tyro | ||
from tyro.conf import UseCounterAction | ||
|
||
|
||
def main( | ||
verbosity: UseCounterAction[int], | ||
aliased_verbosity: Annotated[UseCounterAction[int], tyro.conf.arg(aliases=["-v"])], | ||
) -> None: | ||
"""Example showing how to use counter actions. | ||
Args: | ||
verbosity: Verbosity level. | ||
aliased_verbosity: Same as above, but can also be specified with -v, -vv, -vvv, etc. | ||
""" | ||
print("Verbosity level:", verbosity) | ||
print("Verbosity level (aliased):", aliased_verbosity) | ||
|
||
|
||
if __name__ == "__main__": | ||
tyro.cli(main) |
This file contains 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
This file contains 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
This file contains 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
This file contains 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