Giter VIP home page Giter VIP logo

plac's People

Contributors

micheles avatar

plac's Issues

"raise etype, exc, tb" - python gives syntax error

What steps will reproduce the problem?
1. install python 3.2.3 and plac 0.9.1
2. in plac doc folder execute "example3.py foo"


What is the expected output? What do you see instead?

expected:
foo

instead:
Traceback (most recent call last):
  File "C:\Setup\ heruntergeladen\Python\plac-0.9.1.tar\dist\plac-0.9.1\doc\example3.py", line 8, in <module>
    import plac; plac.call(main)
  File "C:\run\Python\lib\site-packages\plac.py", line 35, in <module>
    from plac_ext import (Interpreter, import_main, ReadlineInput,
  File "C:\run\Python\lib\site-packages\plac_ext.py", line 33
    raise etype, exc, tb
               ^
SyntaxError: invalid syntax


What version of the product are you using? On what operating system?
Windows 7
Python 3.2.3
plac-0.9.1.tar.gz, downloaded from PyPi, installed via "python setup.py install"


Please provide any additional information below.
i have seen this multible tracebacks thing anywhere, but cant find it anymore, 
isnt that a new python 3.x thing?

Original issue reported on code.google.com by [email protected] on 2 Jul 2012 at 5:18

Does not support dashes in long arguments

plac currently requires option names to be valid python identifiers, so it is 
impossible to have an option like "--dry-run". You have to use "--dry_run" 
instead, which is awkward because it has both dashes and underscores in it. 
This can be fixed with just a one-line patch that replaces underscores with 
dashes in option names before calling add_argument.

I'm including the patch below. It includes two possibilities: either accept 
*only* dashed options, or accept options with either dashes or underscores, 
which would be more backward-compatible, but sometimes confusing in the help 
screen.

$ hg diff -w plac_core.py              
diff --git a/plac_core.py b/plac_core.py
--- a/plac_core.py
+++ b/plac_core.py
@@ -255,6 +255,10 @@
                     shortlong = (prefix + a.abbrev, prefix*2 + name)
                 else:
                     shortlong = (prefix + name,)
+                # Replace underscores with dashes in argument names
+                # shortlong = [ s.replace('_', '-') for s in shortlong ]
+                # # Accept either dashes or underscores
+                shortlong = tuple([ s.replace('_', '-') for s in shortlong if 
s.find('_') != -1 ]) + shortlong
             elif default is NONE: # required argument
                 self.add_argument(name, help=a.help, type=a.type, 
                                    choices=a.choices, metavar=metavar)

Original issue reported on code.google.com by [email protected] on 16 Dec 2011 at 1:01

Make plac parser object easily available during execution

In some cases, the programmer has to perform additional validation of arguments 
beyond what is possible in Plac (for example, when arguments depend on each 
other or conflict with each other). When doing this additional validation, it 
would be nice to be able to print an error message followed by the script's 
help text, or simply print the help text by itself. I have an example 
implementation of this (linked below), but it's imperfect because it requires 
you to tell it how far up the stack the "main" function is. I wonder if it is 
possible to make available the "currently active" plac parser object, i.e. the 
parser generated by the latest call to "plac.call".

https://github.com/DarwinAwardWinner/placsupport/blob/master/placsupport/__init_
_.py

Original issue reported on code.google.com by [email protected] on 17 Jun 2012 at 8:39

Corrections to docs and examples

Please find some corrections to docs and examples: 
<http://code.google.com/r/nicolalarosa-plac/source/detail?r=cd156d9657bb60056e47
e202c419a71d118c0b91>.

Thanks for plac!

Original issue reported on code.google.com by [email protected] on 8 Apr 2013 at 11:21

test_cmds fails with python 3.3.1

What steps will reproduce the problem?
1. download plac-0.9.1.tar.gz from pypi
2. install to python 3.3.1 with 
    py -3.3 setup.py install 
(this is equivalent to c:\python33\python.exe setup.py install)

3. cd plac-0.9.1
   py -3.3 test_plac.py

What is the expected output?

A message telling all ok or no output at all

 What do you see instead?
D:\tmp\plac-0.9.1\doc>py -3 test_plac.py
Running test_batch
Running test_cmd_abbrevs
usage: test_plac.py {help,commit} ...
test_plac.py: error: No command 'foo'
Running test_cmds
Traceback (most recent call last):
  File "test_plac.py", line 230, in <module>
    maybegen = test()
  File "test_plac.py", line 184, in test_cmds
    expect(SystemExit, plac.call, cmds, [])
  File "test_plac.py", line 18, in expect
    func(*args, **kw)
  File "C:\Python33\lib\site-packages\plac-0.9.1-py3.3.egg\plac_core.py", line 3
09, in call
    cmd, result = parser_from(obj).consume(arglist)
  File "C:\Python33\lib\site-packages\plac-0.9.1-py3.3.egg\plac_core.py", line 1
89, in consume
    args = [getattr(ns, a) for a in self.argspec.args]
AttributeError: 'ArgumentParser' object has no attribute 'argspec'


What version of the product are you using? On what operating system?
plac 0.9.1
On windows xp sp3

Please provide any additional information below.
Installing and testing to python 2.7 shows no error.

Running test_plac.py in py 3.3.1 with  pytest 2.3.5 tells that it is the only 
test failing in the file, (besides the one for sqlalchemy, which fails because 
the module is missing)

Additionally, deprecation warnings are seen for module imp. 

Original issue reported on code.google.com by [email protected] on 9 May 2013 at 10:49

Not providing positional args when using a container class will not print out descriptive info with -h/help

def main():
    plac.Interpreter.(FooContainer)

class FooContainer(object):
    [...]
    commands=('foo_command',)
    @plac.annotate(
        foo="The default argument"
    )
    def __init__(self, foo):
        self.foo = foo

then run foo.py and get:

$  ./foo.py -h
usage: foo.py [-i] foo [args [args ...]]
foo.py: error: too few arguments


What is the expected output? What do you see instead?

For a user, it's important to know what the first argument can/should be.  the 
examples indicate that this can be done by outputting examples as though the 
full help messages, including annotations for the constructor of the container, 
but in practice I can't get this output. 

What version of the product are you using? On what operating system?
0.9 with argparse 1.2.1 on solaris 10.




Original issue reported on code.google.com by [email protected] on 14 Jul 2011 at 9:01

`plac cmd -h` dies if docstring contains unicode character

What steps will reproduce the problem?
1. Define a command; insert unicode character into docstring
2. Attempt to print script's help

Expect to see the help string; instead experience a stack trace.

pip show plac

---
Name: plac
Version: 0.9.1

See attached test case. Use with:

python test.py -h

See attached patch for one way to fix.


Original issue reported on code.google.com by [email protected] on 20 Jan 2015 at 7:57

Attachments:

There seems to be no way to implement global arguments when using subcommands

I have a script with two subcommands (say install and update), and I want to 
add a argument that is common to all subcommands (verbose), in order to do this 
:

python myscript.py -v install
or
python myscript.py -v update

without having to write the code to handle -v twice.

I couln't find it in the docs nor by reading the code. Is there a way to do so 
? If I think this is a valid use case.

Original issue reported on code.google.com by [email protected] on 6 Feb 2012 at 9:50

AttributeError when using Interpreter Class

Use the same example from the tutorial (ishelve), I'm using python2.7 on amd64 
Arch Linux.

What is the expected output? What do you see instead?
There is the following traceback:

python2.7 ishelve_i.py -i
Traceback (most recent call last):
  File "ishelve_i.py", line 19, in <module>
    plac.call(main)
  File "/usr/lib/python2.7/site-packages/plac_core.py", line 309, in call
    cmd, result = parser_from(obj).consume(arglist)
  File "/usr/lib/python2.7/site-packages/plac_core.py", line 195, in consume
    return cmd, self.func(*(args + varargs + extraopts), **kwargs)
  File "ishelve_i.py", line 13, in main
    plac.Interpreter(ishelve.main).interact()
  File "/usr/lib/python2.7/site-packages/plac_ext.py", line 805, in __init__
    self.tm = TaskManager(obj)
  File "/usr/lib/python2.7/site-packages/plac_ext.py", line 482, in __init__
    obj, prog='' if interact else None, formatter_class=PlacFormatter)
  File "/usr/lib/python2.7/site-packages/plac_core.py", line 127, in parser_from
    parser.populate_from(obj)
  File "/usr/lib/python2.7/site-packages/plac_core.py", line 275, in populate_from
    self.add_argument(action='store_true', help=a.help, *shortlong)
  File "/usr/lib/python2.7/argparse.py", line 1291, in add_argument
    self._get_formatter()._format_args(action, None)
  File "/usr/lib/python2.7/argparse.py", line 572, in _format_args
    get_metavar = self._metavar_formatter(action, default_metavar)
  File "/usr/lib/python2.7/site-packages/plac_ext.py", line 165, in _metavar_formatter
    action.choices = dict((n, c) for n, c in action.choices.iteritems()
AttributeError: 'NoneType' object has no attribute 'iteritems'
[1]    7853 exit 1     python2.7 ishelve_i.py -i

What version of the product are you using? On what operating system?
plac 0.9.0, Python 2.7.2

Please provide any additional information below.

Original issue reported on code.google.com by [email protected] on 31 Oct 2011 at 8:28

Using global options with sub-commands

I know that this was already raised here 
(https://code.google.com/p/plac/issues/detail?id=8) and was declared invalid, 
but my use-case is quite different so might be reconsidered?

If you consider svn as an example of a program with sub-commands, you might 
want to have an `svn --version` option. This is a global setting that should 
always have the same effect, independent of the sub-command and in fact should 
work without a sub-command. 

If there is already a way to achieve this, I'd appreciate your help.

Thanks,
David

Original issue reported on code.google.com by [email protected] on 9 Aug 2013 at 11:45

rethink the import_main mechanism

The problem is that imp.load_module is not looking in the current directory in 
the search path. You can see the problem with

$ plac_runner.py doc/ishelve3.py 

or

$ plac_runner.py doc/ishelve2.py 

not finding ishelve2.py

Original issue reported on code.google.com by [email protected] on 19 Jun 2011 at 9:37

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.