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

Alexander Belchenko bialix at ukr.net
Mon Nov 26 20:39:26 GMT 2007


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

John Arbash Meinel пишет:
> Alexander Belchenko wrote:
>> Aaron Bentley ?8H5B:
>>> Alexander Belchenko wrote:
>>>> Alexander Belchenko has voted abstain.
>>>> Status is now: Waiting
>>>> Comment:
>>>> actually this patch incorrect if we invoke bzr from directory where
>>>> bzrlib installed, e.g. Lib\site-packages.
>>> By abstaining, rather than rejecting, you're still inviting other people
>>> to vote on this.  Is that your intent?
>> I'd like to hear comments from John and Robert.
> 
> 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().
> 
> 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().

Well from my testing on win32 I see that '' in sys.path only appears when python
invoked in interactive mode. And '' is first item in sys.path, i.e. it play
the role of dirname(sys.argv[0]).

Simple test.py reveals that when python script is executed there is no '' in
sys.path. May I quote the e-mail I sent in answer to Robert?

C:\Temp\4>python24
Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> >>> import sys
>>> >>> sys.path
['', 'C:\\WINDOWS\\system32\\python24.zip', 'C:\\Temp\\4', 'C:\\Python24\\DLLs',
'C:\\Python24\\lib', 'C:\\Python24\\lib\\plat-win', 'C:\\Python24\\lib\\lib-tk', 'C:\\Python24',
'C:\\Python24\\lib\\site-packages', 'C:\\Python24\\lib\\site-packages\\win32',
'C:\\Python24\\lib\\site-packages\\win32\\lib', 'C:\\Python24\\lib\\site-packages\\Pythonwin']

Running simple script:

test.py:
import sys
print sys.path

C:\Temp\4>python24 test.py
['C:\\Temp\\4', 'C:\\WINDOWS\\system32\\python24.zip', 'C:\\Temp\\4', 'C:\\Python24\\DLLs',
'C:\\Python24\\lib', 'C:\\Python24\\lib\\plat-win', 'C:\\Python24\\lib\\lib-tk', 'C:\\Python24',
'C:\\Python24\\lib\\site-packages', 'C:\\Python24\\lib\\site-packages\\win32',
'C:\\Python24\\lib\\site-packages\\win32\\lib', 'C:\\Python24\\lib\\site-packages\\Pythonwin']

Actually cwd is sys.path[2] in both examples. But I'm not sure that some additional software
like setuptools don't change this order.


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

iD8DBQFHSy7+zYr338mxwCURArf1AKCJSMdRnUDqTvpf8L7iOSzhuC1KywCffgQy
Dt2MAZHlbO5wEU7z+KhiMsU=
=dzU9
-----END PGP SIGNATURE-----



More information about the bazaar mailing list