Skip to main content

doc to argparse driven by docopt

Project description

doc to argparse driven by docopt

PyPi Status Build Status Coverage Status Branch Coverage Status


Installation

Latest pypi stable release

pip install argopt

Latest development release on github

Pull and install in the current directory:

pip install -e git+https://github.com/casperdcl/argopt.git@master#egg=argopt

Changelog

The list of all changes is available either on Github’s Releases or on crawlers such as allmychanges.com.

Usage

Standard docopt docstring syntax applies. Additionally, some improvements and enhancements are supported, such as type checking and default positional arguments.

from argopt import argopt


def main(doc):
    parser = argopt(doc, version='0.1.2-3.4')
    # parser.print_help()

    args = parser.parse_args()
    print (args)


if __name__ == '__main__':
    doc = '''
Example programme description.
You should be able to do
    args = argopt(__doc__).parse_args()
instead of
    args = docopt(__doc__)
Usage:
    test.py [-h | options] <x> [<y>...]
Arguments:
    <x>                   A file.
    --anarg=<a>           Description here [default: 1e3:int].
    -p PAT, --patts PAT   Or [default: '':str].
    --bar=<b>             Another [default: something] should assume str.
    -f, --force           Force.
    -v, --version         Print version and exit.
'''
    main(doc)

Documentation

def argopt(doc='', argparser=argparse.ArgumentParser, *args, **kwargs):
    """
    Note that `docopt` supports neither type specifiers nor default
    positional arguments. We support both here.

    Parameters
    ----------
    doc  : docopt compatible, with optional type specifiers
         [default: '':str]
    argparser  : Argument parser class [default: argparse.ArgumentParser]

    Returns
    -------
    out  : argparser object (default: argparse.ArgumentParser)

    Usage
    -----
    Extension syntax example: [default: 1e3:int].

    You should be able to do
        parser = argopt(__doc__)
        args   = parser.parse_args()
    instead of
        args = docopt(__doc__)

    TODO
    ----
    add_argument_group
    add_mutually_exclusive_group
    (docopt extension) action choices
    (docopt extension) action count
    """

Contributions

To run the testing suite please make sure tox (https://testrun.org/tox/latest/) is installed, then type tox from the command line.

Where tox is unavailable, a Makefile-like setup is provided with the following command:

$ python setup.py make alltests

To see all options, run:

$ python setup.py make

Licence

OSI approved.

Copyright (c) 2016 Casper da Costa-Luis.

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

Authors

Project details


Download files

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

Source Distributions

argopt-0.2.1.zip (22.2 kB view details)

Uploaded Source

argopt-0.2.1.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

argopt-0.2.1-py2.py3-none-any.whl (14.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file argopt-0.2.1.zip.

File metadata

  • Download URL: argopt-0.2.1.zip
  • Upload date:
  • Size: 22.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for argopt-0.2.1.zip
Algorithm Hash digest
SHA256 afe28c03f31e1a13f4797388432375ee82a38f75e1558d9a6696c00d7c5745b8
MD5 d4cc721e783c2ef66071dd5af4af0ff0
BLAKE2b-256 a4c968acc0516fd57896af13910df3fba1272980f13dd7c2c8b9e291c4d35bd7

See more details on using hashes here.

File details

Details for the file argopt-0.2.1.tar.gz.

File metadata

  • Download URL: argopt-0.2.1.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for argopt-0.2.1.tar.gz
Algorithm Hash digest
SHA256 0e91c767945c35888a3e6cf3223d7a22c26584b4be7544fcd2fa2a2c1f00bfc6
MD5 7a116754a89d3253a50133c6cc53827d
BLAKE2b-256 dd4a6c077882e9734134c98c751999193d173e5f64a6c638deebafb665261544

See more details on using hashes here.

File details

Details for the file argopt-0.2.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for argopt-0.2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 6fe363564f525182dcea17455d94f57846bba30be8117e9e220f7057713676d6
MD5 6c7befa0b96e2c1dfd831aaa2c4e15e1
BLAKE2b-256 5826a0ba9ce500562a9f3f2f71d4a42be1dfd9204ee86b0d0818881bd1c37890

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