pypy / rpython / jit / tl /

The branch 'split-rpython' does not exist.
self cloning, automatic path configuration 

copy this into any subdirectory of pypy from which scripts need 
to be run, typically all of the test subdirs. 
The idea is that any such script simply issues

    import autopath

and this will make sure that the parent directory containing "pypy"
is in sys.path. 

If you modify the master "" version (in pypy/tool/ 
you can directly run it which will copy itself on all files
it finds under the pypy root directory. 

This module always provides these attributes:

    pypydir    pypy root directory path 
    this_dir   directory where this resides 


def __dirinfo(part):
    """ return (partdir, this_dir) and insert parent of partdir
    into sys.path.  If the parent directories don't have the part
    an EnvironmentError is raised."""

    import sys, os
        head = this_dir = os.path.realpath(os.path.dirname(__file__))
    except NameError:
        head = this_dir = os.path.realpath(os.path.dirname(sys.argv[0]))

    error = None
    while head:
        partdir = head
        head, tail = os.path.split(head)
        if tail == part:
            checkfile = os.path.join(partdir, os.pardir, 'pypy', '')
            if not os.path.exists(checkfile):
                error = "Cannot find %r" % (os.path.normpath(checkfile),)
        error = "Cannot find the parent directory %r of the path %r" % (
            partdir, this_dir)
    if not error:
        # check for bogus end-of-line style (e.g. files checked out on
        # Windows and moved to Unix)
        f = open(__file__.replace('.pyc', '.py'), 'r')
        data =
        if data.endswith('\r\n') or data.endswith('\r'):
            error = ("Bad end-of-line style in the .py files. Typically "
                     "caused by a zip file or a checkout done on Windows and "
                     "moved to Unix or vice-versa.")
    if error:
        raise EnvironmentError("Invalid source tree - bogus checkout! " +
    pypy_root = os.path.join(head, '')
    except ValueError:
    sys.path.insert(0, head)

    munged = {}
    for name, mod in sys.modules.items():
        if '.' in name:
        fn = getattr(mod, '__file__', None)
        if not isinstance(fn, str):
        newname = os.path.splitext(os.path.basename(fn))[0]
        if not newname.startswith(part + '.'):
        path = os.path.join(os.path.dirname(os.path.realpath(fn)), '')
        if path.startswith(pypy_root) and newname != part:
            modpaths = os.path.normpath(path[len(pypy_root):]).split(os.sep)
            if newname != '__init__':
            modpath = '.'.join(modpaths)
            if modpath not in sys.modules:
                munged[modpath] = mod

    for name, mod in munged.iteritems():
        if name not in sys.modules:
            sys.modules[name] = mod
        if '.' in name:
            prename = name[:name.rfind('.')]
            postname = name[len(prename)+1:]
            if prename not in sys.modules:
                if not hasattr(sys.modules[prename], postname):
                    setattr(sys.modules[prename], postname, mod)

    return partdir, this_dir

def __clone():
    """ clone master version of into all subdirs """
    from os.path import join, walk
    if not this_dir.endswith(join('pypy','tool')):
        raise EnvironmentError("can only clone master version "
                               "'%s'" % join(pypydir, 'tool',_myname))

    def sync_walker(arg, dirname, fnames):
        if _myname in fnames:
            fn = join(dirname, _myname)
            f = open(fn, 'rwb+')
                if == arg:
                    print "checkok", fn
                    print "syncing", fn
                    f = open(fn, 'w')
    s = open(join(pypydir, 'tool', _myname), 'rb').read()
    walk(pypydir, sync_walker, s)

_myname = ''

# set guaranteed attributes

pypydir, this_dir = __dirinfo('rpython')

if __name__ == '__main__':
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.