Reference
Decorated functions as entry points.
Example
# file.py
from entrypoint import entrypoint
@entrypoint(__name__)
def main() -> None:
print("Hello, world!")
>>> import file
>>> # no output
$ python file.py
Hello, world!
MAIN = '__main__'
module-attribute
The __main__
name constant.
Main = Nullary[None]
module-attribute
The main
function that does not take arguments and returns nothing.
EntryPoint
Represents handlers for @entrypoint
decorators.
Source code in entrypoint/core.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
entrypoint(name: Optional[str] = None) -> EntryPoint
Defines decorated functions as entry points.
Calls the wrapped function if the module gets run directly.
Instead of applying dark magic, this function expects
callers to pass the __name__
variable as an argument,
and merely checks it against MAIN
when needed.
In case __name__
is not provided, this function will attempt to read
the module name from the function given (via __module__
).
EntryPoint(name)
is created under the hood, and is
then used to handle calls.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
Optional[str]
|
The |
None
|
Returns:
Type | Description |
---|---|
EntryPoint
|
The created |
Source code in entrypoint/core.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
is_main(name: str) -> bool
Checks if the name
is equal to MAIN
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name to check. |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether the |
Source code in entrypoint/core.py
18 19 20 21 22 23 24 25 26 27 |
|