Author: Ronny Pfannschmidt <ronny.pfannschm...@gmx.de> Branch: kill-import_from_lib_pypy Changeset: r55873:95707b7b2e26 Date: 2012-06-29 21:26 +0200 http://bitbucket.org/pypy/pypy/changeset/95707b7b2e26/
Log: move config cache recreation code to pypy/tool/lib_pypy diff --git a/lib_pypy/ctypes_config_cache/dumpcache.py b/lib_pypy/ctypes_config_cache/dumpcache.py deleted file mode 100644 --- a/lib_pypy/ctypes_config_cache/dumpcache.py +++ /dev/null @@ -1,25 +0,0 @@ -import os -from ctypes_configure import dumpcache -from pypy.jit.backend import detect_cpu - -def dumpcache2(basename, config): - model = detect_cpu.autodetect_main_model_and_size() - filename = '_%s_%s_.py' % (basename, model) - dumpcache.dumpcache(__file__, filename, config) - # - filename = os.path.join(os.path.dirname(__file__), - '_%s_cache.py' % (basename,)) - g = open(filename, 'w') - print >> g, '''\ -try: - from __pypy__ import cpumodel -except ImportError: - from pypy.jit.backend import detect_cpu - cpumodel = detect_cpu.autodetect_main_model_and_size() -# XXX relative import, should be removed together with -# XXX the relative imports done e.g. by lib_pypy/pypy_test/test_hashlib -mod = __import__("_%s_%%s_" %% (cpumodel,), - globals(), locals(), ["*"]) -globals().update(mod.__dict__)\ -''' % (basename,) - g.close() diff --git a/lib_pypy/ctypes_config_cache/rebuild.py b/lib_pypy/ctypes_config_cache/rebuild.py --- a/lib_pypy/ctypes_config_cache/rebuild.py +++ b/lib_pypy/ctypes_config_cache/rebuild.py @@ -10,55 +10,7 @@ autopath_py = os.path.abspath(autopath_py) execfile(autopath_py, dict(__name__='autopath', __file__=autopath_py)) -import os, sys -import py - -_dirpath = os.path.dirname(__file__) or os.curdir - -from pypy.tool.ansi_print import ansi_log -log = py.log.Producer("ctypes_config_cache") -py.log.setconsumer("ctypes_config_cache", ansi_log) - - -def rebuild_one(name): - filename = os.path.join(_dirpath, name) - d = {'__file__': filename} - path = sys.path[:] - try: - sys.path.insert(0, _dirpath) - execfile(filename, d) - finally: - sys.path[:] = path - -def try_rebuild(): - from pypy.jit.backend import detect_cpu - model = detect_cpu.autodetect_main_model_and_size() - # remove the files '_*_model_.py' - left = {} - for p in os.listdir(_dirpath): - if p.startswith('_') and (p.endswith('_%s_.py' % model) or - p.endswith('_%s_.pyc' % model)): - os.unlink(os.path.join(_dirpath, p)) - elif p.startswith('_') and (p.endswith('_.py') or - p.endswith('_.pyc')): - for i in range(2, len(p)-4): - left[p[:i]] = True - # remove the files '_*_cache.py' if there is no '_*_*_.py' left around - for p in os.listdir(_dirpath): - if p.startswith('_') and (p.endswith('_cache.py') or - p.endswith('_cache.pyc')): - if p[:-9] not in left: - os.unlink(os.path.join(_dirpath, p)) - # - for p in os.listdir(_dirpath): - if p.endswith('.ctc.py'): - try: - rebuild_one(p) - except Exception, e: - log.ERROR("Running %s:\n %s: %s" % ( - os.path.join(_dirpath, p), - e.__class__.__name__, e)) - +from pypy.tool.lib_pypy import try_rebuild if __name__ == '__main__': try_rebuild() diff --git a/pypy/tool/lib_pypy.py b/pypy/tool/lib_pypy.py --- a/pypy/tool/lib_pypy.py +++ b/pypy/tool/lib_pypy.py @@ -1,8 +1,91 @@ +import os +import sys + import py import pypy import pypy.module from pypy.module.sys.version import CPYTHON_VERSION +from ctypes_configure import dumpcache +from pypy.jit.backend import detect_cpu + + +from pypy.tool.ansi_print import ansi_log +log = py.log.Producer("ctypes_config_cache") +py.log.setconsumer("ctypes_config_cache", ansi_log) + + LIB_ROOT = py.path.local(pypy.__path__[0]).dirpath() LIB_PYPY = LIB_ROOT.join('lib_pypy') LIB_PYTHON = LIB_ROOT.join('lib-python', '%d.%d' % CPYTHON_VERSION[:2]) + + +ctypes_cachedir = LIB_PYPY.join('ctypes_config_cache') + + +def dumpcache2(basename, config, sourcefile): + model = detect_cpu.autodetect_main_model_and_size() + filename = '_%s_%s_.py' % (basename, model) + dumpcache.dumpcache(sourcefile, filename, config) + # + filename = ctypes_cachedir.join('_%s_cache.py' % (basename)) + filename.write('''\ +try: + from __pypy__ import cpumodel +except ImportError: + from pypy.jit.backend import detect_cpu + cpumodel = detect_cpu.autodetect_main_model_and_size() +# XXX relative import, should be removed together with +# XXX the relative imports done e.g. by lib_pypy/pypy_test/test_hashlib +mod = __import__("_BASENAME_%s_" % (cpumodel,), + globals(), locals(), ["*"]) +globals().update(mod.__dict__)\\ +'''.replace("BASENAME", basename)) + + + + + +def rebuild_one(path): + filename = str(path) + d = {'__file__': filename} + #XXX: hack + class DumpCache: + @staticmethod + def dumpcache2(basename, config): + dumpcache2(basename, config, filename) + + sys.modules['dumpcache'] = DumpCache() + try: + execfile(filename, d) + finally: + del sys.modules['dumpcache'] + +def try_rebuild(): + from pypy.jit.backend import detect_cpu + model = detect_cpu.autodetect_main_model_and_size() + + # kill pyc files: + for p in ctypes_cachedir.listdir('*.pyc'): + p.remove() + + # remove the files '_*_model_.py' + left = {} + for p in ctypes_cachedir.listdir('_*_%s_.py' % (model,)): + p.remove() + # remove the files '_*_cache.py' if there is no '_*_*_.py' left around + for p in ctypes_cachedir.listdir('_*_cache.py'): + fnmatch = p.basename.replace('cache', '*') + if not ctypes_cachedir.listdir(fnmatch): + p.remove() + # + for p in ctypes_cachedir.listdir('*.ctc.py'): + try: + rebuild_one(p) + except Exception, e: + log.ERROR("Running %s:\n %s: %s" % ( + LIB_PYPY.bestrelpath(p), + e.__class__.__name__, e)) + import traceback + traceback.print_exc() + _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit