[IPython-dev] filename completion - anyone working on it?
Hans Meine
hans_meine at gmx.net
Mon Nov 1 05:55:26 EDT 2010
Hi Fernando!
Op den Dingsdag 26 Oktober 2010 Klock 21:15:40 hett Fernando Perez schreven:
> On Tue, Oct 26, 2010 at 6:31 AM, Hans Meine <hans_meine at gmx.net> wrote:
> > I am constantly bugged by filename completion in IPython. To be
> > specific, there are two cases that maybe need to be considered
> > separately: 1) Completion of filenames in arguments to IPython magics,
> > e.g. %run foo<tab> 2) Completion of filenames in strings, i.e. filename
> > = "../subdir/bar<tab>"
>
> Could you pull from trunk and let me know if you find the situation
> any better? Invoking my time machine for your question, I rewound to
> yesterday afternoon and put more time than I'd like to admit into this
> very problem:
Aaah, I love it when you pull that trick! :-)
> Things already work as you imagine, with a custom completer for magics
> without quotes, and a generic file completer that should work in
> strings. This weekend John and I actually ran into the limitations of
> the completions-in-strings, and that prompted my effort to fix this.
The strange thing is - I updated my git repo and tried it out, and it was
certainly working to some extent (read: at least some completions I tried with
paths containing spaces did work, so I was happy). I planned to try it out
more thoroughly for some days before reporting back, but right now I tried
again (with updated git master), and it does not work at all anymore?!
(OK, it's monday morning, but...)
I tried the following two versions:
current HEAD, i.e. commit bd2a307834c957701bf36e3552ff4072c6bf3d78,
reporting as "0.11.dev" on startup, and
commit 02eecaf061408f26a3c6029886b8794f73581938, which you pointed me to,
reporting as "0.11.alpha1.git" on startup.
Both seem to behave identically.
Given a directory "../Daten/FLIM/1004 Nadine", I tried to <tab>-complete like
this:
a = "../Daten/FLIM/1004<tab>
-> gives proper completion list, and adds a space (which then fails as below)
a = "../Daten/FLIM/1004 <tab>
%run foo.py "../Daten/FLIM/1004 <tab>
-> fails, gives wrong / default completions
%run "../Daten/FLIM/1004 <tab>
-> fails: gives correct completion list, but adds the full prefix again on
every <tab> press.
The last one looks easy to fix though, and seems to be the only case where
pressing <tab> *behind* a space in a filename takes the previous part into
account.
The test suite mostly runs fine, though - I get one error because of a
missing/inaccessible /usr/games/bin, and two failures which seem to be related
to output formatting/coloring:
======================================================================
FAIL: Test that object's __del__ methods are called on exit.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib64/python2.6/site-packages/nose/case.py", line 186, in runTest
self.test(*self.arg)
File
"/informatik/home/meine/Programming/ipython/IPython/testing/decorators.py",
line 225, in skipper_func
return f(*args, **kwargs)
File
"/informatik/home/meine/Programming/ipython/IPython/core/tests/test_run.py",
line 172, in test_obj_del
tt.ipexec_validate(self.fname, 'object A deleted')
File "/informatik/home/meine/Programming/ipython/IPython/testing/tools.py",
line 252, in ipexec_validate
nt.assert_equals(out.strip(), expected_out.strip())
AssertionError: '\x1b[?1034hobject A deleted' != 'object A deleted'
>> raise self.failureException, \
(None or '%r != %r' % ('\x1b[?1034hobject A deleted', 'object A
deleted'))
======================================================================
FAIL: IPython.core.tests.test_run.TestMagicRunSimple.test_tclass
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib64/python2.6/site-packages/nose/case.py", line 186, in runTest
self.test(*self.arg)
File
"/informatik/home/meine/Programming/ipython/IPython/testing/decorators.py",
line 225, in skipper_func
return f(*args, **kwargs)
File
"/informatik/home/meine/Programming/ipython/IPython/core/tests/test_run.py",
line 186, in test_tclass
tt.ipexec_validate(self.fname, out)
File "/informatik/home/meine/Programming/ipython/IPython/testing/tools.py",
line 252, in ipexec_validate
nt.assert_equals(out.strip(), expected_out.strip())
AssertionError: "\x1b[?1034hARGV 1-: ['C-first']\nARGV 1-: ['C-
second']\ntclass.py: deleting object: C-first" != "ARGV 1-: ['C-first']\nARGV
1-: ['C-second']\ntclass.py: deleting object: C-first"
>> raise self.failureException, \
(None or '%r != %r' % ("\x1b[?1034hARGV 1-: ['C-first']\nARGV 1-:
['C-second']\ntclass.py: deleting object: C-first", "ARGV 1-: ['C-
first']\nARGV 1-: ['C-second']\ntclass.py: deleting object: C-first"))
Is there a good way to debug these kind of things? (completion)
I would like to contribute test cases, but they would obviously require some
temp. dir setup, and I don't know yet how to write good unit tests for this.
Given a setup like this:
mkdir tabcomplete && cd $_
mkdir "Test 1"
mkdir "Test 2"
echo 'print "hello world"' > foo.py
echo 'print "from subdir"' > "Test 1/bar.py"
I would expect this to work:
a = "Test<tab> -> should add a space and list 2 possible completions
a = "Test 1/b<tab> -> should fully complete "Test1/bar.py"
a = "Test 1/b<tab>" -> should fully complete "Test1/bar.py" (no 3rd quote)
Similarly:
%run foo.py "Test<tab>
%run foo.py "Test 1/b<tab>
%run "Test<tab>
%run "Test 1/b<tab>
And finally without quotes, too:
%run foo.py Test<tab>
%run foo.py Test\ 1/b<tab>
%run Test<tab>
%run Test\ 1/b<tab>
Thanks,
Hans
More information about the IPython-dev
mailing list