本文整理汇总了Python中cffi.recompiler.make_py_source方法的典型用法代码示例。如果您正苦于以下问题:Python recompiler.make_py_source方法的具体用法?Python recompiler.make_py_source怎么用?Python recompiler.make_py_source使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cffi.recompiler
的用法示例。
在下文中一共展示了recompiler.make_py_source方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_struct_included
# 需要导入模块: from cffi import recompiler [as 别名]
# 或者: from cffi.recompiler import make_py_source [as 别名]
def test_struct_included():
baseffi = FFI()
baseffi.cdef("struct foo_s { int x; };")
baseffi.set_source('test_struct_included_base', None)
#
ffi = FFI()
ffi.include(baseffi)
target = udir.join('test_struct_included.py')
make_py_source(ffi, 'test_struct_included', str(target))
assert target.read() == r"""# auto-generated file
import _cffi_backend
from test_struct_included_base import ffi as _ffi0
ffi = _cffi_backend.FFI('test_struct_included',
_version = 0x2601,
_types = b'\x00\x00\x00\x09',
_struct_unions = ((b'\x00\x00\x00\x00\x00\x00\x00\x08foo_s',),),
_includes = (_ffi0,),
)
"""
示例2: _add_py_module
# 需要导入模块: from cffi import recompiler [as 别名]
# 或者: from cffi.recompiler import make_py_source [as 别名]
def _add_py_module(dist, ffi, module_name):
from distutils.dir_util import mkpath
from distutils.command.build_py import build_py
from distutils.command.build_ext import build_ext
from distutils import log
from cffi import recompiler
def generate_mod(py_file):
log.info("generating cffi module %r" % py_file)
mkpath(os.path.dirname(py_file))
updated = recompiler.make_py_source(ffi, module_name, py_file)
if not updated:
log.info("already up-to-date")
base_class = dist.cmdclass.get('build_py', build_py)
class build_py_make_mod(base_class):
def run(self):
base_class.run(self)
module_path = module_name.split('.')
module_path[-1] += '.py'
generate_mod(os.path.join(self.build_lib, *module_path))
dist.cmdclass['build_py'] = build_py_make_mod
# the following is only for "build_ext -i"
base_class_2 = dist.cmdclass.get('build_ext', build_ext)
class build_ext_make_mod(base_class_2):
def run(self):
base_class_2.run(self)
if self.inplace:
# from get_ext_fullpath() in distutils/command/build_ext.py
module_path = module_name.split('.')
package = '.'.join(module_path[:-1])
build_py = self.get_finalized_command('build_py')
package_dir = build_py.get_package_dir(package)
file_name = module_path[-1] + '.py'
generate_mod(os.path.join(package_dir, file_name))
dist.cmdclass['build_ext'] = build_ext_make_mod
示例3: test_simple
# 需要导入模块: from cffi import recompiler [as 别名]
# 或者: from cffi.recompiler import make_py_source [as 别名]
def test_simple():
ffi = FFI()
ffi.cdef("int close(int); static const int BB = 42; int somevar;")
target = udir.join('test_simple.py')
make_py_source(ffi, 'test_simple', str(target))
assert target.read() == r"""# auto-generated file
import _cffi_backend
ffi = _cffi_backend.FFI('test_simple',
_version = 0x2601,
_types = b'\x00\x00\x01\x0D\x00\x00\x07\x01\x00\x00\x00\x0F',
_globals = (b'\xFF\xFF\xFF\x1FBB',42,b'\x00\x00\x00\x23close',0,b'\x00\x00\x01\x21somevar',0),
)
"""
示例4: test_global_constant
# 需要导入模块: from cffi import recompiler [as 别名]
# 或者: from cffi.recompiler import make_py_source [as 别名]
def test_global_constant():
ffi = FFI()
ffi.cdef("static const long BB; static const float BF = 12;")
target = udir.join('test_valid_global_constant.py')
make_py_source(ffi, 'test_valid_global_constant', str(target))
assert target.read() == r"""# auto-generated file
import _cffi_backend
ffi = _cffi_backend.FFI('test_valid_global_constant',
_version = 0x2601,
_types = b'\x00\x00\x0D\x01\x00\x00\x09\x01',
_globals = (b'\x00\x00\x01\x25BB',0,b'\x00\x00\x00\x25BF',0),
)
"""
示例5: test_invalid_dotdotdot_in_macro
# 需要导入模块: from cffi import recompiler [as 别名]
# 或者: from cffi.recompiler import make_py_source [as 别名]
def test_invalid_dotdotdot_in_macro():
ffi = FFI()
ffi.cdef("#define FOO ...")
target = udir.join('test_invalid_dotdotdot_in_macro.py')
e = py.test.raises(VerificationError, make_py_source, ffi,
'test_invalid_dotdotdot_in_macro', str(target))
assert str(e.value) == ("macro FOO: cannot use the syntax '...' in "
"'#define FOO ...' when using the ABI mode")
示例6: test_typename
# 需要导入模块: from cffi import recompiler [as 别名]
# 或者: from cffi.recompiler import make_py_source [as 别名]
def test_typename():
ffi = FFI()
ffi.cdef("typedef int foobar_t;")
target = udir.join('test_typename.py')
make_py_source(ffi, 'test_typename', str(target))
assert target.read() == r"""# auto-generated file
import _cffi_backend
ffi = _cffi_backend.FFI('test_typename',
_version = 0x2601,
_types = b'\x00\x00\x07\x01',
_typenames = (b'\x00\x00\x00\x00foobar_t',),
)
"""
示例7: test_struct
# 需要导入模块: from cffi import recompiler [as 别名]
# 或者: from cffi.recompiler import make_py_source [as 别名]
def test_struct():
ffi = FFI()
ffi.cdef("struct foo_s { int a; signed char b[]; }; struct bar_s;")
target = udir.join('test_struct.py')
make_py_source(ffi, 'test_struct', str(target))
assert target.read() == r"""# auto-generated file
import _cffi_backend
ffi = _cffi_backend.FFI('test_struct',
_version = 0x2601,
_types = b'\x00\x00\x07\x01\x00\x00\x03\x01\x00\x00\x01\x07\x00\x00\x00\x09\x00\x00\x01\x09',
_struct_unions = ((b'\x00\x00\x00\x03\x00\x00\x00\x10bar_s',),(b'\x00\x00\x00\x04\x00\x00\x00\x02foo_s',b'\x00\x00\x00\x11a',b'\x00\x00\x02\x11b')),
)
"""
示例8: test_include
# 需要导入模块: from cffi import recompiler [as 别名]
# 或者: from cffi.recompiler import make_py_source [as 别名]
def test_include():
ffi = FFI()
ffi.cdef("#define ABC 123")
ffi.set_source('test_include', None)
target = udir.join('test_include.py')
make_py_source(ffi, 'test_include', str(target))
assert target.read() == r"""# auto-generated file
import _cffi_backend
ffi = _cffi_backend.FFI('test_include',
_version = 0x2601,
_types = b'',
_globals = (b'\xFF\xFF\xFF\x1FABC',123,),
)
"""
#
ffi2 = FFI()
ffi2.include(ffi)
target2 = udir.join('test2_include.py')
make_py_source(ffi2, 'test2_include', str(target2))
assert target2.read() == r"""# auto-generated file
import _cffi_backend
from test_include import ffi as _ffi0
ffi = _cffi_backend.FFI('test2_include',
_version = 0x2601,
_types = b'',
_includes = (_ffi0,),
)
"""
示例9: test_negative_constant
# 需要导入模块: from cffi import recompiler [as 别名]
# 或者: from cffi.recompiler import make_py_source [as 别名]
def test_negative_constant():
ffi = FFI()
ffi.cdef("static const int BB = -42;")
target = udir.join('test_negative_constant.py')
make_py_source(ffi, 'test_negative_constant', str(target))
assert target.read() == r"""# auto-generated file
import _cffi_backend
ffi = _cffi_backend.FFI('test_negative_constant',
_version = 0x2601,
_types = b'',
_globals = (b'\xFF\xFF\xFF\x1FBB',-42,),
)
"""
示例10: test_no_cross_include
# 需要导入模块: from cffi import recompiler [as 别名]
# 或者: from cffi.recompiler import make_py_source [as 别名]
def test_no_cross_include():
baseffi = FFI()
baseffi.set_source('test_no_cross_include_base', "..source..")
#
ffi = FFI()
ffi.include(baseffi)
target = udir.join('test_no_cross_include.py')
py.test.raises(VerificationError, make_py_source,
ffi, 'test_no_cross_include', str(target))
示例11: test_array_overflow
# 需要导入模块: from cffi import recompiler [as 别名]
# 或者: from cffi.recompiler import make_py_source [as 别名]
def test_array_overflow():
ffi = FFI()
ffi.cdef("typedef int32_t my_array_t[3000000000];")
target = udir.join('test_array_overflow.py')
py.test.raises(OverflowError, make_py_source,
ffi, 'test_array_overflow', str(target))
示例12: test_global_var
# 需要导入模块: from cffi import recompiler [as 别名]
# 或者: from cffi.recompiler import make_py_source [as 别名]
def test_global_var():
ffi = FFI()
ffi.cdef("int myglob;")
target = udir.join('test_global_var.py')
make_py_source(ffi, 'test_global_var', str(target))
assert target.read() == r"""# auto-generated file
import _cffi_backend
ffi = _cffi_backend.FFI('test_global_var',
_version = 0x2601,
_types = b'\x00\x00\x07\x01',
_globals = (b'\x00\x00\x00\x21myglob',0,),
)
"""
示例13: test_bitfield
# 需要导入模块: from cffi import recompiler [as 别名]
# 或者: from cffi.recompiler import make_py_source [as 别名]
def test_bitfield():
ffi = FFI()
ffi.cdef("struct foo_s { int y:10; short x:5; };")
target = udir.join('test_bitfield.py')
make_py_source(ffi, 'test_bitfield', str(target))
assert target.read() == r"""# auto-generated file
import _cffi_backend
ffi = _cffi_backend.FFI('test_bitfield',
_version = 0x2601,
_types = b'\x00\x00\x07\x01\x00\x00\x05\x01\x00\x00\x00\x09',
_struct_unions = ((b'\x00\x00\x00\x02\x00\x00\x00\x02foo_s',b'\x00\x00\x00\x13\x00\x00\x00\x0Ay',b'\x00\x00\x01\x13\x00\x00\x00\x05x'),),
)
"""
示例14: _add_py_module
# 需要导入模块: from cffi import recompiler [as 别名]
# 或者: from cffi.recompiler import make_py_source [as 别名]
def _add_py_module(dist, ffi, module_name):
from distutils.dir_util import mkpath
from setuptools.command.build_py import build_py
from setuptools.command.build_ext import build_ext
from distutils import log
from cffi import recompiler
def generate_mod(py_file):
log.info("generating cffi module %r" % py_file)
mkpath(os.path.dirname(py_file))
updated = recompiler.make_py_source(ffi, module_name, py_file)
if not updated:
log.info("already up-to-date")
base_class = dist.cmdclass.get('build_py', build_py)
class build_py_make_mod(base_class):
def run(self):
base_class.run(self)
module_path = module_name.split('.')
module_path[-1] += '.py'
generate_mod(os.path.join(self.build_lib, *module_path))
dist.cmdclass['build_py'] = build_py_make_mod
# distutils and setuptools have no notion I could find of a
# generated python module. If we don't add module_name to
# dist.py_modules, then things mostly work but there are some
# combination of options (--root and --record) that will miss
# the module. So we add it here, which gives a few apparently
# harmless warnings about not finding the file outside the
# build directory.
if dist.py_modules is None:
dist.py_modules = []
dist.py_modules.append(module_name)
# the following is only for "build_ext -i"
base_class_2 = dist.cmdclass.get('build_ext', build_ext)
class build_ext_make_mod(base_class_2):
def run(self):
base_class_2.run(self)
if self.inplace:
# from get_ext_fullpath() in distutils/command/build_ext.py
module_path = module_name.split('.')
package = '.'.join(module_path[:-1])
build_py = self.get_finalized_command('build_py')
package_dir = build_py.get_package_dir(package)
file_name = module_path[-1] + '.py'
generate_mod(os.path.join(package_dir, file_name))
dist.cmdclass['build_ext'] = build_ext_make_mod
示例15: _add_py_module
# 需要导入模块: from cffi import recompiler [as 别名]
# 或者: from cffi.recompiler import make_py_source [as 别名]
def _add_py_module(dist, ffi, module_name):
from distutils.dir_util import mkpath
from setuptools.command.build_py import build_py
from setuptools.command.build_ext import build_ext
from distutils import log
from cffi import recompiler
def generate_mod(py_file):
log.info("generating cffi module %r" % py_file)
mkpath(os.path.dirname(py_file))
updated = recompiler.make_py_source(ffi, module_name, py_file)
if not updated:
log.info("already up-to-date")
base_class = dist.cmdclass.get('build_py', build_py)
class build_py_make_mod(base_class):
def run(self):
base_class.run(self)
module_path = module_name.split('.')
module_path[-1] += '.py'
generate_mod(os.path.join(self.build_lib, *module_path))
def get_source_files(self):
# This is called from 'setup.py sdist' only. Exclude
# the generate .py module in this case.
saved_py_modules = self.py_modules
try:
if saved_py_modules:
self.py_modules = [m for m in saved_py_modules
if m != module_name]
return base_class.get_source_files(self)
finally:
self.py_modules = saved_py_modules
dist.cmdclass['build_py'] = build_py_make_mod
# distutils and setuptools have no notion I could find of a
# generated python module. If we don't add module_name to
# dist.py_modules, then things mostly work but there are some
# combination of options (--root and --record) that will miss
# the module. So we add it here, which gives a few apparently
# harmless warnings about not finding the file outside the
# build directory.
# Then we need to hack more in get_source_files(); see above.
if dist.py_modules is None:
dist.py_modules = []
dist.py_modules.append(module_name)
# the following is only for "build_ext -i"
base_class_2 = dist.cmdclass.get('build_ext', build_ext)
class build_ext_make_mod(base_class_2):
def run(self):
base_class_2.run(self)
if self.inplace:
# from get_ext_fullpath() in distutils/command/build_ext.py
module_path = module_name.split('.')
package = '.'.join(module_path[:-1])
build_py = self.get_finalized_command('build_py')
package_dir = build_py.get_package_dir(package)
file_name = module_path[-1] + '.py'
generate_mod(os.path.join(package_dir, file_name))
dist.cmdclass['build_ext'] = build_ext_make_mod