File: fixtures.py

package info (click to toggle)
pypy3 7.3.19%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 212,236 kB
  • sloc: python: 2,098,316; ansic: 540,565; sh: 21,462; asm: 14,419; cpp: 4,451; makefile: 4,209; objc: 761; xml: 530; exp: 499; javascript: 314; pascal: 244; lisp: 45; csh: 12; awk: 4
file content (73 lines) | stat: -rw-r--r-- 2,919 bytes parent folder | download | duplicates (3)
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
from _pytest.tmpdir import TempdirFactory
from pypy.interpreter.baseobjspace import W_Root
from pypy.interpreter.gateway import (unwrap_spec, interp2app)
from pypy.interpreter.typedef import TypeDef
from pypy.module._hpy_universal.test._vendored.support import ExtensionCompiler
from pypy.module._hpy_universal import llapi
from pypy.module._hpy_universal._vendored.hpy.devel import HPyDevel

COMPILER_VERBOSE = False
hpy_abi = 'debug'

class W_ExtensionCompiler(W_Root):
    def __init__(self, compiler):
        self.compiler = compiler

    @staticmethod
    def descr_new(space, w_type):
        return W_ExtensionCompiler()

    @unwrap_spec(main_src='text', name='text', w_extra_sources=W_Root, hpy_abi='text')
    def descr_make_module(self, space, main_src, name='mytest',
                            w_extra_sources=None, hpy_abi=hpy_abi):
        if w_extra_sources is None:
            extra_sources = ()
        else:
            items_w = space.unpackiterable(w_extra_sources)
            extra_sources = [space.text_w(item) for item in items_w]
        module = self.compiler.compile_module(
            main_src, self.compiler.ExtensionTemplate, name, extra_sources)
        if hpy_abi in ("debug", "hybrid+debug"):
            mode = llapi.MODE_DEBUG
        elif hpy_abi in ("universal", "hybrid"):
            mode = llapi.MODE_UNIVERSAL
        elif hpy_abi == "trace":
            mode = llapi.MODE_TRACE
        else:
            mode = -1
        w_mod = space.appexec([space.newtext(name),
                               space.newtext(module.so_filename),
                               space.newint(mode)],
            """(name, so_filename, mode):
                import sys
                import _hpy_universal
                import importlib.util
                assert name not in sys.modules
                spec = importlib.util.spec_from_file_location(name, so_filename)
                mod = _hpy_universal.load(name, so_filename, spec, mode=mode)
                mod.__file__ = so_filename
                mod.__spec__ = spec
                return mod
            """
        )
        return w_mod

W_ExtensionCompiler.typedef = TypeDef("ExtensionCompiler",
    #'__new__'=interp2app(W_ExtensionCompiler.descr_new),
    make_module=interp2app(W_ExtensionCompiler.descr_make_module),
)

def compiler(space, config):
    hpy_abi = 'debug'
    hpy_devel = HPyDevel(str(llapi.BASE_DIR))
    if space.config.objspace.usemodules.cpyext:
        from pypy.module import cpyext
        cpyext_include_dirs = cpyext.api.include_dirs
    else:
        cpyext_include_dirs = None
    tmpdir = TempdirFactory(config).getbasetemp()
    compiler =  ExtensionCompiler(tmpdir, hpy_devel, hpy_abi,
                             compiler_verbose=COMPILER_VERBOSE,
                            extra_include_dirs=cpyext_include_dirs)
    w_compiler = W_ExtensionCompiler(compiler)
    return w_compiler