[ZODB-Dev] Re: [Zope-Checkins] CVS: ZEO/ZEO - start.py:1.60

Florent Guillaume fg@nuxeo.com
20 Jan 2003 19:57:00 +0100


On Mon, 2003-01-20 at 19:11, Guido van Rossum wrote:
> > Modified Files:
> > 	start.py 
> > Log Message:
> > Merge from 2.0 branch:
> > Fixed to correctly munge sys.path.
> > 
> > 
> > === ZEO/ZEO/start.py 1.59 => 1.60 ===
> > --- ZEO/ZEO/start.py:1.59	Fri Jan 17 11:39:20 2003
> > +++ ZEO/ZEO/start.py	Mon Jan 20 13:05:50 2003
> > @@ -22,7 +22,7 @@
> >  import ThreadedAsync.LoopCallback
> >  
> >  def directory(p, n=1):
> > -    d = p
> > +    d = os.path.abspath(p)
> >      while n:
> >          d = os.path.split(d)[0]
> >          if not d or d == '.':
> 
> Florent, I don't understand this change.  Your checkin comment makes
> no sense (the directory() function doesn't use sys.path, and it isn't
> used in the context of sys.path either), and the code doesn't need
> os.path.abspath(), because it already calls getcwd() when it runs out
> of path elements.
> 
> What did you *intend* to do and say?

I mentionned sys.path because directory() is called to insert something
into sys.path.

I intended that fix. There are other ways to do it of course.

In the previous code, directory() removed n components from the path p,
and (mostly) correctly treated the case where, while trying to remove a
component, it encoutered '' or '.', in which case it called os.getcwd()
to find the current path and continue. But if you pass it
'lib/python/ZEO/start.py' with n=2, it returns 'lib/python'. Thus
directory() may return an absolute or a local path.

Jeremy proposes that the caller of directory() then call
os.path.abspath() on the result. This works, but I prefer to have
directory() always do all the work needed.

Note that I did a minimal fix, but maybe I should have rewritten
directory() because now the part that tests if not d or d == '.' is
unneeded...

Florent

-- 
Florent Guillaume, Nuxeo (Paris, France)
+33 1 40 33 79 87  http://nuxeo.com  mailto:fg@nuxeo.com