Hello community,
here is the log from the commit of package python-entrypoint2 for
openSUSE:Factory checked in at 2012-06-25 12:00:14
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-entrypoint2 (Old)
and /work/SRC/openSUSE:Factory/.python-entrypoint2.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-entrypoint2", Maintainer is ""
Changes:
--------
--- /work/SRC/openSUSE:Factory/python-entrypoint2/python-entrypoint2.changes
2012-03-27 08:57:51.000000000 +0200
+++
/work/SRC/openSUSE:Factory/.python-entrypoint2.new/python-entrypoint2.changes
2012-06-25 12:00:16.000000000 +0200
@@ -1,0 +2,10 @@
+Fri Jun 15 15:21:26 UTC 2012 - [email protected]
+
+- Update to 0.0.6. Upstream provides no changelog, but looking at the (4)
+ commits on github since 0.0.5, I see these changes:
+ * Update documentaiton
+ * Support repeated arguments
+ * Use PEP8 formatting
+- Add Requires entries for python-argparse and -decorator
+
+-------------------------------------------------------------------
Old:
----
entrypoint2-0.0.5.tar.gz
New:
----
entrypoint2-0.0.6.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ python-entrypoint2.spec ++++++
--- /var/tmp/diff_new_pack.rdSu4W/_old 2012-06-25 12:00:19.000000000 +0200
+++ /var/tmp/diff_new_pack.rdSu4W/_new 2012-06-25 12:00:19.000000000 +0200
@@ -15,8 +15,9 @@
# Please submit bugfixes or comments via http://bugs.opensuse.org/
#
+
Name: python-entrypoint2
-Version: 0.0.5
+Version: 0.0.6
Release: 0
Url: https://github.com/ponty/entrypoint2
Summary: Easy to use command-line interface for python modules, fork of
entrypoint
@@ -26,6 +27,8 @@
BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildRequires: python-devel
BuildRequires: python-distribute
+Requires: python-argparse
+Requires: python-decorator
%if 0%{?suse_version} && 0%{?suse_version} <= 1110
%{!?python_sitelib: %global python_sitelib %(python -c "from
distutils.sysconfig import get_python_lib; print get_python_lib()")}
%else
@@ -46,7 +49,7 @@
python setup.py install --prefix=%{_prefix} --root=%{buildroot}
%files
-%defattr(-,root,root,-)
+%defattr(-,root,root)
%doc LICENSE.txt README.rst
%{python_sitelib}/*
++++++ entrypoint2-0.0.5.tar.gz -> entrypoint2-0.0.6.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/entrypoint2-0.0.5/PKG-INFO
new/entrypoint2-0.0.6/PKG-INFO
--- old/entrypoint2-0.0.5/PKG-INFO 2012-03-10 09:36:56.000000000 +0100
+++ new/entrypoint2-0.0.6/PKG-INFO 2012-05-17 16:54:00.000000000 +0200
@@ -1,81 +1,58 @@
Metadata-Version: 1.0
Name: entrypoint2
-Version: 0.0.5
+Version: 0.0.6
Summary: easy to use command-line interface for python modules, fork of
entrypoint
Home-page: https://github.com/ponty/entrypoint2
Author: ponty
Author-email: UNKNOWN
License: BSD
-Description: entrypoint2 is an easy to use command-line interface for python
modules, fork of `entrypoint <http://pypi.python.org/pypi/entrypoint/>`_
+Description: entrypoint2 is an easy to use argparse_ based command-line
interface for python modules, fork of `entrypoint
<http://pypi.python.org/pypi/entrypoint/>`_.
+ It translates function signature and documentation to argparse_
configuration.
Links:
+
* home: https://github.com/ponty/entrypoint2
* documentation: http://ponty.github.com/entrypoint2
+ Goals:
- Background
- ============
+ - simplicity: only one decorator to add to existing code
+
+ Features:
- 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
+ - good for protoyping or simple CLI
- 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
- ================
-
- * `entrypoint <http://pypi.python.org/pypi/entrypoint/>`_
- * `plac <http://micheles.googlecode.com/hg/plac/doc/plac.html>`_
- * `baker <http://bitbucket.org/mchaput/baker>`_
- * `argh <http://packages.python.org/argh/>`_
- * `opster <http://pypi.python.org/pypi/opster/>`_
- * `commandline <http://pypi.python.org/pypi/commandline>`_
- * `optfunc <https://github.com/simonw/optfunc>`_: it has the same
concept
- * `commando (1) <http://freshmeat.net/projects/commando>`_
- * `commando (2) <https://github.com/lakshmivyas/commando>`_
-
- Features
- ============
-
- Additional features over original entrypoint_:
+ - the decorated function has the same behavior as without the
entrypoint2 decorator
+ - boolean parameters are toggle flags (e.g. ``--verbose``)
- 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``)
+ - short flags are generated from long flags automatically (e.g.
``--parameter`` -> ``-p``)
- unit tests
- supported python versions: 2.5, 2.6, 2.7, 3.1, 3.2, PyPy
+ - support for repeating arguments
Known problems:
- - there are more decorators in the module inherited from original
entrypoint_,
- but only @entrypoint is tested.
+ - None.
+
+ Similar projects:
+
+ * `entrypoint <http://pypi.python.org/pypi/entrypoint/>`_
+ * `plac <http://micheles.googlecode.com/hg/plac/doc/plac.html>`_
+ * `baker <http://bitbucket.org/mchaput/baker>`_
+ * `argh <http://packages.python.org/argh/>`_
+ * `opster <http://pypi.python.org/pypi/opster/>`_
+ * `commandline <http://pypi.python.org/pypi/commandline>`_
+ * `optfunc <https://github.com/simonw/optfunc>`_: this has the same
concept
+ * `commando (1) <http://freshmeat.net/projects/commando>`_
+ * `commando (2) <https://github.com/lakshmivyas/commando>`_
+ * argparse_
+ * `optparse <http://docs.python.org/library/optparse.html>`_
Basic usage
============
@@ -120,8 +97,7 @@
Installation
============
- General
- --------
+ General:
* install pip_
* install the program::
@@ -129,16 +105,12 @@
# as root
pip install entrypoint2
- Ubuntu
- ----------
- ::
+ Ubuntu::
sudo apt-get install python-pip
sudo pip install entrypoint2
- Uninstall
- ----------
- ::
+ Uninstall::
# as root
pip uninstall entrypoint2
@@ -148,6 +120,8 @@
.. _pip: http://pip.openplans.org/
.. _entrypoint: http://pypi.python.org/pypi/entrypoint/
.. _autodoc: http://sphinx.pocoo.org/ext/autodoc.html
+ .. _argparse: http://docs.python.org/dev/library/argparse.html
+
Keywords: argparse decorator optparse signature command-line
Platform: UNKNOWN
Classifier: License :: OSI Approved :: BSD License
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/entrypoint2-0.0.5/README.rst
new/entrypoint2-0.0.6/README.rst
--- old/entrypoint2-0.0.5/README.rst 2012-03-09 16:33:53.000000000 +0100
+++ new/entrypoint2-0.0.6/README.rst 2012-05-17 10:55:48.000000000 +0200
@@ -1,73 +1,50 @@
-entrypoint2 is an easy to use command-line interface for python modules, fork
of `entrypoint <http://pypi.python.org/pypi/entrypoint/>`_
+entrypoint2 is an easy to use argparse_ based command-line interface for
python modules, fork of `entrypoint
<http://pypi.python.org/pypi/entrypoint/>`_.
+It translates function signature and documentation to argparse_ configuration.
Links:
+
* home: https://github.com/ponty/entrypoint2
* documentation: http://ponty.github.com/entrypoint2
+Goals:
-Background
-============
+ - simplicity: only one decorator to add to existing code
+
+Features:
-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
+ - good for protoyping or simple CLI
- 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
-================
-
- * `entrypoint <http://pypi.python.org/pypi/entrypoint/>`_
- * `plac <http://micheles.googlecode.com/hg/plac/doc/plac.html>`_
- * `baker <http://bitbucket.org/mchaput/baker>`_
- * `argh <http://packages.python.org/argh/>`_
- * `opster <http://pypi.python.org/pypi/opster/>`_
- * `commandline <http://pypi.python.org/pypi/commandline>`_
- * `optfunc <https://github.com/simonw/optfunc>`_: it has the same concept
- * `commando (1) <http://freshmeat.net/projects/commando>`_
- * `commando (2) <https://github.com/lakshmivyas/commando>`_
-
-Features
-============
-
-Additional features over original entrypoint_:
+ - the decorated function has the same behavior as without the entrypoint2
decorator
+ - boolean parameters are toggle flags (e.g. ``--verbose``)
- 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``)
+ - short flags are generated from long flags automatically (e.g.
``--parameter`` -> ``-p``)
- unit tests
- supported python versions: 2.5, 2.6, 2.7, 3.1, 3.2, PyPy
+ - support for repeating arguments
Known problems:
- - there are more decorators in the module inherited from original entrypoint_,
- but only @entrypoint is tested.
+ - None.
+
+Similar projects:
+
+ * `entrypoint <http://pypi.python.org/pypi/entrypoint/>`_
+ * `plac <http://micheles.googlecode.com/hg/plac/doc/plac.html>`_
+ * `baker <http://bitbucket.org/mchaput/baker>`_
+ * `argh <http://packages.python.org/argh/>`_
+ * `opster <http://pypi.python.org/pypi/opster/>`_
+ * `commandline <http://pypi.python.org/pypi/commandline>`_
+ * `optfunc <https://github.com/simonw/optfunc>`_: this has the same concept
+ * `commando (1) <http://freshmeat.net/projects/commando>`_
+ * `commando (2) <https://github.com/lakshmivyas/commando>`_
+ * argparse_
+ * `optparse <http://docs.python.org/library/optparse.html>`_
Basic usage
============
@@ -112,8 +89,7 @@
Installation
============
-General
---------
+General:
* install pip_
* install the program::
@@ -121,16 +97,12 @@
# as root
pip install entrypoint2
-Ubuntu
-----------
-::
+Ubuntu::
sudo apt-get install python-pip
sudo pip install entrypoint2
-Uninstall
-----------
-::
+Uninstall::
# as root
pip uninstall entrypoint2
@@ -139,4 +111,5 @@
.. _setuptools: http://peak.telecommunity.com/DevCenter/EasyInstall
.. _pip: http://pip.openplans.org/
.. _entrypoint: http://pypi.python.org/pypi/entrypoint/
-.. _autodoc: http://sphinx.pocoo.org/ext/autodoc.html
\ No newline at end of file
+.. _autodoc: http://sphinx.pocoo.org/ext/autodoc.html
+.. _argparse: http://docs.python.org/dev/library/argparse.html
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/entrypoint2-0.0.5/docs/usage.rst
new/entrypoint2-0.0.6/docs/usage.rst
--- old/entrypoint2-0.0.5/docs/usage.rst 2011-04-28 18:37:10.000000000
+0200
+++ new/entrypoint2-0.0.6/docs/usage.rst 2012-05-17 10:54:40.000000000
+0200
@@ -56,5 +56,28 @@
.. _autodoc: http://sphinx.pocoo.org/ext/autodoc.html
+Repeating arguments
+--------------------
+
+Only string list is supported
+.. literalinclude:: ../entrypoint2/examples/repeating.py
+
+Printing help with ``--help``:
+
+.. program-output:: python -m entrypoint2.examples.repeating --help
+ :prompt:
+
+Running:
+
+.. program-output:: python -m entrypoint2.examples.repeating
+ :prompt:
+
+
+.. program-output:: python -m entrypoint2.examples.repeating -f input1.txt
+ :prompt:
+
+
+.. program-output:: python -m entrypoint2.examples.repeating -f input1.txt -f
input2.txt
+ :prompt:
\ No newline at end of file
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/entrypoint2-0.0.5/entrypoint2/__init__.py
new/entrypoint2-0.0.6/entrypoint2/__init__.py
--- old/entrypoint2-0.0.5/entrypoint2/__init__.py 2012-03-09
15:06:56.000000000 +0100
+++ new/entrypoint2-0.0.6/entrypoint2/__init__.py 2012-05-17
16:34:03.000000000 +0200
@@ -8,16 +8,17 @@
import sys
import logging
-__version__ = '0.0.5'
+__version__ = '0.0.6'
"""
This is a library of decorators designed for writing scripts quickly. This
means they are not the most sustainable tools that exist, but they do what
they do well, and with minimal fuss. If you want additional features, you
- are likely to have more fun if you stop being lazy and using this library
:p.
+ are likely to have more fun if you stop being lazy and using
+ this library :p.
Everything here uses unicode strings, and opens files for unicode access.
- You can change the ENCODING property of this module from "utf8" if you
+ You can change the ENCODING property of this module from "utf8" if you
need to.
There are three core parts of functionality:
@@ -57,7 +58,7 @@
"""
-ENCODING='utf8'
+ENCODING = 'utf8'
PY3 = sys.version_info[0] >= 3
@@ -68,27 +69,30 @@
else:
return x.decode(ENCODING)
+
def module_version(func):
- version= None
+ version = None
for v in '__version__ VERSION version'.split():
version = func.func_globals.get(v)
if version:
break
return version
+
class ParagraphPreservingArgParseFormatter(argparse.HelpFormatter):
def __init__(self, *args, **kwargs):
- super(ParagraphPreservingArgParseFormatter, self).__init__(*args,
**kwargs)
+ super(ParagraphPreservingArgParseFormatter,
+ self).__init__(*args, **kwargs)
self._long_break_matcher = argparse._re.compile(r'\n\n+')
def _fill_text(self, text, width, indent):
output = []
for block in self._long_break_matcher.split(text.strip()):
- output.append(argparse._textwrap.fill(block, width,
initial_indent=indent, subsequent_indent=indent))
+ output.append(argparse._textwrap.fill(block, width,
+ initial_indent=indent, subsequent_indent=indent))
return "\n\n".join(output + [''])
-
class UsageError(Exception):
"""
When a function wrapped with @acceptargv or @entrypoint raises this
@@ -100,6 +104,7 @@
self.message = message
pass
+
class FileUsageError(UsageError):
def __init__(self, e):
@@ -109,15 +114,18 @@
super(Exception, self).__init__(e)
self.message = "%s: '%s'" % (e.strerror, e.filename)
+
class SpecError(TypeError):
"""
Used for define-time errors with withfile specs.
"""
pass
+
def _parse_doc(docs):
"""
- Converts a well-formed docstring into documentation to be fed into
argparse.
+ Converts a well-formed docstring into documentation
+ to be fed into argparse.
See signature_parser for details.
@@ -131,14 +139,15 @@
name = "(?:[a-zA-Z][a-zA-Z0-9-_]*)"
re_var = re.compile(r"^ *(%s)(?: */(%s))? *:(.*)$" % (name, name))
- re_opt = re.compile(r"^ *(?:(-[a-zA-Z0-9]),? +)?--(%s)(?: *=(%s))?
*:(.*)$" % (name, name))
+ re_opt = re.compile(r"^ *(?:(-[a-zA-Z0-9]),? +)?--(%s)(?: *=(%s))? *:(.*)$"
+ % (name, name))
shorts, metavars, helps, description, epilog = {}, {}, {}, "", ""
if docs:
for line in docs.split("\n"):
-
+
line = line.strip()
#remove starting ':param'
@@ -194,7 +203,6 @@
if line.strip():
previndent = len(line) - len(line.lstrip())
-
return shorts, metavars, helps, description, epilog
@@ -224,8 +232,10 @@
A short introduction to your program.
arg: Help for positional parameter.
- frm/from: Help for a positional parameter with a reserved
public name (i.e.
- this displays to the user as "from" but sets the
"frm" variable)
+ frm/from: Help for a positional parameter
+ with a reserved public name
+ (i.e. this displays to the user as "from"
+ but sets the "frm" variable)
--opt: Help for optional parameter.
-f --flag: An optional parameter that has a short version.
--mode=MODE: An optional parameter that takes a MODE
@@ -246,8 +256,8 @@
NOTE: for this to work, the function's signature must be in-tact
some decorators (like @acceptargv for example) destroy, or
mutilate the signature.
- """
-
+ """
+
args, trail, kwargs, defaults = inspect.getargspec(func)
if not args:
@@ -260,46 +270,49 @@
raise Exception("Can't wrap a function with **kwargs")
# Compulsary positional options
- needed = args[0:len(args)-len(defaults)]
+ needed = args[0:len(args) - len(defaults)]
# Optional flag options
params = args[len(needed):]
shorts, metavars, helps, description, epilog = _parse_doc(func.__doc__)
- parser = argparse.ArgumentParser(description=description, epilog=epilog,
formatter_class=ParagraphPreservingArgParseFormatter)
+ parser = argparse.ArgumentParser(
+ description=description,
+ epilog=epilog,
+ formatter_class=ParagraphPreservingArgParseFormatter)
# special flags
- special_flags=[]
-
+ special_flags = []
+
special_flags += ['debug']
defaults += (False,)
helps['debug'] = 'set logging level to DEBUG'
if module_version(func):
special_flags += ['version']
defaults += (False,)
- helps['version']="show program's version number and exit"
+ helps['version'] = "show program's version number and exit"
params += special_flags
-
+
# Optional flag options
used_shorts = set()
- for param,default in zip(params, defaults):
+ for param, default in zip(params, defaults):
args = ["--%s" % param.replace("_", "-")]
- short=None
+ short = None
if param in shorts:
short = shorts[param]
else:
- if param not in special_flags and len(param)>1:
- first_char=param[0]
+ if param not in special_flags and len(param) > 1:
+ first_char = param[0]
if first_char not in used_shorts:
used_shorts.add(first_char)
short = '-' + first_char
# -h conflicts with 'help'
- if short and short != '-h':
+ if short and short != '-h':
args = [short] + args
kwargs = {'default': default, 'dest': param.replace("-", "_")}
-
+
if param == 'version':
kwargs['action'] = 'version'
kwargs['version'] = module_version(func)
@@ -307,6 +320,18 @@
kwargs['action'] = 'store_false'
elif default is False:
kwargs['action'] = 'store_true'
+ elif isinstance(default, list):
+ kwargs['action'] = 'append'
+# default is not working
+# if len(default):
+# first = default[0]
+# if type(first) in [type(None), unicode]:
+# kwargs['type'] = unidecode
+# else:
+# kwargs['type'] = type(first)
+# kwargs['default'] = []
+# else:
+ kwargs['type'] = unidecode
else:
kwargs['action'] = 'store'
if type(default) in [type(None), unicode]:
@@ -339,7 +364,7 @@
# The trailing arguments
if trail:
- kwargs = {'action':'store', 'type': unidecode, 'nargs':"*"}
+ kwargs = {'action': 'store', 'type': unidecode, 'nargs': "*"}
if trail in helps:
kwargs['help'] = helps[trail]
@@ -350,9 +375,10 @@
kwargs['metavar'] = trail
parser.add_argument('__args', **kwargs)
-
+
return parser
+
def _correct_args(func, kwargs):
"""
Convert a dictionary of arguments including __argv into a list
@@ -361,11 +387,12 @@
args = inspect.getargspec(func)[0]
return [kwargs[arg] for arg in args] + kwargs['__args']
+
def entrypoint(func):
"""
A decorator for your main() function.
- Really a combination of @autorun and @acceptargv, so will run the
+ Really a combination of @autorun and @acceptargv, so will run the
function if __name__ == '__main__' with arguments extricated from
argparse.
@@ -376,7 +403,7 @@
As with @autorun, this must be theoutermost decorator, as any
decorators further out will not be applied to the function until after
it is run.
- """
+ """
frame_local = sys._getframe(1).f_locals
if '__name__' in frame_local and frame_local['__name__'] == '__main__':
argv = sys.argv[1:]
@@ -384,32 +411,33 @@
parser = signature_parser(func)
try:
kwargs = parser.parse_args(argv).__dict__
-
+
# special cli flags
-
+
# --version is handled by ArgParse
#if kwargs.get('version'):
# print module_version(func)
# return
if 'version' in kwargs.keys():
del kwargs['version']
-
+
# --debug
+ FORMAT = '%(asctime)-6s: %(name)s - %(levelname)s - %(message)s'
if kwargs.get('debug'):
logging.basicConfig(
- level=logging.DEBUG,
- format='%(asctime)-6s: %(name)s -
%(levelname)s - %(message)s',
- )
+ level=logging.DEBUG,
+ format=FORMAT,
+ )
del kwargs['debug']
-
+
if "__args" in kwargs:
return func(*_correct_args(func, kwargs))
else:
return func(**kwargs)
-
+
except UsageError, e:
parser.error(e.message)
-
+
return func
#def entrywithfile(*argspec, **kwspec):
@@ -440,6 +468,7 @@
# define_time = withfile(*argspec, **kwspec)
# return lambda func: autorun(define_time(func),2)
+
def autorun(func, _depth=1):
"""
Runs the function if the module in which it is declared is being run
@@ -451,15 +480,16 @@
NOTE: This will work most expectedly as the outermost decorator, as it
will call the function before any more outwards decorators have been
- applied.
+ applied.
"""
frame_local = sys._getframe(_depth).f_locals
if '__name__' in frame_local and frame_local['__name__'] == '__main__':
- func(argv = sys.argv[1:])
+ func(argv=sys.argv[1:])
return func
+
def acceptargv(func):
"""
Transforms the signature of the function, and it's associated __doc__
@@ -483,35 +513,34 @@
parser = signature_parser(func)
def main(*args, **kw):
- argv=kw.get('argv', None)
+ argv = kw.get('argv', None)
if argv == None:
return func(*args, **kw)
else:
try:
kwargs = parser.parse_args(argv).__dict__
-
+
# special cli flags
-
+
# --version is handled by ArgParse
#if kwargs.get('version'):
# print module_version(func)
# return
if 'version' in kwargs.keys():
del kwargs['version']
-
+
# --debug
if kwargs.get('debug'):
logging.basicConfig(level=logging.DEBUG)
del kwargs['debug']
-
-
+
if "__args" in kwargs:
return func(*_correct_args(func, kwargs))
else:
return func(**kwargs)
except UsageError, e:
parser.error(e.message)
-
+
main.__doc__ = func.__doc__
main.__name__ = func.__name__
main.__module__ = func.__module__
@@ -650,4 +679,6 @@
# define_time.__usage_errors = False
# return define_time
-__all__ = ['UsageError', 'FileUsageError', 'acceptargv', 'argparse',
'autorun', 'entrypoint', 'entrywithfile', 'runwithfile', 'signature_parser',
'withfile', 'withuserfile']
+__all__ = ['UsageError', 'FileUsageError', 'acceptargv', 'argparse',
+ 'autorun', 'entrypoint', 'entrywithfile', 'runwithfile',
+ 'signature_parser', 'withfile', 'withuserfile']
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/entrypoint2-0.0.5/entrypoint2/examples/hello.py
new/entrypoint2-0.0.6/entrypoint2/examples/hello.py
--- old/entrypoint2-0.0.5/entrypoint2/examples/hello.py 2012-03-09
16:34:49.000000000 +0100
+++ new/entrypoint2-0.0.6/entrypoint2/examples/hello.py 2012-05-17
16:22:43.000000000 +0200
@@ -3,8 +3,9 @@
__version__ = '3.2'
+
@entrypoint
-def add(one, two=4, three=False):
+def add(one, two=4, three=False):
''' This function adds two number.
:param one: first number to add
@@ -12,8 +13,8 @@
:rtype: int
'''
s = str(int(one) + int(two))
-
+
logging.debug('logging sum from hello.py:' + s)
- print 'printing sum from hello.py:', s
-
+ print 'printing sum from hello.py:', s
+
return s
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/entrypoint2-0.0.5/entrypoint2/examples/repeating.py
new/entrypoint2-0.0.6/entrypoint2/examples/repeating.py
--- old/entrypoint2-0.0.5/entrypoint2/examples/repeating.py 1970-01-01
01:00:00.000000000 +0100
+++ new/entrypoint2-0.0.6/entrypoint2/examples/repeating.py 2012-05-17
10:57:20.000000000 +0200
@@ -0,0 +1,9 @@
+from entrypoint2 import entrypoint
+
+
+@entrypoint
+def main(files=[]):
+ ''' This function has repeating arguments.
+ :param files: test input
+ '''
+ print files
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/entrypoint2-0.0.5/entrypoint2.egg-info/PKG-INFO
new/entrypoint2-0.0.6/entrypoint2.egg-info/PKG-INFO
--- old/entrypoint2-0.0.5/entrypoint2.egg-info/PKG-INFO 2012-03-10
09:36:55.000000000 +0100
+++ new/entrypoint2-0.0.6/entrypoint2.egg-info/PKG-INFO 2012-05-17
16:54:00.000000000 +0200
@@ -1,81 +1,58 @@
Metadata-Version: 1.0
Name: entrypoint2
-Version: 0.0.5
+Version: 0.0.6
Summary: easy to use command-line interface for python modules, fork of
entrypoint
Home-page: https://github.com/ponty/entrypoint2
Author: ponty
Author-email: UNKNOWN
License: BSD
-Description: entrypoint2 is an easy to use command-line interface for python
modules, fork of `entrypoint <http://pypi.python.org/pypi/entrypoint/>`_
+Description: entrypoint2 is an easy to use argparse_ based command-line
interface for python modules, fork of `entrypoint
<http://pypi.python.org/pypi/entrypoint/>`_.
+ It translates function signature and documentation to argparse_
configuration.
Links:
+
* home: https://github.com/ponty/entrypoint2
* documentation: http://ponty.github.com/entrypoint2
+ Goals:
- Background
- ============
+ - simplicity: only one decorator to add to existing code
+
+ Features:
- 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
+ - good for protoyping or simple CLI
- 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
- ================
-
- * `entrypoint <http://pypi.python.org/pypi/entrypoint/>`_
- * `plac <http://micheles.googlecode.com/hg/plac/doc/plac.html>`_
- * `baker <http://bitbucket.org/mchaput/baker>`_
- * `argh <http://packages.python.org/argh/>`_
- * `opster <http://pypi.python.org/pypi/opster/>`_
- * `commandline <http://pypi.python.org/pypi/commandline>`_
- * `optfunc <https://github.com/simonw/optfunc>`_: it has the same
concept
- * `commando (1) <http://freshmeat.net/projects/commando>`_
- * `commando (2) <https://github.com/lakshmivyas/commando>`_
-
- Features
- ============
-
- Additional features over original entrypoint_:
+ - the decorated function has the same behavior as without the
entrypoint2 decorator
+ - boolean parameters are toggle flags (e.g. ``--verbose``)
- 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``)
+ - short flags are generated from long flags automatically (e.g.
``--parameter`` -> ``-p``)
- unit tests
- supported python versions: 2.5, 2.6, 2.7, 3.1, 3.2, PyPy
+ - support for repeating arguments
Known problems:
- - there are more decorators in the module inherited from original
entrypoint_,
- but only @entrypoint is tested.
+ - None.
+
+ Similar projects:
+
+ * `entrypoint <http://pypi.python.org/pypi/entrypoint/>`_
+ * `plac <http://micheles.googlecode.com/hg/plac/doc/plac.html>`_
+ * `baker <http://bitbucket.org/mchaput/baker>`_
+ * `argh <http://packages.python.org/argh/>`_
+ * `opster <http://pypi.python.org/pypi/opster/>`_
+ * `commandline <http://pypi.python.org/pypi/commandline>`_
+ * `optfunc <https://github.com/simonw/optfunc>`_: this has the same
concept
+ * `commando (1) <http://freshmeat.net/projects/commando>`_
+ * `commando (2) <https://github.com/lakshmivyas/commando>`_
+ * argparse_
+ * `optparse <http://docs.python.org/library/optparse.html>`_
Basic usage
============
@@ -120,8 +97,7 @@
Installation
============
- General
- --------
+ General:
* install pip_
* install the program::
@@ -129,16 +105,12 @@
# as root
pip install entrypoint2
- Ubuntu
- ----------
- ::
+ Ubuntu::
sudo apt-get install python-pip
sudo pip install entrypoint2
- Uninstall
- ----------
- ::
+ Uninstall::
# as root
pip uninstall entrypoint2
@@ -148,6 +120,8 @@
.. _pip: http://pip.openplans.org/
.. _entrypoint: http://pypi.python.org/pypi/entrypoint/
.. _autodoc: http://sphinx.pocoo.org/ext/autodoc.html
+ .. _argparse: http://docs.python.org/dev/library/argparse.html
+
Keywords: argparse decorator optparse signature command-line
Platform: UNKNOWN
Classifier: License :: OSI Approved :: BSD License
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/entrypoint2-0.0.5/entrypoint2.egg-info/SOURCES.txt
new/entrypoint2-0.0.6/entrypoint2.egg-info/SOURCES.txt
--- old/entrypoint2-0.0.5/entrypoint2.egg-info/SOURCES.txt 2012-03-10
09:36:56.000000000 +0100
+++ new/entrypoint2-0.0.6/entrypoint2.egg-info/SOURCES.txt 2012-05-17
16:54:00.000000000 +0200
@@ -20,4 +20,5 @@
entrypoint2.egg-info/top_level.txt
entrypoint2/examples/__init__.py
entrypoint2/examples/caller.py
-entrypoint2/examples/hello.py
\ No newline at end of file
+entrypoint2/examples/hello.py
+entrypoint2/examples/repeating.py
\ No newline at end of file
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]