Skip to main content

No project description provided

Project description

Water

codecov

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] is Union[type, NoneType]
  • water.Flag: flag, only denotes the switch was present.
  • water.Repeated[T]: Effectively the same as List[T] but allows flags to be repeated and values will be concatenated

Utilities

  • exclusive_flags forbids certain flag combinations to be used at the same time.
    • If --a and --b are exclusive, executing command --a --b causes an error.
  • required_together requires certain flag combinations to be used at the same time.
    • If --a and --b are required together, executing command --a or command --b causes an error.

Examples

Type casting

class Math1:

    def add_list(self, items: Optional[List[int]] = None):
        if not items:
            return 0
        return sum(items)

    def add_numbers(self, number: Repeated[int]):
        return sum(number)

# `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

# `number` casted to a list of `int`, even though there is only one entry
res = execute_command(Math1, 'add_numbers --number 1')
assert res == 1

# `number` casted to a list of `int`, even though there is only one entry
res = execute_command(Math1, 'add_numbers --number 1 --number 2')
assert res == 3

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.9, 3.11:

docker build -f dockerfiles/3.9-Dockerfile .
docker build -f dockerfiles/3.11-Dockerfile .

Development

poetry run pytest

Releasing

poetry publish --build --username $PYPI_USERNAME --password $PYPI_PASSWORD

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

water_cli-0.1.15.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

water_cli-0.1.15-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file water_cli-0.1.15.tar.gz.

File metadata

  • Download URL: water_cli-0.1.15.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.10.6 Linux/6.0.0-060000-generic

File hashes

Hashes for water_cli-0.1.15.tar.gz
Algorithm Hash digest
SHA256 282cefdf72d4a9370ba9a52d657dfc145231b5228cc949b4ac3a81d89a866025
MD5 f1e5800618b30477c10d3a00bbdd24dd
BLAKE2b-256 2e988d7abaf437831d651098d438d7eb85b6ac85a6c2ba367367c901e2885a07

See more details on using hashes here.

File details

Details for the file water_cli-0.1.15-py3-none-any.whl.

File metadata

  • Download URL: water_cli-0.1.15-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.10.6 Linux/6.0.0-060000-generic

File hashes

Hashes for water_cli-0.1.15-py3-none-any.whl
Algorithm Hash digest
SHA256 15214a1b916f15b6fdc6e93b6343e927044370bc622c8d14fd2f3fa709721ea3
MD5 c48510851b652dc025c58b8246add189
BLAKE2b-256 6d584b5dc8bc4979d462013b6b51b7598f1ffb109a2c72518aba69be4d0b569f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page