[MERGE][1.0] disable python imports from cwd (problem with python2.4 @ win32: bug #53478)

Martin Pool mbp at sourcefrog.net
Mon Nov 26 01:22:35 GMT 2007


On Nov 25, 2007 2:42 AM, Alexander Belchenko <bialix at ukr.net> wrote:

> >> Proposed patch fixes all possible variants and works with 2.4 and 2.5.
> >> In my strong opinion we should not manipulate with sys.path in bzrlib itself,
> >> only in bzr script. Therefore I did only manual testing.
> >
> > I would think that run_bzr_subprocess could be used to test this.
>
> And provide some fake bzrlib in temp dir? It's doable.

Yes, I'd suggest creating a bzrlib/__init__.py that raises an error.

> >> +if os.getcwd() in sys.path[1:]:     # skip first item
> >> +    sys.path.pop(sys.path.index(os.getcwd(),1))
> >
> > So if you run bzr in the directory where it's installed, I think this
> > could remove the only reference to the bzrlib directory, and prevent
> > bzrlib from loading.  Similarly, it could remove references to other
> > paths needed for Bazaar to run.
>
> Yes. Exactly. If you read all comments you'll see that I think this problem
> can not be solved for all possible use cases. Checking that os.getcwd()
> is not C:\Python25\Lib\site-packages or similar path on Linux -- is too much IMO.

I think this would also break my common usage of "./bzr selftest", therefore

bb: resubmit

You could try looking at the path of bzr, and allowing that directory
to be in the sys.path even if it's the same as the cwd.

On ubuntu, the first element is also the absolute cwd.

> Actually I don't think the bug #53478 it's the bzr bug. And your comment only confirm this.
> This bug only affects Python 2.4, not Python 2.5.
>
> I really prefer to do not "fix" it.

This was also reported by someone using bzr to version a python tree
containing logging.py; it can happen whenever they shadow a builtin
module.

I'm ok to just document this as a python bug and say won't fix.

-- 
Martin



More information about the bazaar mailing list