Comment 16 for bug 72227

Revision history for this message
Forest Bond (forest-bond) wrote : Re: [Bug 72227] Re: should avoid loading modules from working directory

Howdie,

On Thu, Jul 16, 2009 at 01:30:42PM -0000, Harald Meland wrote:
> On Thu, Jul 16, 2009 at 2:36 PM, Forest Bond<email address hidden> wrote:
> > Harald,
> >
> > I'm afraid what you're saying isn't adding up.  I can see from your test
> > script that the CWD is in your sys.path.  That clearly indicates that
> > modules in your CWD should get imported.
>
> The _script directory_ is in my sys.path. When I run my test script
> as "./test.py", the script directory and the CWD coincide. However,
> as my bzr typically isn't run as "./bzr" when I'm in danger of
> triggering this bug, the CWD will not be in my sys.path.

... then ./test.py isn't very helpful in diagnosing the problem.

[~]
09:54 forest@W038$ mkdir /tmp/foo
[~]
09:54 forest@W038$ echo 'import sys; print sys.path' >/tmp/foo/test.py
[~]
09:54 forest@W038$ mkdir /tmp/bar
[~]
09:54 forest@W038$ cd /tmp/bar
[/tmp/bar]
09:54 forest@W038$ python /tmp/foo/test.py
['/tmp/foo', '/home/forest/usr/lib/python2.5/site-packages/setuptools-0.6c9-py2.5.egg', '/home/forest/usr/lib/python2.5/site-packages/Satchmo-0.9_pre-py2.5.egg', '/home/forest/lib/python', '/home/forest/usr/lib/python2.6/site-packages', '/home/forest/usr/lib/python2.5/site-packages', '/home/forest/usr/lib/python2.4/site-packages', '/home/forest/usr/lib/python2.3/site-packages', '/tmp/bar', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages/PIL', '/usr/lib/python2.6/dist-packages/gst-0.10', '/var/lib/python-support/python2.6', '/usr/lib/python2.6/dist-packages/gtk-2.0', '/var/lib/python-support/python2.6/gtk-2.0', '/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode', '/usr/local/lib/python2.6/dist-packages', '/home/forest/usr/lib/python2.4/site-packages', '/home/forest/usr/lib/python2.3/site-packages']
[/tmp/bar]
09:54 forest@W038$ python -S /tmp/foo/test.py
['/tmp/foo', '/home/forest/lib/python', '/home/forest/usr/lib/python2.6/site-packages', '/home/forest/usr/lib/python2.5/site-packages', '/home/forest/usr/lib/python2.4/site-packages', '/home/forest/usr/lib/python2.3/site-packages', '', '/usr/lib/python2.6/', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload']

> My thinking is that if the fix for this issue is as simple as removing
> any empty-string elements from sys.path (on Python installations that
> somehow isn't conforming to the sys.path documentation I linked to),
> then that should be easy to fix.
>
> If, on the other hand, your python somehow includes one or more
> absolute path to directories that we don't really want to import
> modules from, the fix might have to be more involved (one possible
> remedy in this case might be to run Python with the -S command-line
> option).

-S isn't great. What if I have bzr plugins installed paths set up by the site
module (likely)?

Thanks,
Forest
--
Forest Bond
http://www.alittletooquiet.net
http://www.pytagsfs.org