Fix issue #2660: parsing of help and version arguments #2663

Merged
merged 1 commit into from Dec 7, 2012

Conversation

Projects
None yet
3 participants

Help (-h --help --help-all) and version (--version -V) arguments that appear after a bare '--' argument are passed to the script IPython is running (like other arguments), instead of causing IPython itself to
write out help / version info.

Timothy O'Donnell
Fix issue #2660. Help (-h --help --help-all) and version (--version -V)
arguments that appear after a bare '--' argument are passed to the script
IPython is running (like other arguments), instead of causing IPython itself to
write out help / version info.
Contributor

bfroehle commented Dec 7, 2012

Looks fine to me.

Owner

takluyver commented Dec 7, 2012

The only thing I wonder is if we should be even more cautious about finding these arguments. i.e. if you run ipython foo.py -h, I think most people would expect foo.py to be run, rather than displaying IPython's help and exiting.

The Python interpreter only looks at the options before the first 'interface option' - which means a filename, -c or -m. See http://docs.python.org/3/using/cmdline.html

Contributor

bfroehle commented Dec 7, 2012

@takluyver I've looked into this in the past and found that it is quite difficult (i.e., impossible?) to wrangle argparse into this same sort of behavior. There isn't any way to specify that some argument is "final" in the parsing. I'd rather not invest time into writing an argument parser by hand, especially for our complex use case.

I think we should accept this as a workable compromise and move on (for now).

Owner

takluyver commented Dec 7, 2012

But this section of the code isn't even doing anything with argparse - it's
just looking for specific arguments in a list. But anyway, I'm happy to
accept this as is.

On 7 December 2012 18:11, Bradley M. Froehle notifications@github.comwrote:

@takluyver https://github.com/takluyver I've looked into this in the
past and found that it is quite difficult (i.e., impossible?) to wrangle
argparse into this same sort of behavior. There isn't any way to specify
that some argument is "final" in the parsing. I'd rather not invest time
into writing an argument parser by hand, especially for our complex use
case.

I think we should accept this as a workable compromise and move on (for
now).


Reply to this email directly or view it on GitHubhttps://github.com/ipython/ipython/pull/2663#issuecomment-11140183.

Contributor

bfroehle commented Dec 7, 2012

You are right... something like interpreted_argv = argv[:argv.first_index_of('--', '-c', '-m')] would be best. But it's hard to check for the most common case --- a filename.

In addition, since this will get parsed with argparse next the user is probably going to have to use -- to separate IPython arguments from script arguments anyway, so there is little point in doing a more sophisticated check here.

(Or am I wrong about that.. do we check explicitly for -c and -m elsewhere?)

bfroehle added a commit that referenced this pull request Dec 7, 2012

Merge pull request #2663 from timodonnell/dev/timodonnell/bug/2660
Fix issue #2660: parsing of help and version arguments

@bfroehle bfroehle merged commit 591e9b3 into ipython:master Dec 7, 2012

1 check passed

default The Travis build passed
Details

minrk added a commit that referenced this pull request Mar 5, 2013

Backport PR #2663: Fix issue #2660: parsing of help and version argum…
…ents

Help (-h --help --help-all) and version (--version -V) arguments that appear after a bare '--' argument are passed to the script IPython is running (like other arguments), instead of causing IPython itself to
write out help / version info.

mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014

Merge pull request #2663 from timodonnell/dev/timodonnell/bug/2660
Fix issue #2660: parsing of help and version arguments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment