doc to argparse driven by docopt
Project description
argopt
======
doc to argparse driven by docopt
|PyPi Status| |PyPi Downloads|
|Build Status| |Coverage Status| |Branch Coverage Status|
------------------------------------------
.. contents:: Table of contents
:backlinks: top
:local:
Installation
------------
Latest pypi stable release
~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code:: sh
pip install argopt
Latest development release on github
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Pull and install in the current directory:
.. code:: sh
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 <https://github.com/casperdcl/argopt/releases>`_
or on crawlers such as
`allmychanges.com <https://allmychanges.com/p/python/argopt/>`_.
Usage
-----
Standard `docopt <https://github.com/docopt/docopt>`_ docstring syntax applies.
Additionally, some improvements and enhancements are supported, such as type
checking and default positional arguments.
.. code:: python
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
-------------
.. code:: python
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:
.. code:: sh
$ python setup.py make alltests
To see all options, run:
.. code:: sh
$ 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/ <https://mozilla.org/MPL/2.0/>`__.
Authors
-------
- Casper da Costa-Luis <casper@caspersci.uk.to>
.. |Build Status| image:: https://travis-ci.org/casperdcl/argopt.svg?branch=master
:target: https://travis-ci.org/casperdcl/argopt
.. |Coverage Status| image:: https://coveralls.io/repos/casperdcl/argopt/badge.svg
:target: https://coveralls.io/r/casperdcl/argopt
.. |Branch Coverage Status| image:: https://codecov.io/github/casperdcl/argopt/coverage.svg?branch=master
:target: https://codecov.io/github/casperdcl/argopt?branch=master
.. |PyPi Status| image:: https://img.shields.io/pypi/v/argopt.svg
:target: https://pypi.python.org/pypi/argopt
======
doc to argparse driven by docopt
|PyPi Status| |PyPi Downloads|
|Build Status| |Coverage Status| |Branch Coverage Status|
------------------------------------------
.. contents:: Table of contents
:backlinks: top
:local:
Installation
------------
Latest pypi stable release
~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code:: sh
pip install argopt
Latest development release on github
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Pull and install in the current directory:
.. code:: sh
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 <https://github.com/casperdcl/argopt/releases>`_
or on crawlers such as
`allmychanges.com <https://allmychanges.com/p/python/argopt/>`_.
Usage
-----
Standard `docopt <https://github.com/docopt/docopt>`_ docstring syntax applies.
Additionally, some improvements and enhancements are supported, such as type
checking and default positional arguments.
.. code:: python
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
-------------
.. code:: python
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:
.. code:: sh
$ python setup.py make alltests
To see all options, run:
.. code:: sh
$ 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/ <https://mozilla.org/MPL/2.0/>`__.
Authors
-------
- Casper da Costa-Luis <casper@caspersci.uk.to>
.. |Build Status| image:: https://travis-ci.org/casperdcl/argopt.svg?branch=master
:target: https://travis-ci.org/casperdcl/argopt
.. |Coverage Status| image:: https://coveralls.io/repos/casperdcl/argopt/badge.svg
:target: https://coveralls.io/r/casperdcl/argopt
.. |Branch Coverage Status| image:: https://codecov.io/github/casperdcl/argopt/coverage.svg?branch=master
:target: https://codecov.io/github/casperdcl/argopt?branch=master
.. |PyPi Status| image:: https://img.shields.io/pypi/v/argopt.svg
:target: https://pypi.python.org/pypi/argopt
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 Distributions
argopt-0.2.0.zip
(22.2 kB
view details)
argopt-0.2.0.tar.gz
(16.1 kB
view details)
File details
Details for the file argopt-0.2.0.zip
.
File metadata
- Download URL: argopt-0.2.0.zip
- Upload date:
- Size: 22.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 623757a8efd1d34139aa80afd2271d67e02b17ac74b23afd95e50ce6d5b41991 |
|
MD5 | 0b25990a137287f69271e0035b95df41 |
|
BLAKE2b-256 | ac85929e5e5b289d6b5db026b20bbccddadb71bd41cfd5249719b763aaad6dd8 |
File details
Details for the file argopt-0.2.0.tar.gz
.
File metadata
- Download URL: argopt-0.2.0.tar.gz
- Upload date:
- Size: 16.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08b6e14363a3b994f3c328bbd5d4cb49fe2d6ac84545a2dea2ecf8a738029d3c |
|
MD5 | c75f2c7915f6264734173fd0651e1e77 |
|
BLAKE2b-256 | 3e7a271eb8bd6a8b2370400ee00bf8fb57489e1f7c7b4b41d0805e2070f510bb |