Comment 17 for bug 72227

Revision history for this message
John A Meinel (jameinel) wrote : Re: [Bug 72227] Re: should avoid loading modules from working directory

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

...

> 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]

^- So indeed, /tmp/bar is in your path.

What I've seen in the past, is that if you insert debug statements into
*site.py* it gets a '' in sys.path, and then it calls a function to turn
all paths in 'sys.path' into absolute paths (and thus '' => $PWD).

Obviously you are getting $PWD into your path somehow, the question is
figuring out how.

For bzrlib, one possibility could be to do:

cwd = os.getcwd()
bzr_path = os.path.dirname(sys.argv[0])
if bzr_path != cwd:
  while cwd in sys.path:
    sys.path.remove(cwd)

Alternatively, if we do it in the 'bzr' main script, we can change the
line to:

bzr_path = os.path.dirname(__file__)

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkpfN38ACgkQJdeBCYSNAANh7QCgtPkEGdc4GykL51ahAQa4LADT
VMUAn3PAW7mNRidgRdJnDeCOrYiAO3Ol
=pIQS
-----END PGP SIGNATURE-----