Skip to main content

No project description provided

Project description

@entryp.oint

PyPI version Supported Python Versions Code Style

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

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

entryp-0.1.4.tar.gz (3.9 kB view hashes)

Uploaded Source

Built Distribution

entryp-0.1.4-py3-none-any.whl (3.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page