Skip to content

use argparse to parse aliases & flags #674

Merged
merged 5 commits into from Aug 18, 2011

3 participants

@minrk
IPython member
minrk commented Aug 4, 2011

This is a first step towards using argparse as the main parser, and it was pretty trivial to implement. The only change to existing code is moving a few generic blocks of the KVLoader to the parent class, so they could be reused in the new sibling. Other than that, simply changing the import in config.application was all it took.

We probably want a better implementation, but this appears to solve the immediate problem of not being able to do things like:

ipython --pylab qt and ipcluster start -n 4. anything argparse did not recognize (e.g. full --Class.trait=value simply get passed to the stricter KV loader.

Note that this does not use argparse's tools for handling types, etc. It's strictly for mapping names to be eval'd.

I don't expect this to be merged as-is, but it's a placeholder for discussion or something better.

ref #563

@epatters
epatters commented Aug 4, 2011

Great, thanks for this!

The fact that we're not using argparse has caused me a great deal of frustration in trying to pass arguments to the kernel launch script, particularly on Windows. I'm glad this will be resolved.

@minrk
IPython member
minrk commented Aug 4, 2011

An ideal situation would be to use argparse for everything, since we could do pretty clever things with types, nargs, etc. building a parser from traitlets. But since we must generate the parser at launch, the construction would probably add a great deal to the startup time, which would be pretty rough.

With this as it is, I think the only thing we get is allowing spaces between name and value :)

@epatters
epatters commented Aug 4, 2011

But that's actually what's important to me: I can pass extra_args=['--c', 'some code'] to the kernel launch function and let Popen escape the code argument. Currently, I have to do extra_args=['--c="my code"'] and worry about everything being escaped properly. Painful, especially on Windows.

@fperez fperez merged commit 832789b into ipython:master Aug 18, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.