未提供项目描述
项目描述
主入口点
避免使用的装饰器if __name__ == "__main__":
,而是使用
from main_entrypoint import entrypoint
@entrypoint
def main():
print("Hello World")
$ python my_script.py
Hello World
$ python -c "import my_script"
# no output
安装
pip install main-entrypoint
细节
在函数上指定@entrypoint
装饰器my_func
可以认为等同于运行
if __name__ == "__main__":
my_func()
在同一模块的末尾。
如果在同一个文件中多次使用装饰器,则函数按照定义的顺序执行。
默认entrypoint
装饰器使用atexit
模块。注册的 atexit 函数的简单使用仍然按预期工作,但涉及依赖 atexit 行为的工作流(例如特定异常流)可能:tm:中断。在这些情况下,请考虑使用其他两种可用模式之一first_rerun_remaining
,immediate
例如
from main_entrypoint import entrypoint
@entrypoint(mode="immediate")
def main():
print("Hello World")
immediate
立即调用修饰函数,模块后面定义的实体将不可用,因此鼓励将函数移动到模块末尾。first_rerun_remaining
将在修饰函数两次之后有效地运行所有内容,因此代码应该没有副作用,并且在这种情况下最好只包含定义。默认模式是at_exit
并且应该被视为首选。
未来的工作
- 测试
- 自动格式化、检查和发布
- 允许将参数传递给入口点函数
执照
项目详情
关
main_entrypoint -0.1.3-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | c2ba8d27d140572146b1cd1980d7ede525847cf0486647fb72adb731b8efaa59 |
|
MD5 | 70ba2a680405d4040796114fab89a522 |
|
布莱克2-256 | 24c47873413ce0e530a04ddd3dfedac97bf1efdda080363fc16e49fc9379b8d3 |