No project description provided
Project description
@entryp.oint
A decorator to avoid if __name__ == "__main__":, instead use
import entryp
@entryp.oint
def main():
print("Hello World")
$ python my_script.py
Hello World
$ python -c "import my_script"
# no output
Installation
pip install entryp
Details
Specifying the @entryp.oint decorator on a function my_func can be considered equivalent to running
if __name__ == "__main__":
my_func()
at the end of the same module.
If the decorator is used multiple times in the same file, the functions are executed in the order they are defined.
The default @entryp.oint decorator uses the atexit module. Simple usage of registered atexit functions still works as expected, but involved workflows (e.g. specific exception-flows) relying on atexit behaviour might:tm: break. In those cases, please consider to use one of the two other available modes, first_rerun_remaining and immediate, e.g.
import entryp
@entryp.oint(mode="immediate")
def main():
print("Hello World")
immediate calls the decorated function immediately, entities defined later in the module will not be available, so moving the function to the end of the module is encouraged. first_rerun_remaining will effectively run everything after the decorated function twice, so the code should be free of side-effects and preferably only consist of definitions in this case. The default mode is at_exit and should be considered as a first choice.
Future Work
- tests
- automating formatting, checking and releases
- allow to pass arguments to the entrypoint function
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file entryp-0.1.4.tar.gz.
File metadata
- Download URL: entryp-0.1.4.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.11 CPython/3.7.3 Linux/4.19.0-20-amd64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b2b16e8376e59e5e28ad2dfe0b01692be2b86312f988e43998cdccf75aa4ce7
|
|
| MD5 |
3fc7f90126808f0a8e9ba0c83eb97854
|
|
| BLAKE2b-256 |
197c2f9e35d8d26e51b4670e925cbabcfda47ed975ba14eeff46b73f16e0a609
|
File details
Details for the file entryp-0.1.4-py3-none-any.whl.
File metadata
- Download URL: entryp-0.1.4-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.11 CPython/3.7.3 Linux/4.19.0-20-amd64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5800d9d26fc3ab62eb580a0e03da4754e031e95edcbf8336851e31bda7f7ec3c
|
|
| MD5 |
26f1c5160f550d4d832a335178fe6ea9
|
|
| BLAKE2b-256 |
6df55a90be43259ae6bed23e85c30f522a6413b07b08fdf6c94da0f90c8b2a67
|