Skip to main content

easy to use command-line interface for python modules, fork of entrypoint

Project description

entrypoint2 is an easy to use command-line interface for python modules, fork of entrypoint

Links:

Background

There are tons of command-line handling modules but none of them can generate a CLI interface for a very simple function like this without duplicating the existing code and without making the function from other modules unusable:

def add(one, two=4, three=False):
        ''' description
        one: description
        two: description
        three: description
        '''

Best solution I could find is entrypoint, but there is no link to development site, so I forked the project. The only big disadvantage of entrypoint: it destroys the function signature, therefore the function can not be called from other modules.

Goals

  • the decorated function should have the same behavior as without the entrypoint2 decorator

  • generate CLI parameters from function signature

  • generate CLI documentation from python documentation

  • boolean parameters should be toggle flags

  • generate short flags from long flags: --long -> -l

  • automatic –version flag

Similar projects

Features

Additional features over original entrypoint:
  • function signature is preserved so it can be called both from command-line and external module

  • function name, doc and module are preserved so it can be used with sphinx autodoc

  • sphinx autodoc documentation style is supported: :param x: this is x

  • automatic --version flag, which prints version variable from the current module (__version__, VERSION, ..)

  • automatic --debug flag, which turns on logging

  • short flags are generated automatically (e.g. --parameter -> -p)

  • unit tests

Known problems:
  • Python 3 is not supported

  • there are more decorators in the module inherited from original entrypoint, but only @entrypoint is tested.

  • Autocompletion is not supported

Basic usage

Example:

from entrypoint2 import entrypoint

__version__ = '3.2'

@entrypoint
def add(one, two=4, three=False):
    ''' This function adds three numbers.

    one: first number to add
    two: second number to add
    '''

Generated help:

$ python -m entrypoint2.examples.hello --help
usage: hello.py [-h] [-t TWO] [--three] [--version] [--debug] one

This function adds two number.

positional arguments:
  one                first number to add

optional arguments:
  -h, --help         show this help message and exit
  -t TWO, --two TWO  second number to add
  --three
  --version          show program's version number and exit
  --debug            set logging level to DEBUG

Printing version:

$ python -m entrypoint2.examples.hello --version
3.2

Installation

General

if you have setuptools installed:

# as root
easy_install entrypoint2

if you have pip installed:

# as root
pip install entrypoint2

Ubuntu

sudo apt-get install python-setuptools
sudo easy_install entrypoint2

Uninstall

# as root
pip uninstall entrypoint2

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

entrypoint2-0.0.1.tar.gz (44.8 kB view details)

Uploaded Source

File details

Details for the file entrypoint2-0.0.1.tar.gz.

File metadata

  • Download URL: entrypoint2-0.0.1.tar.gz
  • Upload date:
  • Size: 44.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for entrypoint2-0.0.1.tar.gz
Algorithm Hash digest
SHA256 0e8c3c44ad6e28a526bd1129dbbeef671e66433da0427b81cdaaa6b80f03104a
MD5 c509f3dd345638f68b95cd21449e004d
BLAKE2b-256 1c11354e52e92ed59639f5b75f2056666ab79530249c5b92a83ae07dc4c359c3

See more details on using hashes here.

Supported by

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