1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
import sys
import traceback
from rpython.translator.tool.pdbplus import PdbPlusShow
from pypy.objspace.fake.objspace import FakeObjSpace, W_Root
from pypy.config.pypyoption import get_pypy_config
def checkmodule(modname, translate_startup=True, ignore=(),
c_compile=False, extra_func=None, rpython_opts=None,
pypy_opts=None, show_pdbplus=False):
"""
Check that the module 'modname' translates.
Options:
translate_startup: TODO, document me
ignore: list of module interpleveldefs/appleveldefs to ignore
c_compile: determine whether to inokve the C compiler after rtyping
extra_func: extra function which will be annotated and called. It takes
a single "space" argment
rpython_opts: dictionariy containing extra configuration options
pypy_opts: dictionariy containing extra configuration options
show_pdbplus: show Pdb+ prompt on error. Useful for pdb commands such as
flowg, callg, etc.
"""
config = get_pypy_config(translating=True)
if pypy_opts:
config.set(**pypy_opts)
space = FakeObjSpace(config)
seeobj_w = []
modules = []
modnames = [modname]
for modname in modnames:
mod = __import__(
'pypy.module.%s.moduledef' % modname, None, None, ['__doc__'])
# force computation and record what we wrap
module = mod.Module(space, W_Root())
module.setup_after_space_initialization()
modules.append(module)
for name in module.loaders:
if name in ignore:
continue
seeobj_w.append(module._load_lazily(space, name))
if hasattr(module, 'submodules'):
for cls in module.submodules.itervalues():
submod = cls(space, W_Root())
for name in submod.loaders:
seeobj_w.append(submod._load_lazily(space, name))
#
def func():
for mod in modules:
mod.startup(space)
if not translate_startup:
func() # call it now
func = None
opts = {'translation.list_comprehension_operations': True}
if rpython_opts:
opts.update(rpython_opts)
try:
space.translates(func, seeobj_w=seeobj_w,
c_compile=c_compile, extra_func=extra_func, **opts)
except:
if not show_pdbplus:
raise
print
exc, val, tb = sys.exc_info()
traceback.print_exc()
sys.pdbplus = p = PdbPlusShow(space.t)
p.start(tb)
else:
if show_pdbplus:
sys.pdbplus = p = PdbPlusShow(space.t)
p.start(None)
|