autoexec
Automatically turn python functions into executable scripts
Whenever you have written some code and want to run it on a cluster, the first step is to turn it into an executable. This typically leads to a quick stop over at the docs for argparse, together with a lot of duplicated effort in reproducing the function signature. This can be error-prone and annoying, especially if one edits the function.
This script automates this process, using information about types provided either through function annotation, default values in keyword arguments, or type information in numpydoc-style docstrings. Like any shell script, this limits the functions to arguments that can be passed in the terminal, (str, int, float,…).
Example
Let’s say you’ve written the following function in example.py, which provides all kinds of different type information
def add(a: int, b, c=5, d=7., e=None):
"""Some cool addition.
It's super complicated.
You know, adding and stuff.
Parameters
----------
b : int
This is the second complicated parameter
super complicated
e : int, optional
"""
if e is None:
e = 0
return a + b + c + d + e
Now all you have to do to turn this into an executable is add the following code at the bottom
if __name__ == '__main__':
import autoexec
res = autoexec.execute_function(add)
print(res)
and run chmod +x example.py. Now if you run ./example.py --help you get the following output
❯❯❯ ./example.py --help
usage: example.py [-h] --a A --b B [--c C] [--d D] [--e E]
Some cool addition.
It's super complicated.
You know, adding and stuff.
optional arguments:
-h, --help show this help message and exit
--a A int
--b B This is the second complicated parameter
super complicated
--c C int, default: 5
--d D float, default: 7.0
--e E int, default: None
And you’re ready to call the script from the command line
❯❯❯ ./example.py --a 1 --b 2 --c 3
13.0
There is type-checking by argparse
❯❯❯ ./example.py --a 1 --b stringy
usage: example.py [-h] --a A --b B [--c C] [--d D] [--e E]
example.py: error: argument --b: invalid int value: 'stringy'
and it complains about missing arguments
❯❯❯ ./example.py --a 1
usage: example.py [-h] --a A --b B [--c C] [--d D] [--e E]
example.py: error: the following arguments are required: --b
There is also support for multiple functions via autoexec.execute_functions.
Metadata
Release files for autoexec 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| autoexec-0.1.1.tar.gz | 4.5 kB | Without provenance | Details for autoexec-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| autoexec-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for autoexec-0.1.1-py3-none-any.whl |
Total release size: 11.0 kB
Release files / autoexec-0.1.1.tar.gz
| Download URL | autoexec-0.1.1.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3dee1722d8fafad4e8adbe3290316aff9848e9838c91c73e30040e06cb9fe75a
|
|
BLAKE2b-256 checksum How to use checksums |
2c0c4d0113bc56f7c887ae6a7ab174228f876782b63cb513c5491927eadc8429
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / autoexec-0.1.1-py3-none-any.whl
| Download URL | autoexec-0.1.1-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b927a073bd639a38caf7c128a7a6c08675eb10c94a099c9fa131d74f5db4a45a
|
|
BLAKE2b-256 checksum How to use checksums |
d6545cb39e0f6a96c43ef1497e7d3f80e4ee3e800b5986472b3e6d9024bea08a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for autoexec 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.