def import_module(space, name, init=None, body='', load_it=True, filename=None, PY_SSIZE_T_CLEAN=False): """ init specifies the overall template of the module. if init is None, the module source will be loaded from a file in this test direcory, give a name given by the filename parameter. if filename is None, the module name will be used to construct the filename. """ name = name.encode() if body or init: body = body.encode() if init is None: init = "return PyModule_Create(&moduledef);" else: init = init.encode() code = """ %(PY_SSIZE_T_CLEAN)s #include <Python.h> %(body)s PyMODINIT_FUNC PyInit_%(name)s(void) { %(init)s } """ % dict(name=name, init=init, body=body, PY_SSIZE_T_CLEAN='#define PY_SSIZE_T_CLEAN' if PY_SSIZE_T_CLEAN else '') kwds = dict(separate_module_sources=[code]) else: assert not PY_SSIZE_T_CLEAN if filename is None: filename = name filename = py.path.local(pypydir) / 'module' \ / 'cpyext'/ 'test' / (filename + ".c") kwds = dict(separate_module_files=[filename]) mod = compile_extension_module(space, name, **kwds) if load_it: api.load_extension_module(space, mod, name) self.imported_module_names.append(name) return space.getitem( space.sys.get('modules'), space.wrap(name)) else: return os.path.dirname(mod)
def import_module(self, name, init=None, body='', load_it=True, filename=None): """ init specifies the overall template of the module. if init is None, the module source will be loaded from a file in this test direcory, give a name given by the filename parameter. if filename is None, the module name will be used to construct the filename. """ if init is not None: code = """ #include <Python.h> %(body)s void init%(name)s(void) { %(init)s } """ % dict(name=name, init=init, body=body) kwds = dict(separate_module_sources=[code]) else: if filename is None: filename = name filename = py.path.local(autopath.pypydir) / 'module' \ / 'cpyext'/ 'test' / (filename + ".c") kwds = dict(separate_module_files=[filename]) mod = self.compile_module(name, **kwds) if load_it: api.load_extension_module(self.space, mod, name) self.imported_module_names.append(name) return self.space.getitem(self.space.sys.get('modules'), self.space.wrap(name)) else: return os.path.dirname(mod)
def import_module(space, name, init=None, body='', load_it=True, filename=None): """ init specifies the overall template of the module. if init is None, the module source will be loaded from a file in this test direcory, give a name given by the filename parameter. if filename is None, the module name will be used to construct the filename. """ if init is not None: code = """ #include <Python.h> %(body)s void init%(name)s(void) { %(init)s } """ % dict(name=name, init=init, body=body) kwds = dict(separate_module_sources=[code]) else: if filename is None: filename = name filename = py.path.local(pypydir) / 'module' \ / 'cpyext'/ 'test' / (filename + ".c") kwds = dict(separate_module_files=[filename]) mod = compile_extension_module(space, name, **kwds) if load_it: api.load_extension_module(space, mod, name) self.imported_module_names.append(name) return space.getitem( space.sys.get('modules'), space.wrap(name)) else: return os.path.dirname(mod)
def load_c_extension(space, filename, modulename): from pypy.module.cpyext.api import load_extension_module load_extension_module(space, filename, modulename)
def load_module(self, mod, name): space = self.space api.load_extension_module(space, mod, name) return space.getitem( space.sys.get('modules'), space.wrap(name))
def reimport_module(space, mod, name): api.load_extension_module(space, mod, name) return space.getitem( space.sys.get('modules'), space.wrap(name))
def load_c_extension(space, filename, modulename): # the next line is mandatory to init cpyext space.getbuiltinmodule("cpyext") from pypy.module.cpyext.api import load_extension_module load_extension_module(space, filename, modulename)
def load_module(self, mod, name): space = self.space api.load_extension_module(space, mod, name) return space.getitem(space.sys.get('modules'), space.wrap(name))
def reimport_module(space, mod, name): api.load_extension_module(space, mod, name) return space.getitem(space.sys.get('modules'), space.wrap(name))
def load_c_extension(space, filename, modulename): from pypy.module.cpyext.api import load_extension_module log_pyverbose(space, 1, "import %s # from %s\n" % (modulename, filename)) return load_extension_module(space, filename, modulename)
def load_c_extension(space, filename, modulename): from pypy.module.cpyext.api import load_extension_module log_pyverbose(space, 1, "import %s # from %s\n" % (modulename, filename)) load_extension_module(space, filename, modulename)
def reimport_module(self, mod, name): api.load_extension_module(self.space, mod, name) return self.space.getitem(self.space.sys.get("modules"), self.space.wrap(name))