def-main 0.10.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.
- def_main.py → def_main/__init__.py +10 -2
- def_main-0.12.0.dist-info/METADATA +72 -0
- def_main-0.12.0.dist-info/RECORD +4 -0
- {def_main-0.10.0.dist-info → def_main-0.12.0.dist-info}/WHEEL +1 -2
- def_main-0.10.0.dist-info/METADATA +0 -64
- def_main-0.10.0.dist-info/RECORD +0 -5
- def_main-0.10.0.dist-info/top_level.txt +0 -1
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
import inspect
|
|
2
2
|
import sys
|
|
3
|
+
from collections.abc import Callable
|
|
4
|
+
|
|
5
|
+
MAINS = []
|
|
3
6
|
|
|
4
7
|
|
|
5
8
|
def def_main(f: Callable) -> Callable:
|
|
9
|
+
s = inspect.stack()[1]
|
|
10
|
+
MAINS.append((f, s.filename, s.lineno))
|
|
11
|
+
|
|
6
12
|
if f.__module__ == '__main__':
|
|
7
|
-
f(*sys.argv[1:])
|
|
13
|
+
result = f(*sys.argv[1:])
|
|
14
|
+
if result:
|
|
15
|
+
sys.exit(result)
|
|
8
16
|
|
|
9
17
|
return f
|
|
10
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,64 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: def-main
|
|
3
|
-
Version: 0.10.0
|
|
4
|
-
Summary: A simple definition of main
|
|
5
|
-
Home-page: https://github.com/rec/def_main
|
|
6
|
-
Author: Tom Ritchford
|
|
7
|
-
Author-email: tom@swirly.com
|
|
8
|
-
License: MIT
|
|
9
|
-
Keywords: main function
|
|
10
|
-
Classifier: Development Status :: 4 - Beta
|
|
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: Intended Audience :: Developers
|
|
16
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
-
Classifier: Topic :: Utilities
|
|
18
|
-
|
|
19
|
-
========================================================
|
|
20
|
-
``def_main``: a tiny decorator to define main
|
|
21
|
-
========================================================
|
|
22
|
-
|
|
23
|
-
Define a Python main function in one step - no more `__main__`!
|
|
24
|
-
|
|
25
|
-
For any non-trivial projects, use typer and dtyper instead.
|
|
26
|
-
|
|
27
|
-
Why?
|
|
28
|
-
=================
|
|
29
|
-
|
|
30
|
-
1. Less typing
|
|
31
|
-
2. Avoid the foolish ``== '__main_'`` and other mistakes
|
|
32
|
-
|
|
33
|
-
How to install
|
|
34
|
-
==================
|
|
35
|
-
|
|
36
|
-
Use ``pip``:
|
|
37
|
-
|
|
38
|
-
.. code-block:: bash
|
|
39
|
-
|
|
40
|
-
pip install def_main
|
|
41
|
-
|
|
42
|
-
Usage example
|
|
43
|
-
==================
|
|
44
|
-
|
|
45
|
-
.. code-block:: python
|
|
46
|
-
|
|
47
|
-
import def_main
|
|
48
|
-
|
|
49
|
-
@def_main
|
|
50
|
-
def main(*argv):
|
|
51
|
-
print('hello,', *argv)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
means precisely the same as:
|
|
55
|
-
|
|
56
|
-
.. code-block:: python
|
|
57
|
-
|
|
58
|
-
def main(*argv):
|
|
59
|
-
print('hello,', *argv)
|
|
60
|
-
|
|
61
|
-
if __name__ == '__main__':
|
|
62
|
-
import sys
|
|
63
|
-
|
|
64
|
-
main(sys.argv[1:])
|
def_main-0.10.0.dist-info/RECORD
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
def_main.py,sha256=t6KbsD-MujoDtv-0kD0fpHVfopcJpiNBykL_U_FHY04,297
|
|
2
|
-
def_main-0.10.0.dist-info/METADATA,sha256=Wq9XoyzBTy-SglF0UpkO66y8akM3uhNNFvkxSWE2z6Q,1405
|
|
3
|
-
def_main-0.10.0.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
|
|
4
|
-
def_main-0.10.0.dist-info/top_level.txt,sha256=vP5-CDeRdbQoKdJJRVsbHXjiBVzh88ofNMvtM38_xhU,9
|
|
5
|
-
def_main-0.10.0.dist-info/RECORD,,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
def_main
|