Comment 13 for bug 366353

Revision history for this message
Brian Granger (ellisonbg) wrote : Re: [Bug 366353] Re: %run doesn't work with paths returned by tempfile.NamedTemporaryFile()

I have added a new function to platutils that can expand the "~" in
Windows paths:

In [1]: import tempfile

In [2]: import os

In [3]: from IPython.platutils import get_long_path_name

In [4]: f = tempfile.NamedTemporaryFile(suffix='.py')

In [5]: f.write('pass\n')

In [6]: name = f.name

In [7]: bname = get_long_path_name(name)

In [10]: name
Out[10]: 'c:\\docume~1\\admini~1\\locals~1\\temp\\tmpixcmwt.py'

In [11]: bname
Out[11]: u'c:\\Documents and Settings\\Administrator\\Local
Settings\\Temp\\tmpixcmwt.py'

In [8]: %run $name
ERROR: File `c:docume~1admini~1locals~1temptmpixcmwt.py` not found.

In [9]: %run $bname
ERROR: File `c:Documents.py` not found.

Run chokes on both forms of Windows paths. I have tracked the problem
down to line 1557 of Magic.py:

        opts,arg_lst = self.parse_options(parameter_s,'nidtN:b:pD:l:rs:T:e',
                                          mode='list',list_all=1)

Here the parse_options method is where the paths get messed up. If
the path has spaces, parse_options is splitting on the spaces and only
returning the first part of the path. If the path has the "~" chars,
it somehow deletes the ""\\"" path separators. I don't have time to
fix this now, but that is what is wrong.