Exposing python functions to the command line
Project description
pyopt version 0.75
A module for command-line options with a pythonic, decorator-centric syntax.
The following example auto-generates help with docstrings, type casting for
arguments and enforcing argument count:
import pyopt
expose = pyopt.Exposer()
@expose.args
def regular_function(arg1:str, arg2:int):
'''Your help - the docstring'''
# bla, etc, foobar spam...
print(repr(arg1), repr(arg2))
if __name__ == "__main__":
expose.run()
There are 3 modes of operation:
1. expose.args - A decorator for positional arguments.
2. expose.kwargs - A decorator for keyword arguments.
3. expose.mixed - A decorator for keyword and positional arguments.
Currently known compromises that are open to discussion, e-mail me:
1. This module was specifically designed with python 3 in mind, certain features
can be converted to python 2.x, but the awesome ones can't.
2. Keyword command-line functions require every argument to start with a
different letter to avoid collisions.
3. Annotations aren't mandatory, I don't know if this is the right way to go,
it's an explicity vs convenience issue.
4. Booleans can't default to false. I couldn't think of a use case for this
so tell me if you did.
License: whatever, I don't mind. Google Code made me choose so I went with
the "New BSD". If somebody has a better idea, e-mail, comment or whatnot.
Hearing from whoever uses this code would be nice, but you really shouldn't
feel obliged.
Contact me at: ubershmekel at gmail
A module for command-line options with a pythonic, decorator-centric syntax.
The following example auto-generates help with docstrings, type casting for
arguments and enforcing argument count:
import pyopt
expose = pyopt.Exposer()
@expose.args
def regular_function(arg1:str, arg2:int):
'''Your help - the docstring'''
# bla, etc, foobar spam...
print(repr(arg1), repr(arg2))
if __name__ == "__main__":
expose.run()
There are 3 modes of operation:
1. expose.args - A decorator for positional arguments.
2. expose.kwargs - A decorator for keyword arguments.
3. expose.mixed - A decorator for keyword and positional arguments.
Currently known compromises that are open to discussion, e-mail me:
1. This module was specifically designed with python 3 in mind, certain features
can be converted to python 2.x, but the awesome ones can't.
2. Keyword command-line functions require every argument to start with a
different letter to avoid collisions.
3. Annotations aren't mandatory, I don't know if this is the right way to go,
it's an explicity vs convenience issue.
4. Booleans can't default to false. I couldn't think of a use case for this
so tell me if you did.
License: whatever, I don't mind. Google Code made me choose so I went with
the "New BSD". If somebody has a better idea, e-mail, comment or whatnot.
Hearing from whoever uses this code would be nice, but you really shouldn't
feel obliged.
Contact me at: ubershmekel at gmail
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
pyopt-0.75.zip
(9.1 kB
view details)
File details
Details for the file pyopt-0.75.zip.
File metadata
- Download URL: pyopt-0.75.zip
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8df3ad00d417f399a5dbd55cce7d78a2a980c243d1cead8e21a49f0ebeb7dca1
|
|
| MD5 |
86a6f10263df1e7de301ceffde8ca6e0
|
|
| BLAKE2b-256 |
6ae691979e58348cdc38d3c55f18f0c0f2364fb58ccdc643d3c6d5d6231e7685
|