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

Martin Pool mbp at sourcefrog.net
Tue Nov 27 07:55:06 GMT 2007


>
> I haven't followed this thread very closely (on vacation this last week).
>
> I seem to remember sys.path getting '' put into it, but then some other code in
> site.py changing it to expand it to os.getcwd().
>
> In fact, looking at the bug:
> https://bugs.launchpad.net/bzr/+bug/53478
>
> I find this patch was the fix:
> http://launchpadlibrarian.net/3498888/site-py-update.diff
>
> +        if dir == '':
> +            # On some platforms there is an extra empty string in the list
> +            # of paths, which causes the current working directory to always
> +            # be added to the search path. Prevent this.
> +            # it will be added later if it is required by the code that adds
> +            # dirname(sys.argv[0])
> +            continue
>
> I believe I tracked down how we were getting '' in the original sys.path, but I
> can't remember it now.
>
> Anyway, if the raw string '' is in sys.path, it makes sense to me to filter it
> out in the 'bzr' front-end script.
>
> I'm not as convinced about removing os.getcwd().

You may be right that it's site.py that does the expansion - there is
code in there that could do it, certainly.  Anyhow, by the time we get
started, '' is gone.

> So in summary:
>
>   if '' in sys.path:
>     sys.path.remove('')
>
> is good. And I would start with that, and see if it gets you to what you need,
> without checking getcwd().

I don't think it will help - it's the same on Ubuntu as Alexander
reports on Windows.

-- 
Martin



More information about the bazaar mailing list