[pypy-svn] r7369 - in pypy/trunk/src/pypy: annotation/test appspace appspace/test interpreter interpreter/test module/test objspace/flow/test objspace/std objspace/std/test objspace/test tool tool/test translator translator/test translator/tool translator/tool/pygame
bob at codespeak.net
bob at codespeak.net
Thu Nov 18 12:54:25 CET 2004
Author: bob
Date: Thu Nov 18 12:54:25 2004
New Revision: 7369
Modified:
pypy/trunk/src/pypy/annotation/test/autopath.py
pypy/trunk/src/pypy/appspace/autopath.py
pypy/trunk/src/pypy/appspace/test/autopath.py
pypy/trunk/src/pypy/interpreter/autopath.py
pypy/trunk/src/pypy/interpreter/test/autopath.py
pypy/trunk/src/pypy/module/test/autopath.py
pypy/trunk/src/pypy/objspace/flow/test/autopath.py
pypy/trunk/src/pypy/objspace/std/autopath.py
pypy/trunk/src/pypy/objspace/std/multimethod.py
pypy/trunk/src/pypy/objspace/std/test/autopath.py
pypy/trunk/src/pypy/objspace/test/autopath.py
pypy/trunk/src/pypy/tool/autopath.py
pypy/trunk/src/pypy/tool/test/autopath.py
pypy/trunk/src/pypy/translator/autopath.py
pypy/trunk/src/pypy/translator/test/autopath.py
pypy/trunk/src/pypy/translator/tool/autopath.py
pypy/trunk/src/pypy/translator/tool/pygame/autopath.py
Log:
smarter implementation of autopath
Modified: pypy/trunk/src/pypy/annotation/test/autopath.py
==============================================================================
--- pypy/trunk/src/pypy/annotation/test/autopath.py (original)
+++ pypy/trunk/src/pypy/annotation/test/autopath.py Thu Nov 18 12:54:25 2004
@@ -24,28 +24,32 @@
def __dirinfo(part):
""" return (partdir, this_dir) and insert parent of partdir
- into sys.path. If the parent directories dont have the part
+ into sys.path. If the parent directories don't have the part
an EnvironmentError is raised."""
- import sys, os
+ import sys, os
try:
- head = this_dir = os.path.abspath(os.path.dirname(__file__))
+ head = this_dir = os.path.realpath(os.path.dirname(__file__))
except NameError:
- head = this_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
+ head = this_dir = os.path.realpath(os.path.dirname(sys.argv[0]))
while head:
partdir = head
- try:
- sys.path.remove(head)
- except ValueError:
- pass
head, tail = os.path.split(head)
if tail == part:
- if head not in sys.path:
- sys.path.insert(0, head)
- return partdir, this_dir
-
- raise EnvironmentError, "'%s' missing in '%r'" % (pathpart,this_path)
+ break
+ else:
+ raise EnvironmentError, "'%s' missing in '%r'" % (partdir, this_dir)
+
+ checkpaths = sys.path[:]
+ pypy_root = os.path.join(head, '')
+
+ while checkpaths:
+ orig = checkpaths.pop()
+ if os.path.join(os.path.realpath(orig), '').startswith(pypy_root):
+ sys.path.remove(orig)
+ sys.path.insert(0, head)
+ return partdir, this_dir
def __clone():
""" clone master version of autopath.py into all subdirs """
Modified: pypy/trunk/src/pypy/appspace/autopath.py
==============================================================================
--- pypy/trunk/src/pypy/appspace/autopath.py (original)
+++ pypy/trunk/src/pypy/appspace/autopath.py Thu Nov 18 12:54:25 2004
@@ -24,28 +24,32 @@
def __dirinfo(part):
""" return (partdir, this_dir) and insert parent of partdir
- into sys.path. If the parent directories dont have the part
+ into sys.path. If the parent directories don't have the part
an EnvironmentError is raised."""
- import sys, os
+ import sys, os
try:
- head = this_dir = os.path.abspath(os.path.dirname(__file__))
+ head = this_dir = os.path.realpath(os.path.dirname(__file__))
except NameError:
- head = this_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
+ head = this_dir = os.path.realpath(os.path.dirname(sys.argv[0]))
while head:
partdir = head
- try:
- sys.path.remove(head)
- except ValueError:
- pass
head, tail = os.path.split(head)
if tail == part:
- if head not in sys.path:
- sys.path.insert(0, head)
- return partdir, this_dir
-
- raise EnvironmentError, "'%s' missing in '%r'" % (pathpart,this_path)
+ break
+ else:
+ raise EnvironmentError, "'%s' missing in '%r'" % (partdir, this_dir)
+
+ checkpaths = sys.path[:]
+ pypy_root = os.path.join(head, '')
+
+ while checkpaths:
+ orig = checkpaths.pop()
+ if os.path.join(os.path.realpath(orig), '').startswith(pypy_root):
+ sys.path.remove(orig)
+ sys.path.insert(0, head)
+ return partdir, this_dir
def __clone():
""" clone master version of autopath.py into all subdirs """
Modified: pypy/trunk/src/pypy/appspace/test/autopath.py
==============================================================================
--- pypy/trunk/src/pypy/appspace/test/autopath.py (original)
+++ pypy/trunk/src/pypy/appspace/test/autopath.py Thu Nov 18 12:54:25 2004
@@ -24,28 +24,32 @@
def __dirinfo(part):
""" return (partdir, this_dir) and insert parent of partdir
- into sys.path. If the parent directories dont have the part
+ into sys.path. If the parent directories don't have the part
an EnvironmentError is raised."""
- import sys, os
+ import sys, os
try:
- head = this_dir = os.path.abspath(os.path.dirname(__file__))
+ head = this_dir = os.path.realpath(os.path.dirname(__file__))
except NameError:
- head = this_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
+ head = this_dir = os.path.realpath(os.path.dirname(sys.argv[0]))
while head:
partdir = head
- try:
- sys.path.remove(head)
- except ValueError:
- pass
head, tail = os.path.split(head)
if tail == part:
- if head not in sys.path:
- sys.path.insert(0, head)
- return partdir, this_dir
-
- raise EnvironmentError, "'%s' missing in '%r'" % (pathpart,this_path)
+ break
+ else:
+ raise EnvironmentError, "'%s' missing in '%r'" % (partdir, this_dir)
+
+ checkpaths = sys.path[:]
+ pypy_root = os.path.join(head, '')
+
+ while checkpaths:
+ orig = checkpaths.pop()
+ if os.path.join(os.path.realpath(orig), '').startswith(pypy_root):
+ sys.path.remove(orig)
+ sys.path.insert(0, head)
+ return partdir, this_dir
def __clone():
""" clone master version of autopath.py into all subdirs """
Modified: pypy/trunk/src/pypy/interpreter/autopath.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/autopath.py (original)
+++ pypy/trunk/src/pypy/interpreter/autopath.py Thu Nov 18 12:54:25 2004
@@ -24,28 +24,32 @@
def __dirinfo(part):
""" return (partdir, this_dir) and insert parent of partdir
- into sys.path. If the parent directories dont have the part
+ into sys.path. If the parent directories don't have the part
an EnvironmentError is raised."""
- import sys, os
+ import sys, os
try:
- head = this_dir = os.path.abspath(os.path.dirname(__file__))
+ head = this_dir = os.path.realpath(os.path.dirname(__file__))
except NameError:
- head = this_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
+ head = this_dir = os.path.realpath(os.path.dirname(sys.argv[0]))
while head:
partdir = head
- try:
- sys.path.remove(head)
- except ValueError:
- pass
head, tail = os.path.split(head)
if tail == part:
- if head not in sys.path:
- sys.path.insert(0, head)
- return partdir, this_dir
-
- raise EnvironmentError, "'%s' missing in '%r'" % (pathpart,this_path)
+ break
+ else:
+ raise EnvironmentError, "'%s' missing in '%r'" % (partdir, this_dir)
+
+ checkpaths = sys.path[:]
+ pypy_root = os.path.join(head, '')
+
+ while checkpaths:
+ orig = checkpaths.pop()
+ if os.path.join(os.path.realpath(orig), '').startswith(pypy_root):
+ sys.path.remove(orig)
+ sys.path.insert(0, head)
+ return partdir, this_dir
def __clone():
""" clone master version of autopath.py into all subdirs """
Modified: pypy/trunk/src/pypy/interpreter/test/autopath.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/test/autopath.py (original)
+++ pypy/trunk/src/pypy/interpreter/test/autopath.py Thu Nov 18 12:54:25 2004
@@ -24,28 +24,32 @@
def __dirinfo(part):
""" return (partdir, this_dir) and insert parent of partdir
- into sys.path. If the parent directories dont have the part
+ into sys.path. If the parent directories don't have the part
an EnvironmentError is raised."""
- import sys, os
+ import sys, os
try:
- head = this_dir = os.path.abspath(os.path.dirname(__file__))
+ head = this_dir = os.path.realpath(os.path.dirname(__file__))
except NameError:
- head = this_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
+ head = this_dir = os.path.realpath(os.path.dirname(sys.argv[0]))
while head:
partdir = head
- try:
- sys.path.remove(head)
- except ValueError:
- pass
head, tail = os.path.split(head)
if tail == part:
- if head not in sys.path:
- sys.path.insert(0, head)
- return partdir, this_dir
-
- raise EnvironmentError, "'%s' missing in '%r'" % (pathpart,this_path)
+ break
+ else:
+ raise EnvironmentError, "'%s' missing in '%r'" % (partdir, this_dir)
+
+ checkpaths = sys.path[:]
+ pypy_root = os.path.join(head, '')
+
+ while checkpaths:
+ orig = checkpaths.pop()
+ if os.path.join(os.path.realpath(orig), '').startswith(pypy_root):
+ sys.path.remove(orig)
+ sys.path.insert(0, head)
+ return partdir, this_dir
def __clone():
""" clone master version of autopath.py into all subdirs """
Modified: pypy/trunk/src/pypy/module/test/autopath.py
==============================================================================
--- pypy/trunk/src/pypy/module/test/autopath.py (original)
+++ pypy/trunk/src/pypy/module/test/autopath.py Thu Nov 18 12:54:25 2004
@@ -24,28 +24,32 @@
def __dirinfo(part):
""" return (partdir, this_dir) and insert parent of partdir
- into sys.path. If the parent directories dont have the part
+ into sys.path. If the parent directories don't have the part
an EnvironmentError is raised."""
- import sys, os
+ import sys, os
try:
- head = this_dir = os.path.abspath(os.path.dirname(__file__))
+ head = this_dir = os.path.realpath(os.path.dirname(__file__))
except NameError:
- head = this_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
+ head = this_dir = os.path.realpath(os.path.dirname(sys.argv[0]))
while head:
partdir = head
- try:
- sys.path.remove(head)
- except ValueError:
- pass
head, tail = os.path.split(head)
if tail == part:
- if head not in sys.path:
- sys.path.insert(0, head)
- return partdir, this_dir
-
- raise EnvironmentError, "'%s' missing in '%r'" % (pathpart,this_path)
+ break
+ else:
+ raise EnvironmentError, "'%s' missing in '%r'" % (partdir, this_dir)
+
+ checkpaths = sys.path[:]
+ pypy_root = os.path.join(head, '')
+
+ while checkpaths:
+ orig = checkpaths.pop()
+ if os.path.join(os.path.realpath(orig), '').startswith(pypy_root):
+ sys.path.remove(orig)
+ sys.path.insert(0, head)
+ return partdir, this_dir
def __clone():
""" clone master version of autopath.py into all subdirs """
Modified: pypy/trunk/src/pypy/objspace/flow/test/autopath.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/flow/test/autopath.py (original)
+++ pypy/trunk/src/pypy/objspace/flow/test/autopath.py Thu Nov 18 12:54:25 2004
@@ -24,28 +24,32 @@
def __dirinfo(part):
""" return (partdir, this_dir) and insert parent of partdir
- into sys.path. If the parent directories dont have the part
+ into sys.path. If the parent directories don't have the part
an EnvironmentError is raised."""
- import sys, os
+ import sys, os
try:
- head = this_dir = os.path.abspath(os.path.dirname(__file__))
+ head = this_dir = os.path.realpath(os.path.dirname(__file__))
except NameError:
- head = this_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
+ head = this_dir = os.path.realpath(os.path.dirname(sys.argv[0]))
while head:
partdir = head
- try:
- sys.path.remove(head)
- except ValueError:
- pass
head, tail = os.path.split(head)
if tail == part:
- if head not in sys.path:
- sys.path.insert(0, head)
- return partdir, this_dir
-
- raise EnvironmentError, "'%s' missing in '%r'" % (pathpart,this_path)
+ break
+ else:
+ raise EnvironmentError, "'%s' missing in '%r'" % (partdir, this_dir)
+
+ checkpaths = sys.path[:]
+ pypy_root = os.path.join(head, '')
+
+ while checkpaths:
+ orig = checkpaths.pop()
+ if os.path.join(os.path.realpath(orig), '').startswith(pypy_root):
+ sys.path.remove(orig)
+ sys.path.insert(0, head)
+ return partdir, this_dir
def __clone():
""" clone master version of autopath.py into all subdirs """
Modified: pypy/trunk/src/pypy/objspace/std/autopath.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/autopath.py (original)
+++ pypy/trunk/src/pypy/objspace/std/autopath.py Thu Nov 18 12:54:25 2004
@@ -24,28 +24,32 @@
def __dirinfo(part):
""" return (partdir, this_dir) and insert parent of partdir
- into sys.path. If the parent directories dont have the part
+ into sys.path. If the parent directories don't have the part
an EnvironmentError is raised."""
- import sys, os
+ import sys, os
try:
- head = this_dir = os.path.abspath(os.path.dirname(__file__))
+ head = this_dir = os.path.realpath(os.path.dirname(__file__))
except NameError:
- head = this_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
+ head = this_dir = os.path.realpath(os.path.dirname(sys.argv[0]))
while head:
partdir = head
- try:
- sys.path.remove(head)
- except ValueError:
- pass
head, tail = os.path.split(head)
if tail == part:
- if head not in sys.path:
- sys.path.insert(0, head)
- return partdir, this_dir
-
- raise EnvironmentError, "'%s' missing in '%r'" % (pathpart,this_path)
+ break
+ else:
+ raise EnvironmentError, "'%s' missing in '%r'" % (partdir, this_dir)
+
+ checkpaths = sys.path[:]
+ pypy_root = os.path.join(head, '')
+
+ while checkpaths:
+ orig = checkpaths.pop()
+ if os.path.join(os.path.realpath(orig), '').startswith(pypy_root):
+ sys.path.remove(orig)
+ sys.path.insert(0, head)
+ return partdir, this_dir
def __clone():
""" clone master version of autopath.py into all subdirs """
Modified: pypy/trunk/src/pypy/objspace/std/multimethod.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/multimethod.py (original)
+++ pypy/trunk/src/pypy/objspace/std/multimethod.py Thu Nov 18 12:54:25 2004
@@ -33,6 +33,81 @@
# has been bound to a specific object space. It is obtained by
# 'space.xxx' or explicitly by calling 'xxx.get(space)'.
+class SourceCallList(object):
+ def __new__(cls, operatorsymbol, callist, dispatch_arity):
+ self = super(SourceCallList, cls).__new__()
+ if len(calllist) == 1:
+ fn, conversions = calllist[0]
+ if conversions == ((),) * len(conversions):
+ # no conversion, just calling a single function: return
+ # that function directly
+ return fn
+
+ def do(space, *args):
+ args, extraargs = args[:dispatch_arity], args[dispatch_arity:]
+ if len(args) < dispatch_arity:
+ raise TypeError, 'MultiMethod %s has an arity of %d (%d given)' % (operatorsymbol, len(args))
+
+ converted = [{(): (i, False)} for i in range(dispatch_arity)]
+ all_functions = {}
+
+ def make_conversion(dct, convtuple):
+ rval = dct.get(convtuple)
+ if rval is not None:
+ return rval
+ prev, can_fail = make_conversion(dct, convtuple[:-1])
+ new = '%s_%d' % (prev, len(dct))
+ fname = all_functions.setdefault(convtuple[-1],
+ 'd%d' % len(all_functions))
+ if can_fail:
+ source.append(' if isinstance(%s, FailedToImplement):' % prev)
+ source.append(' %s = %s' % (new, prev))
+ source.append(' else:')
+ indent = ' '
+ else:
+ indent = ' '
+ source.append('%s%s = %s(space,%s)' % (indent, new, fname, prev))
+ can_fail = can_fail or getattr(convtuple[-1], 'can_fail', False)
+ dct[convtuple] = new, can_fail
+ return new, can_fail
+
+ all_functions = {}
+ has_firstfailure = False
+ for fn, conversions in calllist:
+ # make the required conversions
+ fname = all_functions.setdefault(fn, 'f%d' % len(all_functions))
+ arglist = []
+ failcheck = []
+ for i in range(dispatch_arity):
+ argname, can_fail = make_conversion(i, conversions[i])
+ arglist.append(argname)
+ if can_fail:
+ failcheck.append(argname)
+ arglist.append('*extraargs')
+ source.append( ' try:')
+ for argname in failcheck:
+ source.append(' if isinstance(%s, FailedToImplement):' % argname)
+ source.append(' raise %s' % argname)
+ source.append( ' return %s(space,%s)' % (
+ fname, ','.join(arglist)))
+ if has_firstfailure:
+ source.append(' except FailedToImplement:')
+ else:
+ source.append(' except FailedToImplement, firstfailure:')
+ has_firstfailure = True
+ source.append( ' pass')
+
+ # complete exhaustion
+ if has_firstfailure:
+ source.append(' raise firstfailure')
+ else:
+ source.append(' raise FailedToImplement()')
+ source.append('')
+
+ glob = {'FailedToImplement': FailedToImplement}
+ for fn, fname in all_functions.items():
+ glob[fname] = fn
+ return '\n'.join(source), glob
class AbstractMultiMethod(object):
"""Abstract base class for MultiMethod and UnboundMultiMethod
@@ -92,6 +167,8 @@
def internal_compilecalllist(self, calllist):
source, glob = self.internal_sourcecalllist(calllist)
+ print glob
+ print source
# compile the function
exec source in glob
return glob['do']
Modified: pypy/trunk/src/pypy/objspace/std/test/autopath.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/test/autopath.py (original)
+++ pypy/trunk/src/pypy/objspace/std/test/autopath.py Thu Nov 18 12:54:25 2004
@@ -24,28 +24,32 @@
def __dirinfo(part):
""" return (partdir, this_dir) and insert parent of partdir
- into sys.path. If the parent directories dont have the part
+ into sys.path. If the parent directories don't have the part
an EnvironmentError is raised."""
- import sys, os
+ import sys, os
try:
- head = this_dir = os.path.abspath(os.path.dirname(__file__))
+ head = this_dir = os.path.realpath(os.path.dirname(__file__))
except NameError:
- head = this_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
+ head = this_dir = os.path.realpath(os.path.dirname(sys.argv[0]))
while head:
partdir = head
- try:
- sys.path.remove(head)
- except ValueError:
- pass
head, tail = os.path.split(head)
if tail == part:
- if head not in sys.path:
- sys.path.insert(0, head)
- return partdir, this_dir
-
- raise EnvironmentError, "'%s' missing in '%r'" % (pathpart,this_path)
+ break
+ else:
+ raise EnvironmentError, "'%s' missing in '%r'" % (partdir, this_dir)
+
+ checkpaths = sys.path[:]
+ pypy_root = os.path.join(head, '')
+
+ while checkpaths:
+ orig = checkpaths.pop()
+ if os.path.join(os.path.realpath(orig), '').startswith(pypy_root):
+ sys.path.remove(orig)
+ sys.path.insert(0, head)
+ return partdir, this_dir
def __clone():
""" clone master version of autopath.py into all subdirs """
Modified: pypy/trunk/src/pypy/objspace/test/autopath.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/test/autopath.py (original)
+++ pypy/trunk/src/pypy/objspace/test/autopath.py Thu Nov 18 12:54:25 2004
@@ -24,28 +24,32 @@
def __dirinfo(part):
""" return (partdir, this_dir) and insert parent of partdir
- into sys.path. If the parent directories dont have the part
+ into sys.path. If the parent directories don't have the part
an EnvironmentError is raised."""
- import sys, os
+ import sys, os
try:
- head = this_dir = os.path.abspath(os.path.dirname(__file__))
+ head = this_dir = os.path.realpath(os.path.dirname(__file__))
except NameError:
- head = this_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
+ head = this_dir = os.path.realpath(os.path.dirname(sys.argv[0]))
while head:
partdir = head
- try:
- sys.path.remove(head)
- except ValueError:
- pass
head, tail = os.path.split(head)
if tail == part:
- if head not in sys.path:
- sys.path.insert(0, head)
- return partdir, this_dir
-
- raise EnvironmentError, "'%s' missing in '%r'" % (pathpart,this_path)
+ break
+ else:
+ raise EnvironmentError, "'%s' missing in '%r'" % (partdir, this_dir)
+
+ checkpaths = sys.path[:]
+ pypy_root = os.path.join(head, '')
+
+ while checkpaths:
+ orig = checkpaths.pop()
+ if os.path.join(os.path.realpath(orig), '').startswith(pypy_root):
+ sys.path.remove(orig)
+ sys.path.insert(0, head)
+ return partdir, this_dir
def __clone():
""" clone master version of autopath.py into all subdirs """
Modified: pypy/trunk/src/pypy/tool/autopath.py
==============================================================================
--- pypy/trunk/src/pypy/tool/autopath.py (original)
+++ pypy/trunk/src/pypy/tool/autopath.py Thu Nov 18 12:54:25 2004
@@ -24,28 +24,32 @@
def __dirinfo(part):
""" return (partdir, this_dir) and insert parent of partdir
- into sys.path. If the parent directories dont have the part
+ into sys.path. If the parent directories don't have the part
an EnvironmentError is raised."""
- import sys, os
+ import sys, os
try:
- head = this_dir = os.path.abspath(os.path.dirname(__file__))
+ head = this_dir = os.path.realpath(os.path.dirname(__file__))
except NameError:
- head = this_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
+ head = this_dir = os.path.realpath(os.path.dirname(sys.argv[0]))
while head:
partdir = head
- try:
- sys.path.remove(head)
- except ValueError:
- pass
head, tail = os.path.split(head)
if tail == part:
- if head not in sys.path:
- sys.path.insert(0, head)
- return partdir, this_dir
-
- raise EnvironmentError, "'%s' missing in '%r'" % (pathpart,this_path)
+ break
+ else:
+ raise EnvironmentError, "'%s' missing in '%r'" % (partdir, this_dir)
+
+ checkpaths = sys.path[:]
+ pypy_root = os.path.join(head, '')
+
+ while checkpaths:
+ orig = checkpaths.pop()
+ if os.path.join(os.path.realpath(orig), '').startswith(pypy_root):
+ sys.path.remove(orig)
+ sys.path.insert(0, head)
+ return partdir, this_dir
def __clone():
""" clone master version of autopath.py into all subdirs """
Modified: pypy/trunk/src/pypy/tool/test/autopath.py
==============================================================================
--- pypy/trunk/src/pypy/tool/test/autopath.py (original)
+++ pypy/trunk/src/pypy/tool/test/autopath.py Thu Nov 18 12:54:25 2004
@@ -24,28 +24,32 @@
def __dirinfo(part):
""" return (partdir, this_dir) and insert parent of partdir
- into sys.path. If the parent directories dont have the part
+ into sys.path. If the parent directories don't have the part
an EnvironmentError is raised."""
- import sys, os
+ import sys, os
try:
- head = this_dir = os.path.abspath(os.path.dirname(__file__))
+ head = this_dir = os.path.realpath(os.path.dirname(__file__))
except NameError:
- head = this_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
+ head = this_dir = os.path.realpath(os.path.dirname(sys.argv[0]))
while head:
partdir = head
- try:
- sys.path.remove(head)
- except ValueError:
- pass
head, tail = os.path.split(head)
if tail == part:
- if head not in sys.path:
- sys.path.insert(0, head)
- return partdir, this_dir
-
- raise EnvironmentError, "'%s' missing in '%r'" % (pathpart,this_path)
+ break
+ else:
+ raise EnvironmentError, "'%s' missing in '%r'" % (partdir, this_dir)
+
+ checkpaths = sys.path[:]
+ pypy_root = os.path.join(head, '')
+
+ while checkpaths:
+ orig = checkpaths.pop()
+ if os.path.join(os.path.realpath(orig), '').startswith(pypy_root):
+ sys.path.remove(orig)
+ sys.path.insert(0, head)
+ return partdir, this_dir
def __clone():
""" clone master version of autopath.py into all subdirs """
Modified: pypy/trunk/src/pypy/translator/autopath.py
==============================================================================
--- pypy/trunk/src/pypy/translator/autopath.py (original)
+++ pypy/trunk/src/pypy/translator/autopath.py Thu Nov 18 12:54:25 2004
@@ -24,28 +24,32 @@
def __dirinfo(part):
""" return (partdir, this_dir) and insert parent of partdir
- into sys.path. If the parent directories dont have the part
+ into sys.path. If the parent directories don't have the part
an EnvironmentError is raised."""
- import sys, os
+ import sys, os
try:
- head = this_dir = os.path.abspath(os.path.dirname(__file__))
+ head = this_dir = os.path.realpath(os.path.dirname(__file__))
except NameError:
- head = this_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
+ head = this_dir = os.path.realpath(os.path.dirname(sys.argv[0]))
while head:
partdir = head
- try:
- sys.path.remove(head)
- except ValueError:
- pass
head, tail = os.path.split(head)
if tail == part:
- if head not in sys.path:
- sys.path.insert(0, head)
- return partdir, this_dir
-
- raise EnvironmentError, "'%s' missing in '%r'" % (pathpart,this_path)
+ break
+ else:
+ raise EnvironmentError, "'%s' missing in '%r'" % (partdir, this_dir)
+
+ checkpaths = sys.path[:]
+ pypy_root = os.path.join(head, '')
+
+ while checkpaths:
+ orig = checkpaths.pop()
+ if os.path.join(os.path.realpath(orig), '').startswith(pypy_root):
+ sys.path.remove(orig)
+ sys.path.insert(0, head)
+ return partdir, this_dir
def __clone():
""" clone master version of autopath.py into all subdirs """
Modified: pypy/trunk/src/pypy/translator/test/autopath.py
==============================================================================
--- pypy/trunk/src/pypy/translator/test/autopath.py (original)
+++ pypy/trunk/src/pypy/translator/test/autopath.py Thu Nov 18 12:54:25 2004
@@ -24,28 +24,32 @@
def __dirinfo(part):
""" return (partdir, this_dir) and insert parent of partdir
- into sys.path. If the parent directories dont have the part
+ into sys.path. If the parent directories don't have the part
an EnvironmentError is raised."""
- import sys, os
+ import sys, os
try:
- head = this_dir = os.path.abspath(os.path.dirname(__file__))
+ head = this_dir = os.path.realpath(os.path.dirname(__file__))
except NameError:
- head = this_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
+ head = this_dir = os.path.realpath(os.path.dirname(sys.argv[0]))
while head:
partdir = head
- try:
- sys.path.remove(head)
- except ValueError:
- pass
head, tail = os.path.split(head)
if tail == part:
- if head not in sys.path:
- sys.path.insert(0, head)
- return partdir, this_dir
-
- raise EnvironmentError, "'%s' missing in '%r'" % (pathpart,this_path)
+ break
+ else:
+ raise EnvironmentError, "'%s' missing in '%r'" % (partdir, this_dir)
+
+ checkpaths = sys.path[:]
+ pypy_root = os.path.join(head, '')
+
+ while checkpaths:
+ orig = checkpaths.pop()
+ if os.path.join(os.path.realpath(orig), '').startswith(pypy_root):
+ sys.path.remove(orig)
+ sys.path.insert(0, head)
+ return partdir, this_dir
def __clone():
""" clone master version of autopath.py into all subdirs """
Modified: pypy/trunk/src/pypy/translator/tool/autopath.py
==============================================================================
--- pypy/trunk/src/pypy/translator/tool/autopath.py (original)
+++ pypy/trunk/src/pypy/translator/tool/autopath.py Thu Nov 18 12:54:25 2004
@@ -24,28 +24,32 @@
def __dirinfo(part):
""" return (partdir, this_dir) and insert parent of partdir
- into sys.path. If the parent directories dont have the part
+ into sys.path. If the parent directories don't have the part
an EnvironmentError is raised."""
- import sys, os
+ import sys, os
try:
- head = this_dir = os.path.abspath(os.path.dirname(__file__))
+ head = this_dir = os.path.realpath(os.path.dirname(__file__))
except NameError:
- head = this_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
+ head = this_dir = os.path.realpath(os.path.dirname(sys.argv[0]))
while head:
partdir = head
- try:
- sys.path.remove(head)
- except ValueError:
- pass
head, tail = os.path.split(head)
if tail == part:
- if head not in sys.path:
- sys.path.insert(0, head)
- return partdir, this_dir
-
- raise EnvironmentError, "'%s' missing in '%r'" % (pathpart,this_path)
+ break
+ else:
+ raise EnvironmentError, "'%s' missing in '%r'" % (partdir, this_dir)
+
+ checkpaths = sys.path[:]
+ pypy_root = os.path.join(head, '')
+
+ while checkpaths:
+ orig = checkpaths.pop()
+ if os.path.join(os.path.realpath(orig), '').startswith(pypy_root):
+ sys.path.remove(orig)
+ sys.path.insert(0, head)
+ return partdir, this_dir
def __clone():
""" clone master version of autopath.py into all subdirs """
Modified: pypy/trunk/src/pypy/translator/tool/pygame/autopath.py
==============================================================================
--- pypy/trunk/src/pypy/translator/tool/pygame/autopath.py (original)
+++ pypy/trunk/src/pypy/translator/tool/pygame/autopath.py Thu Nov 18 12:54:25 2004
@@ -24,28 +24,32 @@
def __dirinfo(part):
""" return (partdir, this_dir) and insert parent of partdir
- into sys.path. If the parent directories dont have the part
+ into sys.path. If the parent directories don't have the part
an EnvironmentError is raised."""
- import sys, os
+ import sys, os
try:
- head = this_dir = os.path.abspath(os.path.dirname(__file__))
+ head = this_dir = os.path.realpath(os.path.dirname(__file__))
except NameError:
- head = this_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
+ head = this_dir = os.path.realpath(os.path.dirname(sys.argv[0]))
while head:
partdir = head
- try:
- sys.path.remove(head)
- except ValueError:
- pass
head, tail = os.path.split(head)
if tail == part:
- if head not in sys.path:
- sys.path.insert(0, head)
- return partdir, this_dir
-
- raise EnvironmentError, "'%s' missing in '%r'" % (pathpart,this_path)
+ break
+ else:
+ raise EnvironmentError, "'%s' missing in '%r'" % (partdir, this_dir)
+
+ checkpaths = sys.path[:]
+ pypy_root = os.path.join(head, '')
+
+ while checkpaths:
+ orig = checkpaths.pop()
+ if os.path.join(os.path.realpath(orig), '').startswith(pypy_root):
+ sys.path.remove(orig)
+ sys.path.insert(0, head)
+ return partdir, this_dir
def __clone():
""" clone master version of autopath.py into all subdirs """
More information about the Pypy-commit
mailing list