Debian Codegraph @

pypy/objspace/fake/checkmodule.py

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