auto-cli-py: python package to automatically create CLI commands from function via introspection
Project description
auto-cli-py
Python Library that builds a complete CLI given one or more functions.
Most options are set using introspection/signature and annotation functionality, so very little configuration has to be done.
Setup
TL;DR Install for usage
# Install from github
pip install auto-cli-py
# See example code and output
python examples.py
In python code
Development
- Standard python packaging - Follows methodologies from: https://python-packaging.readthedocs.io/en/latest/minimal .html
- Uses pytest
Pytest
https://docs.pytest.org/en/latest/
Python (Anaconda) environment
(assumes anaconda is properly installed)
# First time. Create conda environment from environment.yml and activate it:
conda env create -f environment.yml -n auto-cli-py
conda activate auto-cli-py
# If environment changes:
conda activate auto-cli-py
conda env update -f=environment.yml
# -- OR remove and restart --
conda remove --name auto-cli-py --all
conda env create -f environment.yml
Activate environment
conda activate auto-cli-py
# This symlinks the installed auto_cli package to the source:
pip install -e .
Preparation
conda activate auto-cli-py
Linting and Testing
pytest behavior and output is controlled through auto_cli/tests/pytest.ini
# Lint all code:
pylint auto_cli
# Run all tests
pytest
# See more options for pytest:
pytest --help
# This is handy:
pytest --fixtures-per-test
Installation (other)
# AND/OR Install from a specific github branch
pip uninstall auto-cli-py
pip install git+https://github.com/tangledpath/auto-cli-py.git@features/blah
Example
#!/usr/bin/env python """ Simple Examples of CLI creation. """ import sys from auto_cli.cli import CLI import enum
def foo(): print("FOO!")
def train( data_dir:str='./data/', initial_learning_rate:float=0.0001, seed:int=2112, batch_size:int=512, epochs:int = 20): print("Training with initial_learning_rate:{initial_learning_rate}, seed:{seed}, batch_size:{batch_size}, epochs:{epochs} into data_dir:{data_dir}")
#AnimalEnum = enum.Enum('Animal', 'ANT BEE CAT DOG') class AnimalEnum(enum.Enum): ANT = 1 BEE = 2 CAT = 3 DOG = 4
def count_animals(count:int=20, animal:AnimalEnum=AnimalEnum.BEE): return count
if name == 'main': fn_opts = { 'foo': {'description':'Foobar'}, 'train': {'description':'Train'}, 'count_animals': {'description':'Count Animals'}, }
cli = CLI(sys.modules[name], function_opts=fn_opts, title="Foobar Example CLI") cli.display()
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
Built Distribution
Hashes for auto_cli_py-0.4.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0e59681ddb94455bb9f89a7e4001e4dd570bc2822aecb927bc95ea0a3320dd7 |
|
MD5 | 69bc843d253125f8fba211ffb17e0164 |
|
BLAKE2b-256 | e760e768a7291ebe17d61097736b52a7d637310168fd5bde5301a7d1443bb285 |