fun-args 0.0.1__py3-none-any.whl → 0.0.3__py3-none-any.whl
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/__init__.py +59 -1
- {fun_args-0.0.1.dist-info → fun_args-0.0.3.dist-info}/METADATA +5 -3
- fun_args-0.0.3.dist-info/RECORD +5 -0
- fun_args/main.py +0 -59
- fun_args-0.0.1.dist-info/RECORD +0 -6
- {fun_args-0.0.1.dist-info → fun_args-0.0.3.dist-info}/WHEEL +0 -0
- {fun_args-0.0.1.dist-info → fun_args-0.0.3.dist-info}/top_level.txt +0 -0
fun_args/__init__.py
CHANGED
|
@@ -1 +1,59 @@
|
|
|
1
|
-
|
|
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)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
|
-
Name:
|
|
3
|
-
Version: 0.0.
|
|
2
|
+
Name: fun_args
|
|
3
|
+
Version: 0.0.3
|
|
4
4
|
Summary: Tiny CLI argument parser inspired by Typer
|
|
5
5
|
Author-email: Maxim Grivennyy <maximgriven@gmail.com>
|
|
6
|
-
Requires-Python: >=3.
|
|
6
|
+
Requires-Python: >=3.9
|
|
7
7
|
Description-Content-Type: text/markdown
|
|
8
8
|
|
|
9
9
|
# Fun Args Package
|
|
@@ -11,6 +11,8 @@ Description-Content-Type: text/markdown
|
|
|
11
11
|
Simple argument passing library inspired by Typer
|
|
12
12
|
|
|
13
13
|
```python
|
|
14
|
+
from fun_args import argumentize
|
|
15
|
+
|
|
14
16
|
# Your main with explicitly defined parameters
|
|
15
17
|
def main(name: str, age: int = 25, smart = False):
|
|
16
18
|
print(f"Hi, {name}")
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
fun_args/__init__.py,sha256=9CNToRrgk2Gg6E6XjPQbJPShy5HwadELAq9-FRhH8eY,1533
|
|
2
|
+
fun_args-0.0.3.dist-info/METADATA,sha256=Dx8iCd-5wH8OCMu6e25Dpu5qpQ0oAHfM0ksuSNOkGl8,851
|
|
3
|
+
fun_args-0.0.3.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
4
|
+
fun_args-0.0.3.dist-info/top_level.txt,sha256=Zo8QUvL6orXEOdypGmIotozZTcv6rH-INV6Yjzc-_wM,9
|
|
5
|
+
fun_args-0.0.3.dist-info/RECORD,,
|
fun_args/main.py
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
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)
|
fun_args-0.0.1.dist-info/RECORD
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
fun_args/__init__.py,sha256=5g6QiGB9QrBzT3wbJXluhdcRkskSmoIkIRGYsxR_dCA,31
|
|
2
|
-
fun_args/main.py,sha256=9CNToRrgk2Gg6E6XjPQbJPShy5HwadELAq9-FRhH8eY,1533
|
|
3
|
-
fun_args-0.0.1.dist-info/METADATA,sha256=K6E7ZQyQZp_sH4nDrfGVEGQ9D7-0sm-vrJODBjaR5vM,816
|
|
4
|
-
fun_args-0.0.1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
5
|
-
fun_args-0.0.1.dist-info/top_level.txt,sha256=Zo8QUvL6orXEOdypGmIotozZTcv6rH-INV6Yjzc-_wM,9
|
|
6
|
-
fun_args-0.0.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|