From: Michele Simionato on
A few weeks ago I presented on this list my most recent effort, plac.
Now there is a *huge* new release:
the size of plac and of its documentation doubled.

Now plac is much more than a simple command-line arguments parser: it
is
also a generic tool to write command languages, similar to the cmd
module in the standard library, only better. In particular plac
supports
a doctests-like functionality for each language you define for it,
as well as a plac runner to run your scripts and tests.

You define plac commands from Python functions: plac will build
a parser from the function signature and interpret the command line
accordingly.

The documentation contains a lot of simple and not so simple examples:

http://micheles.googlecode.com/hg/plac/doc/plac.html
http://micheles.googlecode.com/hg/plac/doc/plac_ext.html

Plac works in all versions of Python starting from Python 2.3 up to
Python 3.1, but the new features require Python 2.5.

You can download it from PyPI ($ easy_install -U plac):

http://pypi.python.org/pypi/plac

Enjoy!

Michele Simionato
From: Andre Alexander Bell on
On 06/20/2010 11:22 AM, Michele Simionato wrote:
> A few weeks ago I presented on this list my most recent effort, plac.
> Now there is a *huge* new release:
> the size of plac and of its documentation doubled.

How about adding some support for internationalization of the generated
usage output?


Andre
From: Michele Simionato on
On Jun 20, 12:02 pm, Andre Alexander Bell <p...(a)andre-bell.de> wrote:
>
> How about adding some support for internationalization of the generated
> usage output?

The usage message of plac is actually generated by the underlying
argparse library. argparse use gettext internally, so I would say the
support is already there.
From: Andre Alexander Bell on
On 06/20/2010 11:22 AM, Michele Simionato wrote:
> A few weeks ago I presented on this list my most recent effort, plac.
> Now there is a *huge* new release:
> the size of plac and of its documentation doubled.
> [...]
>
> http://micheles.googlecode.com/hg/plac/doc/plac.html

I've read this one...

> http://micheles.googlecode.com/hg/plac/doc/plac_ext.html

But this one is broken. :(

How about hierarchical composition. I've seen several scripts following
the format

basescript command [options] subcommands [other optiones] ...

It would be great if one can compose functions to form the commands.
Instead of

def main(command, opt1, opt2):
"""..."""
if command == 'cmd1':
...
elif command == 'cmd2':
...

if __name__=='__main__':
import plac
plac.call(main)

one could then write

def cmd1(opt1):
"""..."""
...

def cmd2(opt2):
"""..."""
...

if __name__=='__main__':
import plac
plac.call(plac.commands(cmd1, cmd2))

This should then produce usage info like this

$ basescript --help
usage: basescript [-h] command

....

commands:
cmd1
cmd2

$ basescript cmd1 --help
usage basescript cmd1 [cmd1 specific options]
....

$ basescript cmd2 --help
usage basescript cmd2 [cmd2 specific options]
....

Maybe one could even extend to subcommands and so on.
Maybe this is already possible but just not covered by the first link
I've read by now.
Anyway, I very much like this package and it seems like I have a new
friend at my disposal.

Thanks and best regards


Andre
From: Michele Simionato on
On Jun 20, 8:26 pm, Andre Alexander Bell <p...(a)andre-bell.de> wrote:
> On 06/20/2010 11:22 AM, Michele Simionato wrote:
>
> > A few weeks ago I presented on this list my most recent effort, plac.
> >  http://micheles.googlecode.com/hg/plac/doc/plac_ext.html
>
> But this one is broken. :(

Aagh! The good one is http://micheles.googlecode.com/hg/plac/doc/plac_adv.html.
Luckily the one I posted on PyPI is correct.

><snip>
> Maybe one could even extend to subcommands and so on.
> Maybe this is already possible but just not covered by the first link
> I've read by now.

Indeed this is already possible and covered in the advanced document.
See the section containers of commands:

http://micheles.googlecode.com/hg/plac/doc/plac_adv.html#containers-of-commands