No project description provided
Project description
Water
Like fire
This python library parses classes so that they can be executed as commands.
In contrast with fire, there is no "automatic" type casting -- the type casting is 100% based on type hints.
Type casting
When calling execute_command the values passed in the command get casted to the annotated types on the function
signature.
Supported types:
- int, float
- bool: the strings
['true', '1', 't', 'y']are considered true. - lists, tuples: input is split by comma (
,) and each element is casted independently. - enum
- Union[]: gets casted to all options in order, first success is returned.
Optional[type]isUnion[type, NoneType]
water.Flag: flag, only denotes the switch was present.
Examples
Type casting
class Math1:
def add_list(self, items: Optional[List[int]] = None):
if not items:
return 0
return sum(items)
# `items` casted to a list of `int`
res = execute_command(Math1, 'add_list --items 1,2,3')
assert res == 6
# `items` casted to a list of `int`, even though there is only one entry
res = execute_command(Math1, 'add_list --items 1')
assert res == 1
Nested commands
class NestedObj:
class Inside1:
def fn1(self, number: int):
return number
res = execute_command(NestedObj, 'Inside1 fn1 --number 1')
assert res == 1
Testing
Python3.6:
docker build -f dockerfiles/3.6-Dockerfile .
Python3.7+
poetry run pytest
Releasing
poetry publish --build --username $PYPI_USERNAME --password $PYPI_PASSWORD
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
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 water_cli-0.1.10.tar.gz.
File metadata
- Download URL: water_cli-0.1.10.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.8 CPython/3.9.5 Linux/5.11.0-40-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e35f301a3465710f3c3645e5ccbf81fa21962c0c6c385efce72da196634ad2ad
|
|
| MD5 |
93a5a306b7cd596f59190553b4311b56
|
|
| BLAKE2b-256 |
73f0313c59f1fba932ec98dda70a4b6850f073e61bd295f542cca6b8b12ace22
|
File details
Details for the file water_cli-0.1.10-py3-none-any.whl.
File metadata
- Download URL: water_cli-0.1.10-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.8 CPython/3.9.5 Linux/5.11.0-40-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c2f4d370a14c9bf2f0be35e07aa76a0ca20569bc4662b72ab5c7f1445a36545
|
|
| MD5 |
144fab90612500566ffb72af4e2f9a92
|
|
| BLAKE2b-256 |
9706b136aeb39fe16241036be584e75a69e9090a34a1b342fa30396f6287d15a
|