Skip to main content

No project description provided

Project description

main-entrypoint

PyPI version Supported Python Versions Code Style

A decorator to avoid if __name__ == "__main__":, instead use

from main_entrypoint import entrypoint

@entrypoint
def main():
    print("Hello World")
$ python my_script.py
Hello World

$ python -c "import my_script"
# no output

Installation

pip install main-entrypoint

Details

Specifying the @entrypoint 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 entrypoint 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.

from main_entrypoint import entrypoint

@entrypoint(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

main-entrypoint-0.1.3.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

main_entrypoint-0.1.3-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file main-entrypoint-0.1.3.tar.gz.

File metadata

  • Download URL: main-entrypoint-0.1.3.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

Hashes for main-entrypoint-0.1.3.tar.gz
Algorithm Hash digest
SHA256 97dbcec60cd216d569f8a52de268429cf2343bf3e814895cf09fd9b666281210
MD5 ab5dd0722207b415b82a2cc4e383dc42
BLAKE2b-256 39599126a38a104d1ead1a59d0033a53f9edad879cb12c70bcaa5b1a5799840b

See more details on using hashes here.

File details

Details for the file main_entrypoint-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: main_entrypoint-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 4.0 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

Hashes for main_entrypoint-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c2ba8d27d140572146b1cd1980d7ede525847cf0486647fb72adb731b8efaa59
MD5 70ba2a680405d4040796114fab89a522
BLAKE2b-256 24c47873413ce0e530a04ddd3dfedac97bf1efdda080363fc16e49fc9379b8d3

See more details on using hashes here.

Supported by

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