2
self cloning, automatic path configuration
4
copy this into any subdirectory of pypy from which scripts need
5
to be run, typically all of the test subdirs.
6
The idea is that any such script simply issues
10
and this will make sure that the parent directory containing "pypy"
13
If you modify the master "autopath.py" version (in pypy/tool/autopath.py)
14
you can directly run it which will copy itself on all autopath.py files
15
it finds under the pypy root directory.
17
This module always provides these attributes:
19
pypydir pypy root directory path
20
this_dir directory where this autopath.py resides
26
""" return (partdir, this_dir) and insert parent of partdir
27
into sys.path. If the parent directories don't have the part
28
an EnvironmentError is raised."""
32
head = this_dir = os.path.realpath(os.path.dirname(__file__))
34
head = this_dir = os.path.realpath(os.path.dirname(sys.argv[0]))
38
head, tail = os.path.split(head)
42
raise EnvironmentError, "'%s' missing in '%r'" % (partdir, this_dir)
44
pypy_root = os.path.join(head, '')
49
sys.path.insert(0, head)
52
for name, mod in sys.modules.items():
55
fn = getattr(mod, '__file__', None)
56
if not isinstance(fn, str):
58
newname = os.path.splitext(os.path.basename(fn))[0]
59
if not newname.startswith(part + '.'):
61
path = os.path.join(os.path.dirname(os.path.realpath(fn)), '')
62
if path.startswith(pypy_root) and newname != part:
63
modpaths = os.path.normpath(path[len(pypy_root):]).split(os.sep)
64
if newname != '__init__':
65
modpaths.append(newname)
66
modpath = '.'.join(modpaths)
67
if modpath not in sys.modules:
70
for name, mod in munged.iteritems():
71
if name not in sys.modules:
72
sys.modules[name] = mod
74
prename = name[:name.rfind('.')]
75
postname = name[len(prename)+1:]
76
if prename not in sys.modules:
78
if not hasattr(sys.modules[prename], postname):
79
setattr(sys.modules[prename], postname, mod)
81
return partdir, this_dir
84
""" clone master version of autopath.py into all subdirs """
85
from os.path import join, walk
86
if not this_dir.endswith(join('pypy','tool')):
87
raise EnvironmentError("can only clone master version "
88
"'%s'" % join(pypydir, 'tool',_myname))
91
def sync_walker(arg, dirname, fnames):
93
fn = join(dirname, _myname)
104
s = open(join(pypydir, 'tool', _myname), 'rb').read()
105
walk(pypydir, sync_walker, s)
107
_myname = 'autopath.py'
109
# set guaranteed attributes
111
pypydir, this_dir = __dirinfo('pypy')
113
if __name__ == '__main__':