def-main 0.11.0__py3-none-any.whl → 0.12.0__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.
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
from typing import Callable
|
|
2
1
|
import inspect
|
|
3
2
|
import sys
|
|
3
|
+
from collections.abc import Callable
|
|
4
4
|
|
|
5
5
|
MAINS = []
|
|
6
6
|
|
|
@@ -10,7 +10,9 @@ def def_main(f: Callable) -> Callable:
|
|
|
10
10
|
MAINS.append((f, s.filename, s.lineno))
|
|
11
11
|
|
|
12
12
|
if f.__module__ == '__main__':
|
|
13
|
-
f(*sys.argv[1:])
|
|
13
|
+
result = f(*sys.argv[1:])
|
|
14
|
+
if result:
|
|
15
|
+
sys.exit(result)
|
|
14
16
|
|
|
15
17
|
return f
|
|
16
18
|
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: def-main
|
|
3
|
+
Version: 0.12.0
|
|
4
|
+
Summary: 🗣 A decorator for main 🗣
|
|
5
|
+
Author-email: Tom Ritchford <tom@swirly.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
13
|
+
Requires-Python: >=3.10
|
|
14
|
+
Requires-Dist: xmod<2,>=1.3.2
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# `def_main`: a tiny decorator to define main
|
|
18
|
+
|
|
19
|
+
Define the main function in one step.
|
|
20
|
+
|
|
21
|
+
For any non-trivial projects, use typer and dtyper instead!
|
|
22
|
+
|
|
23
|
+
## Usage example
|
|
24
|
+
|
|
25
|
+
### Without an return code
|
|
26
|
+
|
|
27
|
+
``` python
|
|
28
|
+
import def_main
|
|
29
|
+
|
|
30
|
+
@def_main
|
|
31
|
+
def main(*argv):
|
|
32
|
+
print('hello,', *argv)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
means precisely the same as:
|
|
36
|
+
|
|
37
|
+
``` python
|
|
38
|
+
def main(*argv):
|
|
39
|
+
print('hello,', *argv)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
if __name__ == '__main__':
|
|
43
|
+
import sys
|
|
44
|
+
|
|
45
|
+
main(sys.argv[1:])
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### With a return code
|
|
49
|
+
|
|
50
|
+
``` python
|
|
51
|
+
import def_main
|
|
52
|
+
|
|
53
|
+
@def_main
|
|
54
|
+
def main(*argv):
|
|
55
|
+
print('hello,', *argv)
|
|
56
|
+
return argv
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
means precisely the same as:
|
|
60
|
+
|
|
61
|
+
``` python
|
|
62
|
+
def main(*argv):
|
|
63
|
+
print('hello,', *argv)
|
|
64
|
+
return argv
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
if __name__ == '__main__':
|
|
68
|
+
import sys
|
|
69
|
+
|
|
70
|
+
returncode = main(sys.argv[1:])
|
|
71
|
+
sys.exit(returncode)
|
|
72
|
+
```
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
def_main/__init__.py,sha256=v1MPQh_7lMaVeRXOZYBMPeTo76UcnE6OQW6BUOiTctM,462
|
|
2
|
+
def_main-0.12.0.dist-info/METADATA,sha256=o7zePQgYpigYpQuFEkh0nWF2QhOsrFeUQ1fYDQ8Ilmg,1336
|
|
3
|
+
def_main-0.12.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
4
|
+
def_main-0.12.0.dist-info/RECORD,,
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: def-main
|
|
3
|
-
Version: 0.11.0
|
|
4
|
-
Summary: Define the main function in one step and make it testable
|
|
5
|
-
License: MIT
|
|
6
|
-
Author: Tom Ritchford
|
|
7
|
-
Author-email: tom@swirly.com
|
|
8
|
-
Requires-Python: >=3.7,<4.0
|
|
9
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
-
Classifier: Programming Language :: Python :: 3
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.7
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
-
Description-Content-Type: text/x-rst
|
|
17
|
-
|
|
18
|
-
========================================================
|
|
19
|
-
``def_main``: a tiny decorator to define main
|
|
20
|
-
========================================================
|
|
21
|
-
|
|
22
|
-
Define the main function in one step.
|
|
23
|
-
|
|
24
|
-
For any non-trivial projects, use typer and dtyper instead!
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
Usage example
|
|
28
|
-
==================
|
|
29
|
-
|
|
30
|
-
Without an return code
|
|
31
|
-
~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
32
|
-
|
|
33
|
-
.. code-block:: python
|
|
34
|
-
|
|
35
|
-
import def_main
|
|
36
|
-
|
|
37
|
-
@def_main
|
|
38
|
-
def main(*argv):
|
|
39
|
-
print('hello,', *argv)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
means precisely the same as:
|
|
43
|
-
|
|
44
|
-
.. code-block:: python
|
|
45
|
-
|
|
46
|
-
def main(*argv):
|
|
47
|
-
print('hello,', *argv)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if __name__ == '__main__':
|
|
51
|
-
import sys
|
|
52
|
-
|
|
53
|
-
main(sys.argv[1:])
|
|
54
|
-
|
|
55
|
-
With a return code
|
|
56
|
-
~~~~~~~~~~~~~~~~~~~~~~~
|
|
57
|
-
|
|
58
|
-
.. code-block:: python
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
import def_main
|
|
62
|
-
|
|
63
|
-
@def_main
|
|
64
|
-
def main(*argv):
|
|
65
|
-
print('hello,', *argv)
|
|
66
|
-
return argv
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
means precisely the same as:
|
|
70
|
-
|
|
71
|
-
.. code-block:: python
|
|
72
|
-
|
|
73
|
-
def main(*argv):
|
|
74
|
-
print('hello,', *argv)
|
|
75
|
-
return argv
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if __name__ == '__main__':
|
|
79
|
-
import sys
|
|
80
|
-
|
|
81
|
-
returncode = main(sys.argv[1:])
|
|
82
|
-
sys.exit(returncode)
|
|
83
|
-
|
def_main-0.11.0.dist-info/RECORD
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
def_main.py,sha256=fZf-qhIiAuKUH9BQ_cUA6zzA2CP2mReGYG-3qW8jY7Y,396
|
|
2
|
-
def_main-0.11.0.dist-info/WHEEL,sha256=vxFmldFsRN_Hx10GDvsdv1wroKq8r5Lzvjp6GZ4OO8c,88
|
|
3
|
-
def_main-0.11.0.dist-info/METADATA,sha256=CazI_ZUu7GaxY2g_3VD0YFpJy_MwdIFh3v4v6OnRfgc,1674
|
|
4
|
-
def_main-0.11.0.dist-info/RECORD,,
|