fun-args 0.0.1__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.
- fun_args-0.0.1/PKG-INFO +36 -0
- fun_args-0.0.1/README.md +28 -0
- fun_args-0.0.1/fun_args/__init__.py +1 -0
- fun_args-0.0.1/fun_args/main.py +59 -0
- fun_args-0.0.1/fun_args.egg-info/PKG-INFO +36 -0
- fun_args-0.0.1/fun_args.egg-info/SOURCES.txt +8 -0
- fun_args-0.0.1/fun_args.egg-info/dependency_links.txt +1 -0
- fun_args-0.0.1/fun_args.egg-info/top_level.txt +1 -0
- fun_args-0.0.1/pyproject.toml +14 -0
- fun_args-0.0.1/setup.cfg +4 -0
fun_args-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fun-args
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Tiny CLI argument parser inspired by Typer
|
|
5
|
+
Author-email: Maxim Grivennyy <maximgriven@gmail.com>
|
|
6
|
+
Requires-Python: >=3.11
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
|
|
9
|
+
# Fun Args Package
|
|
10
|
+
|
|
11
|
+
Simple argument passing library inspired by Typer
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
# Your main with explicitly defined parameters
|
|
15
|
+
def main(name: str, age: int = 25, smart = False):
|
|
16
|
+
print(f"Hi, {name}")
|
|
17
|
+
|
|
18
|
+
# Don't forget to call my function
|
|
19
|
+
argumentize(main)
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Now you in your terminal you can run:
|
|
23
|
+
`python filename.py --name Max --age 22`
|
|
24
|
+
|
|
25
|
+
Supports both flagged and ordered parameters. E.g.
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
def main(a, b):
|
|
29
|
+
print(a + b)
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
You could run in with
|
|
34
|
+
`python filename.py 2 7`
|
|
35
|
+
|
|
36
|
+
And get 27, because by default everything's converted to strings
|
fun_args-0.0.1/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Fun Args Package
|
|
2
|
+
|
|
3
|
+
Simple argument passing library inspired by Typer
|
|
4
|
+
|
|
5
|
+
```python
|
|
6
|
+
# Your main with explicitly defined parameters
|
|
7
|
+
def main(name: str, age: int = 25, smart = False):
|
|
8
|
+
print(f"Hi, {name}")
|
|
9
|
+
|
|
10
|
+
# Don't forget to call my function
|
|
11
|
+
argumentize(main)
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Now you in your terminal you can run:
|
|
15
|
+
`python filename.py --name Max --age 22`
|
|
16
|
+
|
|
17
|
+
Supports both flagged and ordered parameters. E.g.
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
def main(a, b):
|
|
21
|
+
print(a + b)
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
You could run in with
|
|
26
|
+
`python filename.py 2 7`
|
|
27
|
+
|
|
28
|
+
And get 27, because by default everything's converted to strings
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .main import argumentize
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import inspect
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def convert(value, to_type):
|
|
6
|
+
try:
|
|
7
|
+
if to_type == bool:
|
|
8
|
+
return True
|
|
9
|
+
if to_type == int:
|
|
10
|
+
return int(value)
|
|
11
|
+
if to_type == float:
|
|
12
|
+
return float(value)
|
|
13
|
+
return value
|
|
14
|
+
except ValueError:
|
|
15
|
+
print(f"Invalid value: {value} for type: {to_type}")
|
|
16
|
+
return None
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def argumentize(main):
|
|
20
|
+
sig = inspect.signature(main)
|
|
21
|
+
params = list(sig.parameters.values())
|
|
22
|
+
|
|
23
|
+
argv = sys.argv[1:]
|
|
24
|
+
parsed = {}
|
|
25
|
+
positionals = []
|
|
26
|
+
|
|
27
|
+
i = 0
|
|
28
|
+
while i < len(argv):
|
|
29
|
+
arg = argv[i]
|
|
30
|
+
|
|
31
|
+
if arg.startswith("--"):
|
|
32
|
+
key = arg[2:]
|
|
33
|
+
param = sig.parameters[key]
|
|
34
|
+
|
|
35
|
+
if param.annotation == bool:
|
|
36
|
+
parsed[key] = True
|
|
37
|
+
i += 1
|
|
38
|
+
else:
|
|
39
|
+
value = argv[i + 1]
|
|
40
|
+
parsed[key] = convert(value, param.annotation)
|
|
41
|
+
i += 2
|
|
42
|
+
else:
|
|
43
|
+
positionals.append(arg)
|
|
44
|
+
i += 1
|
|
45
|
+
|
|
46
|
+
# fill positional parameters
|
|
47
|
+
for param, value in zip(params, positionals):
|
|
48
|
+
if param.name not in parsed:
|
|
49
|
+
parsed[param.name] = convert(value, param.annotation)
|
|
50
|
+
|
|
51
|
+
# fill defaults
|
|
52
|
+
for param in params:
|
|
53
|
+
if param.name not in parsed:
|
|
54
|
+
if param.default != inspect._empty:
|
|
55
|
+
parsed[param.name] = param.default
|
|
56
|
+
elif param.annotation == bool:
|
|
57
|
+
parsed[param.name] = False
|
|
58
|
+
|
|
59
|
+
return main(**parsed)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fun-args
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Tiny CLI argument parser inspired by Typer
|
|
5
|
+
Author-email: Maxim Grivennyy <maximgriven@gmail.com>
|
|
6
|
+
Requires-Python: >=3.11
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
|
|
9
|
+
# Fun Args Package
|
|
10
|
+
|
|
11
|
+
Simple argument passing library inspired by Typer
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
# Your main with explicitly defined parameters
|
|
15
|
+
def main(name: str, age: int = 25, smart = False):
|
|
16
|
+
print(f"Hi, {name}")
|
|
17
|
+
|
|
18
|
+
# Don't forget to call my function
|
|
19
|
+
argumentize(main)
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Now you in your terminal you can run:
|
|
23
|
+
`python filename.py --name Max --age 22`
|
|
24
|
+
|
|
25
|
+
Supports both flagged and ordered parameters. E.g.
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
def main(a, b):
|
|
29
|
+
print(a + b)
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
You could run in with
|
|
34
|
+
`python filename.py 2 7`
|
|
35
|
+
|
|
36
|
+
And get 27, because by default everything's converted to strings
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
fun_args
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "fun-args"
|
|
3
|
+
version = "0.0.1"
|
|
4
|
+
description = "Tiny CLI argument parser inspired by Typer"
|
|
5
|
+
authors = [
|
|
6
|
+
{ name="Maxim Grivennyy", email="maximgriven@gmail.com" }
|
|
7
|
+
]
|
|
8
|
+
dependencies = []
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
|
|
12
|
+
[build-system]
|
|
13
|
+
requires = ["setuptools>=61.0"]
|
|
14
|
+
build-backend = "setuptools.build_meta"
|
fun_args-0.0.1/setup.cfg
ADDED