argparse-dantic 0.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. argparse_dantic-0.0.0/LICENSE +21 -0
  2. argparse_dantic-0.0.0/PKG-INFO +167 -0
  3. argparse_dantic-0.0.0/README.md +141 -0
  4. argparse_dantic-0.0.0/argparse_dantic/__init__.py +20 -0
  5. argparse_dantic-0.0.0/argparse_dantic/_argparse/__init__.py +3 -0
  6. argparse_dantic-0.0.0/argparse_dantic/_argparse/actions.py +768 -0
  7. argparse_dantic-0.0.0/argparse_dantic/_argparse/container.py +399 -0
  8. argparse_dantic-0.0.0/argparse_dantic/_argparse/help.py +511 -0
  9. argparse_dantic-0.0.0/argparse_dantic/_argparse/parser.py +1226 -0
  10. argparse_dantic-0.0.0/argparse_dantic/dantic_types/__init__.py +13 -0
  11. argparse_dantic-0.0.0/argparse_dantic/dantic_types/_construct.py +718 -0
  12. argparse_dantic-0.0.0/argparse_dantic/dantic_types/_fields.py +465 -0
  13. argparse_dantic-0.0.0/argparse_dantic/dantic_types/_import_utils.py +11 -0
  14. argparse_dantic-0.0.0/argparse_dantic/dantic_types/fields.py +437 -0
  15. argparse_dantic-0.0.0/argparse_dantic/dantic_types/main.py +91 -0
  16. argparse_dantic-0.0.0/argparse_dantic/parsers/__init__.py +16 -0
  17. argparse_dantic-0.0.0/argparse_dantic/parsers/boolean.py +68 -0
  18. argparse_dantic-0.0.0/argparse_dantic/parsers/command.py +61 -0
  19. argparse_dantic-0.0.0/argparse_dantic/parsers/container.py +64 -0
  20. argparse_dantic-0.0.0/argparse_dantic/parsers/enum.py +71 -0
  21. argparse_dantic-0.0.0/argparse_dantic/parsers/literal.py +73 -0
  22. argparse_dantic-0.0.0/argparse_dantic/parsers/mapping.py +59 -0
  23. argparse_dantic-0.0.0/argparse_dantic/parsers/standard.py +45 -0
  24. argparse_dantic-0.0.0/argparse_dantic/utils/__init__.py +25 -0
  25. argparse_dantic-0.0.0/argparse_dantic/utils/arguments.py +65 -0
  26. argparse_dantic-0.0.0/argparse_dantic/utils/errors.py +25 -0
  27. argparse_dantic-0.0.0/argparse_dantic/utils/namespaces.py +31 -0
  28. argparse_dantic-0.0.0/argparse_dantic/utils/pydantic.py +134 -0
  29. argparse_dantic-0.0.0/argparse_dantic/utils/types.py +60 -0
  30. argparse_dantic-0.0.0/argparse_dantic.egg-info/PKG-INFO +167 -0
  31. argparse_dantic-0.0.0/argparse_dantic.egg-info/SOURCES.txt +34 -0
  32. argparse_dantic-0.0.0/argparse_dantic.egg-info/dependency_links.txt +1 -0
  33. argparse_dantic-0.0.0/argparse_dantic.egg-info/requires.txt +2 -0
  34. argparse_dantic-0.0.0/argparse_dantic.egg-info/top_level.txt +1 -0
  35. argparse_dantic-0.0.0/pyproject.toml +37 -0
  36. argparse_dantic-0.0.0/setup.cfg +4 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Hayden Richards
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,167 @@
1
+ Metadata-Version: 2.4
2
+ Name: argparse-dantic
3
+ Version: 0.0.0
4
+ Summary: Typed Argument Parsing with Pydantic enhanced version
5
+ Author-email: Erlone Alpha <zhongerlong@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Changelog, https://github.com/Erlonealpha/argparse-dantic/blob/master/CHANGELOG.md
8
+ Project-URL: Repository, https://github.com/Erlonealpha/argparse-dantic
9
+ Project-URL: Issues, https://github.com/Erlonealpha/argparse-dantic/issues
10
+ Keywords: python,pydantic,argparse,typed,validation
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Programming Language :: Python
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Intended Audience :: Developers
18
+ Classifier: Framework :: Pydantic
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Requires-Python: >=3.10
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: pydantic>=2.10.0
24
+ Requires-Dist: rich>=12.0.0
25
+ Dynamic: license-file
26
+
27
+ <div align="center">
28
+ <!-- Logo -->
29
+ <a href="https://pydantic-argparse.supimdos.com"><img src="https://raw.githubusercontent.com/SupImDos/pydantic-argparse/master/docs/assets/images/logo.svg" width="50%"></a>
30
+ <!-- Headings -->
31
+ <h1>Argparse Dantic</h1>
32
+ <p><em>Typed Argument Parsing with Pydantic Enhanced</em></p>
33
+ <!-- Badges (Row 1) -->
34
+ <a href="https://pypi.python.org/pypi/argparse-dantic"><img src="https://img.shields.io/pypi/v/pydantic-argparse"></a>
35
+ <a href="https://pepy.tech/project/pydantic-argparse"><img src="https://img.shields.io/pepy/dt/pydantic-argparse?color=blue"></a>
36
+ <a href="https://github.com/SupImDos/pydantic-argparse/blob/master/LICENSE"><img src="https://img.shields.io/github/license/SupImDos/pydantic-argparse"></a>
37
+ <br>
38
+ </div>
39
+
40
+ ## Help
41
+ See [documentation](https://pydantic-argparse.supimdos.com) for help.
42
+
43
+ ## Requirements
44
+ Requires Python 3.8+, and is compatible with the Pydantic v1 API.
45
+
46
+ ## Installation
47
+ Installation with `pip` is simple:
48
+ ```console
49
+ $ pip install argparse-dantic
50
+ ```
51
+
52
+ ## Example
53
+ ```py
54
+ from argparse_dantic import ArgumentParser, BaseModel, Field
55
+
56
+
57
+ class Arguments(BaseModel):
58
+ # Required Args
59
+ string: str = Field(description="a required string", aliases=["-s"])
60
+ integer: int = Field(description="a required integer", aliases=["-i"])
61
+ flag: bool = Field(description="a required flag", aliases=["-f"])
62
+
63
+ # Optional Args
64
+ second_flag: bool = Field(False, description="an optional flag")
65
+ third_flag: bool = Field(True, description="an optional flag")
66
+
67
+
68
+ def main() -> None:
69
+ # Create Parser and Parse Args
70
+ parser = ArgumentParser(
71
+ model=Arguments,
72
+ prog="Example Program",
73
+ description="Example Description",
74
+ version="0.0.1",
75
+ epilog="Example Epilog",
76
+ )
77
+ args = parser.parse_typed_args()
78
+
79
+ # Print Args
80
+ print(args)
81
+
82
+
83
+ if __name__ == "__main__":
84
+ main()
85
+ ```
86
+
87
+ ```console
88
+ $ python3 example.py --help
89
+ usage: Example Program [-h] [-v] [-s STRING] [-i INTEGER] [-f | --flag | --no-flag]
90
+ [--second-flag] [--no-third-flag]
91
+
92
+ Example Description
93
+
94
+ required arguments:
95
+ -s STRING, --string STRING
96
+ a required string
97
+ -i INTEGER, --integer INTEGER
98
+ a required integer
99
+ -f, --flag, --no-flag
100
+ a required flag
101
+
102
+ optional arguments:
103
+ --second-flag an optional flag (default: False)
104
+ --no-third-flag an optional flag (default: True)
105
+
106
+ help:
107
+ -h, --help show this help message and exit
108
+ -v, --version show program's version number and exit
109
+
110
+ Example Epilog
111
+ ```
112
+
113
+ ```console
114
+ $ python3 example.py --string hello -i 42 -f
115
+ string='hello' integer=42 flag=True second_flag=False third_flag=True
116
+ ```
117
+
118
+ ## Advanced Example
119
+ ```py
120
+ from argparse_dantic import ArgumentParser, BaseModel, Field, ActionNameBind
121
+
122
+ class GlobalModel(BaseModel):
123
+ action_name: ActionNameBind # This is a special field that binds the action name to the model
124
+ verbose: bool = Field(False, description="verbose output", global_=True)
125
+ debug: bool = Field(False, description="debug output", global_=True)
126
+
127
+ class PubOptionsModel(BaseModel):
128
+ target: str = Field(description="build target", aliases=["-t"])
129
+ clean: bool = Field(False, description="clean build", aliases=["--c"])
130
+
131
+ class BuildCommandModel(GlobalModel, PubOptionsModel):
132
+ build_type: str = Field(description="build type", aliases=["-bt"])
133
+
134
+ class InstallCommandModel(GlobalModel, PubOptionsModel):
135
+ install_type: str = Field(description="install type", aliases=["-it"])
136
+
137
+ class BasicModel(GlobalModel):
138
+ build: BuildCommandModel = Field(aliases=["bd"], description="build command")
139
+ install: InstallCommandModel = Field(aliases=["ins"], description="install command")
140
+
141
+ def main() -> None:
142
+ # Create Parser and Parse Args
143
+ parser = ArgumentParser(
144
+ model=BasicModel,
145
+ prog="Example Program",
146
+ description="Example Description",
147
+ version="0.0.1",
148
+ epilog="Example Epilog",
149
+ )
150
+ args = parser.parse_typed_args()
151
+
152
+ # Print Args
153
+ print(args)
154
+
155
+ # Get Command Arguments Faster
156
+ command_arguments = getattr(args, args.action_name)
157
+
158
+ # Get Global Arguments Faster
159
+ verbose = args.global_data.get("verbose")
160
+ debug = args.global_data.get("debug")
161
+ # In child models you can also access global data
162
+ # verbose = command_arguments.global_data.get("verbose")
163
+ # debug = command_arguments.global_data.get("debug")
164
+ ```
165
+
166
+ ## License
167
+ This project is licensed under the terms of the MIT license.
@@ -0,0 +1,141 @@
1
+ <div align="center">
2
+ <!-- Logo -->
3
+ <a href="https://pydantic-argparse.supimdos.com"><img src="https://raw.githubusercontent.com/SupImDos/pydantic-argparse/master/docs/assets/images/logo.svg" width="50%"></a>
4
+ <!-- Headings -->
5
+ <h1>Argparse Dantic</h1>
6
+ <p><em>Typed Argument Parsing with Pydantic Enhanced</em></p>
7
+ <!-- Badges (Row 1) -->
8
+ <a href="https://pypi.python.org/pypi/argparse-dantic"><img src="https://img.shields.io/pypi/v/pydantic-argparse"></a>
9
+ <a href="https://pepy.tech/project/pydantic-argparse"><img src="https://img.shields.io/pepy/dt/pydantic-argparse?color=blue"></a>
10
+ <a href="https://github.com/SupImDos/pydantic-argparse/blob/master/LICENSE"><img src="https://img.shields.io/github/license/SupImDos/pydantic-argparse"></a>
11
+ <br>
12
+ </div>
13
+
14
+ ## Help
15
+ See [documentation](https://pydantic-argparse.supimdos.com) for help.
16
+
17
+ ## Requirements
18
+ Requires Python 3.8+, and is compatible with the Pydantic v1 API.
19
+
20
+ ## Installation
21
+ Installation with `pip` is simple:
22
+ ```console
23
+ $ pip install argparse-dantic
24
+ ```
25
+
26
+ ## Example
27
+ ```py
28
+ from argparse_dantic import ArgumentParser, BaseModel, Field
29
+
30
+
31
+ class Arguments(BaseModel):
32
+ # Required Args
33
+ string: str = Field(description="a required string", aliases=["-s"])
34
+ integer: int = Field(description="a required integer", aliases=["-i"])
35
+ flag: bool = Field(description="a required flag", aliases=["-f"])
36
+
37
+ # Optional Args
38
+ second_flag: bool = Field(False, description="an optional flag")
39
+ third_flag: bool = Field(True, description="an optional flag")
40
+
41
+
42
+ def main() -> None:
43
+ # Create Parser and Parse Args
44
+ parser = ArgumentParser(
45
+ model=Arguments,
46
+ prog="Example Program",
47
+ description="Example Description",
48
+ version="0.0.1",
49
+ epilog="Example Epilog",
50
+ )
51
+ args = parser.parse_typed_args()
52
+
53
+ # Print Args
54
+ print(args)
55
+
56
+
57
+ if __name__ == "__main__":
58
+ main()
59
+ ```
60
+
61
+ ```console
62
+ $ python3 example.py --help
63
+ usage: Example Program [-h] [-v] [-s STRING] [-i INTEGER] [-f | --flag | --no-flag]
64
+ [--second-flag] [--no-third-flag]
65
+
66
+ Example Description
67
+
68
+ required arguments:
69
+ -s STRING, --string STRING
70
+ a required string
71
+ -i INTEGER, --integer INTEGER
72
+ a required integer
73
+ -f, --flag, --no-flag
74
+ a required flag
75
+
76
+ optional arguments:
77
+ --second-flag an optional flag (default: False)
78
+ --no-third-flag an optional flag (default: True)
79
+
80
+ help:
81
+ -h, --help show this help message and exit
82
+ -v, --version show program's version number and exit
83
+
84
+ Example Epilog
85
+ ```
86
+
87
+ ```console
88
+ $ python3 example.py --string hello -i 42 -f
89
+ string='hello' integer=42 flag=True second_flag=False third_flag=True
90
+ ```
91
+
92
+ ## Advanced Example
93
+ ```py
94
+ from argparse_dantic import ArgumentParser, BaseModel, Field, ActionNameBind
95
+
96
+ class GlobalModel(BaseModel):
97
+ action_name: ActionNameBind # This is a special field that binds the action name to the model
98
+ verbose: bool = Field(False, description="verbose output", global_=True)
99
+ debug: bool = Field(False, description="debug output", global_=True)
100
+
101
+ class PubOptionsModel(BaseModel):
102
+ target: str = Field(description="build target", aliases=["-t"])
103
+ clean: bool = Field(False, description="clean build", aliases=["--c"])
104
+
105
+ class BuildCommandModel(GlobalModel, PubOptionsModel):
106
+ build_type: str = Field(description="build type", aliases=["-bt"])
107
+
108
+ class InstallCommandModel(GlobalModel, PubOptionsModel):
109
+ install_type: str = Field(description="install type", aliases=["-it"])
110
+
111
+ class BasicModel(GlobalModel):
112
+ build: BuildCommandModel = Field(aliases=["bd"], description="build command")
113
+ install: InstallCommandModel = Field(aliases=["ins"], description="install command")
114
+
115
+ def main() -> None:
116
+ # Create Parser and Parse Args
117
+ parser = ArgumentParser(
118
+ model=BasicModel,
119
+ prog="Example Program",
120
+ description="Example Description",
121
+ version="0.0.1",
122
+ epilog="Example Epilog",
123
+ )
124
+ args = parser.parse_typed_args()
125
+
126
+ # Print Args
127
+ print(args)
128
+
129
+ # Get Command Arguments Faster
130
+ command_arguments = getattr(args, args.action_name)
131
+
132
+ # Get Global Arguments Faster
133
+ verbose = args.global_data.get("verbose")
134
+ debug = args.global_data.get("debug")
135
+ # In child models you can also access global data
136
+ # verbose = command_arguments.global_data.get("verbose")
137
+ # debug = command_arguments.global_data.get("debug")
138
+ ```
139
+
140
+ ## License
141
+ This project is licensed under the terms of the MIT license.
@@ -0,0 +1,20 @@
1
+ from argparse_dantic._argparse import ArgumentParser
2
+ from argparse_dantic.dantic_types import ActionNameBind, FieldInfo, BaseModel, Field
3
+
4
+ from pydantic import (
5
+ FilePath,
6
+ DirectoryPath,
7
+ IPvAnyAddress
8
+ )
9
+
10
+ __all__ = [
11
+ "ArgumentParser",
12
+ "ActionNameBind",
13
+ "BaseModel",
14
+ "FieldInfo",
15
+ "Field",
16
+
17
+ "FilePath",
18
+ "DirectoryPath",
19
+ "IPvAnyAddress"
20
+ ]
@@ -0,0 +1,3 @@
1
+ from .parser import ArgumentParser
2
+
3
+ __all__ = ["ArgumentParser"]