[Patches] [ python-Patches-442983 ] site.py rev 1.28 broke addsitedir()

noreply@sourceforge.net noreply@sourceforge.net
Fri, 20 Jul 2001 13:07:46 -0700


Patches item #442983, was opened at 2001-07-19 23:33
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=442983&group_id=5470

>Category: library
Group: None
>Status: Closed
Resolution: Fixed
Priority: 5
Submitted By: Tim Peters (tim_one)
>Assigned to: Fred L. Drake, Jr. (fdrake)
Summary: site.py rev 1.28 broke addsitedir()

Initial Comment:
addsitedir() was changed to refer to global
dirs_in_sys_path, but that global got explictly del'ed 
on line 152 too, so it doesn't exist when addsitedir() 
is called.  Report from c.l.py follows:

"""
From: David Konerding <dek@cgl.ucsf.edu>
Sent: Friday, July 20, 2001 1:56 AM
To: python-list@python.org
Subject: python 2.1.1 trouble with addsitedir


Hi, I am checking my application's compatibility wiht 
2.1.1 and I've
run into a snag.  We use "site.addsitedir" to add a 
directory to the
loading path.

As an example, the following works just fine on Python-
2.1:

[dek@tolkien dek]$ python
Python 2.1 (#2, Jul 19 2001, 20:48:59) 
[GCC 2.95.3 20010315 (release)] on linux2
Type "copyright", "credits" or "license" for more 
information.
>>> import site
>>> site.addsitedir("/tmp")
>>> 


but running it with 2.1.1 gives the following:

[dek@tolkien Python-2.1.1c1]
$ /var/tmp/python/bin/python
Python 2.1.1c1 (#1, Jul 19 2001, 22:49:25) 
[GCC 2.95.3 20010315 (release)] on linux2
Type "copyright", "credits" or "license" for more 
information.
>>> import site
>>> site.addsitedir("/tmp")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/var/tmp/python/lib/python2.1/site.py", line 
100, in addsitedir
    if not dirs_in_sys_path.has_key(sitedircase):
NameError: global name 'dirs_in_sys_path' is not 
defined
"""


----------------------------------------------------------------------

>Comment By: Fred L. Drake, Jr. (fdrake)
Date: 2001-07-20 13:07

Message:
Logged In: YES 
user_id=3066

Checked in as Lib/site.py revision 1.32.

----------------------------------------------------------------------

Comment By: Fred L. Drake, Jr. (fdrake)
Date: 2001-07-20 08:27

Message:
Logged In: YES 
user_id=3066

After talking to Guido about this, agreed to let it ride for Python 2.1.1, but 2.2 should be more robust if we want to support making add*() publically available functions.

I've attached a patch that does what I think is the right thing; still needs documentation.

----------------------------------------------------------------------

Comment By: Fred L. Drake, Jr. (fdrake)
Date: 2001-07-20 08:12

Message:
Logged In: YES 
user_id=3066

I don't think that's the right fix.  (In fact, I was about
to check in the right fix, and encountered a conflict with
yours -- the lack of reasonably quick email through
digicool.com is a problem.)

Specifically, just letting the dirs_in_sys_path value sit
around assumes that the only use code which manipulates
sys.path uses the helpers in site.py, which is a bad
assumption given that these are undocumented.  It is better
to reset the dictionary to None and force it to be rebuilt
for external calls.  This way it doesn't break when other
modules manipulate sys.path.

Re-opening pending discussion -- keep it in the tracker so
we can all see it!

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-07-20 08:04

Message:
Logged In: YES 
user_id=6380

I've fixed this by removing the 'del dirs_in_sys_path' line,
both in 2.1.1 and in 2.2 (on the trunk).

This fix will make it into the 2.1.1 release.

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=442983&group_id=5470