rdee-series toolkits: python-easyarg
Project description
rdee-python-easyarg
- This package is primarily designed to automatically generate command-line interfaces for functions.
- Inspired by typer and fire, they aim to achieve comprehensive functionality but requires the insertion of specific code snippets into the codebase.
- This project intends to generate command-line interfaces for functions without intruding into the function code (using the decorator pattern) or even the entire script (using the
pyfexeexecutable). - The trade-off is that all function parameters must have type annotations, and at least one must be of a primitive type (float, int, str, or bool).
Install
pip install rdee-easyarg
Examples
CLI-app mode
- In this mode, we use a decorator to declare CLI interface
import easyarg
ea = easyarg.EasyArg()
# @ea.command()
# @ea.command(desc="manual description rather than docstring")
@ea.command(name="func1", alias="f", defaults={"y": 3}, choicess={"x": (1,2,3)})
def f1(x: int, y: int, flag1: bool, flag2: bool = False):
"""
:param x: this info will be read as argument description in -h, --help
:param y: {3,4,5} the leading {...} will be parsed into choices if not specified
"""
print(x+y)
if __name__ == "__main__":
ea.parse()
- You can run the script directly, such as
./a.py f1 --x 1 --y 2, and get 3 -h/--helpfor app level and function level are both supported
CLI-executor mode
- In this mode, we can execute a function in CLI without INSERTING any code
- For instance, given the
funcs.py
def add(x: int, y: int = 0) -> int:
print(x + y)
def failfunc(x, y):
pass
def mul(a: float, B: float, c: float = 1.0) -> float:
print(a * B * c)
- run
pyfexe funcs.py -hto check valid functions to execute - then run
pyfexe funcs.py add -hto check usage of target function - then run
pyfexe funcs.py add -x 1execute the function "add", withx=1, y=0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
rdee_easyarg-25.4.10.tar.gz
(15.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rdee_easyarg-25.4.10.tar.gz.
File metadata
- Download URL: rdee_easyarg-25.4.10.tar.gz
- Upload date:
- Size: 15.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.31.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72b286c94a4fd1f08da03521192a438b5c33e669071a2a7318ce7d21723f65e3
|
|
| MD5 |
a0cb1efd1ccd92987eb31bd54b3870c1
|
|
| BLAKE2b-256 |
cae60864cb92d803ca9ad3ac7aaf5a4d8115f13d2ea1f5781c988935107e0caa
|
File details
Details for the file rdee_easyarg-25.4.10-py2.py3-none-any.whl.
File metadata
- Download URL: rdee_easyarg-25.4.10-py2.py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.31.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
175fcb4834a8e84d5560a225ef3cd57d47025640844376c3050f2880f3aff988
|
|
| MD5 |
146567f64e59139ed49bc597ba0ce457
|
|
| BLAKE2b-256 |
4eb4101566bc5cb3ebd13cf5efd65b55a32ed4055e2e160b7f7a112f205ff4ad
|