@@ -41,16 +41,16 @@ Running `python square.py --num 2` will print `The square of your number is 4.0.
4141
4242Tap requires Python 3.10+
4343
44- To install Tap from PyPI run:
44+ To install Tap from PyPI run:
4545
46- ```
46+ ``` shell
4747pip install typed-argument-parser
4848```
4949
5050<details >
5151<summary >To install Tap from source, run the following commands:</summary >
5252
53- ```
53+ ``` shell
5454git clone https://github.com/swansonk14/typed-argument-parser.git
5555cd typed-argument-parser
5656pip install -e .
@@ -61,51 +61,69 @@ pip install -e .
6161<details >
6262<summary >To develop this package, install development requirements (in a virtual environment):</summary >
6363
64- ```
64+ ``` shell
6565python -m pip install -e " .[dev]"
6666```
6767
6868Use [ ` flake8 ` ] ( https://github.com/PyCQA/flake8 ) linting.
6969
7070To run tests, run:
7171
72- ```
72+ ``` shell
7373pytest
7474```
7575
7676</details >
7777
7878## Table of Contents
7979
80- * [ Installation] ( #installation )
81- * [ Table of Contents] ( #table-of-contents )
82- * [ Tap is Python-native] ( #tap-is-python-native )
83- * [ Tap features] ( #tap-features )
84- + [ Arguments] ( #arguments )
85- + [ Tap help] ( #tap-help )
86- + [ Configuring arguments] ( #configuring-arguments )
87- - [ Adding special argument behavior] ( #adding-special-argument-behavior )
88- - [ Adding subparsers] ( #adding-subparsers )
89- + [ Types] ( #types )
90- + [ Argument processing] ( #argument-processing )
91- + [ Processing known args] ( #processing-known-args )
92- + [ Subclassing] ( #subclassing )
93- + [ Printing] ( #printing )
94- + [ Reproducibility] ( #reproducibility )
95- + [ Saving and loading arguments] ( #saving-and-loading-arguments )
96- + [ Loading from configuration files] ( #loading-from-configuration-files )
97- * [ tapify] ( #tapify )
98- + [ Examples] ( #examples )
99- - [ Function] ( #function )
100- - [ Class] ( #class )
101- - [ Dataclass] ( #dataclass )
102- + [ tapify help] ( #tapify-help )
103- + [ Command line vs explicit arguments] ( #command-line-vs-explicit-arguments )
104- + [ Known args] ( #known-args )
105- * [ Convert to a ` Tap ` class] ( #convert-to-a-tap-class )
106- + [ ` to_tap_class ` examples] ( #to_tap_class-examples )
107- - [ Simple] ( #simple )
108- - [ Complex] ( #complex )
80+ - [ Typed Argument Parser (Tap)] ( #typed-argument-parser-tap )
81+ - [ Installation] ( #installation )
82+ - [ Table of Contents] ( #table-of-contents )
83+ - [ Tap is Python-native] ( #tap-is-python-native )
84+ - [ Tap features] ( #tap-features )
85+ - [ Arguments] ( #arguments )
86+ - [ Tap help] ( #tap-help )
87+ - [ Configuring arguments] ( #configuring-arguments )
88+ - [ Adding special argument behavior] ( #adding-special-argument-behavior )
89+ - [ Adding subparsers] ( #adding-subparsers )
90+ - [ Types] ( #types )
91+ - [ ` str ` , ` int ` , and ` float ` ] ( #str-int-and-float )
92+ - [ ` bool ` ] ( #bool )
93+ - [ ` Optional ` ] ( #optional )
94+ - [ ` List ` ] ( #list )
95+ - [ ` Set ` ] ( #set )
96+ - [ ` Tuple ` ] ( #tuple )
97+ - [ ` Literal ` ] ( #literal )
98+ - [ ` Union ` ] ( #union )
99+ - [ Complex Types] ( #complex-types )
100+ - [ Ignore Attribute] ( #ignore-attribute )
101+ - [ Argument processing] ( #argument-processing )
102+ - [ Processing known args] ( #processing-known-args )
103+ - [ Subclassing] ( #subclassing )
104+ - [ Printing] ( #printing )
105+ - [ Reproducibility] ( #reproducibility )
106+ - [ Reproducibility info] ( #reproducibility-info )
107+ - [ Conversion Tap to and from dictionaries] ( #conversion-tap-to-and-from-dictionaries )
108+ - [ Saving and loading arguments] ( #saving-and-loading-arguments )
109+ - [ Save] ( #save )
110+ - [ Load] ( #load )
111+ - [ Load from dict] ( #load-from-dict )
112+ - [ Loading from configuration files] ( #loading-from-configuration-files )
113+ - [ tapify] ( #tapify )
114+ - [ Examples] ( #examples )
115+ - [ Function] ( #function )
116+ - [ Class] ( #class )
117+ - [ Dataclass] ( #dataclass )
118+ - [ Pydantic] ( #pydantic )
119+ - [ tapify help] ( #tapify-help )
120+ - [ Command line vs explicit arguments] ( #command-line-vs-explicit-arguments )
121+ - [ Known args] ( #known-args )
122+ - [ Explicit boolean arguments] ( #explicit-boolean-arguments )
123+ - [ Convert to a ` Tap ` class] ( #convert-to-a-tap-class )
124+ - [ ` to_tap_class ` examples] ( #to_tap_class-examples )
125+ - [ Simple] ( #simple )
126+ - [ Complex] ( #complex )
109127
110128## Tap is Python-native
111129
@@ -361,6 +379,33 @@ args = Args().parse_args('--aged_person Tapper,27'.split())
361379print (f ' { args.aged_person.name} is { args.aged_person.age} ' ) # Tapper is 27
362380```
363381
382+ ### Ignore Attribute
383+
384+ Sometimes you may want to define attributes that should not be parsed as command line arguments, but you still want to type them.
385+ This can be achieved by using ` TapIgnore ` .
386+
387+ ``` python
388+ from tap import Tap, TapIgnore
389+
390+ class MyTap (Tap ):
391+ # Regular arguments (will be parsed)
392+ package: str
393+ stars: int = 5
394+
395+ # Ignored attributes (will not be parsed)
396+ internal_counter: TapIgnore[int ] = 0
397+
398+ args = MyTap().parse_args([" --help" ])
399+ ```
400+
401+ ``` txt
402+ usage: ipython --package PACKAGE [--stars STARS] [-h]
403+
404+ options:
405+ --package PACKAGE (str, required)
406+ --stars STARS (int, default=5)
407+ -h, --help show this help message and exit
408+ ```
364409
365410### Argument processing
366411
@@ -863,7 +908,7 @@ Running `python person.py --name Jesse --age 1` prints `My name is Jesse.` follo
863908
864909### Explicit boolean arguments
865910
866- Tapify supports explicit specification of boolean arguments (see [ bool] ( #bool ) for more details). By default, ` explicit_bool=False ` and it can be set with ` tapify(..., explicit_bool=True) ` .
911+ Tapify supports explicit specification of boolean arguments (see [ bool] ( #bool ) for more details). By default, ` explicit_bool=False ` and it can be set with ` tapify(..., explicit_bool=True) ` .
867912
868913## Convert to a ` Tap ` class
869914
@@ -903,7 +948,7 @@ if __name__ == "__main__":
903948
904949Running ` python main.py --package tap ` will print ` Project instance: package='tap' is_cool=True stars=5 ` .
905950
906- ### Complex
951+ #### Complex
907952
908953The general pattern is:
909954
0 commit comments