本文整理汇总了Python中distutils.core.Extension方法的典型用法代码示例。如果您正苦于以下问题:Python core.Extension方法的具体用法?Python core.Extension怎么用?Python core.Extension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类distutils.core
的用法示例。
在下文中一共展示了core.Extension方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_extensions
# 需要导入模块: from distutils import core [as 别名]
# 或者: from distutils.core import Extension [as 别名]
def get_extensions():
libraries = []
sources = [os.path.join(C_DIR, filename) for filename in C_FILES]
sources.append(os.path.join(HEALPIX_ROOT, 'interpolation.c'))
sources.append(os.path.join(HEALPIX_ROOT, '_core.c'))
extension = Extension(
name="astropy_healpix._core",
sources=sources,
include_dirs=C_DIRS,
libraries=libraries,
language="c",
extra_compile_args=['-O2'])
return [extension]
示例2: setUp
# 需要导入模块: from distutils import core [as 别名]
# 或者: from distutils.core import Extension [as 别名]
def setUp(self):
self.req = Require('Distutils','1.0.3','distutils')
self.dist = makeSetup(
features={
'foo': Feature("foo",standard=True,require_features=['baz',self.req]),
'bar': Feature("bar", standard=True, packages=['pkg.bar'],
py_modules=['bar_et'], remove=['bar.ext'],
),
'baz': Feature(
"baz", optional=False, packages=['pkg.baz'],
scripts = ['scripts/baz_it'],
libraries=[('libfoo','foo/foofoo.c')]
),
'dwim': Feature("DWIM", available=False, remove='bazish'),
},
script_args=['--without-bar', 'install'],
packages = ['pkg.bar', 'pkg.foo'],
py_modules = ['bar_et', 'bazish'],
ext_modules = [Extension('bar.ext',['bar.c'])]
)
示例3: _fixup_command
# 需要导入模块: from distutils import core [as 别名]
# 或者: from distutils.core import Extension [as 别名]
def _fixup_command(self, cmd):
# When Python was build with --enable-shared, -L. is not good enough
# to find the libpython<blah>.so. This is because regrtest runs it
# under a tempdir, not in the top level where the .so lives. By the
# time we've gotten here, Python's already been chdir'd to the
# tempdir.
#
# To further add to the fun, we can't just add library_dirs to the
# Extension() instance because that doesn't get plumbed through to the
# final compiler command.
if (sysconfig.get_config_var('Py_ENABLE_SHARED') and
not sys.platform.startswith('win')):
runshared = sysconfig.get_config_var('RUNSHARED')
if runshared is None:
cmd.library_dirs = ['.']
else:
name, equals, value = runshared.partition('=')
cmd.library_dirs = value.split(os.pathsep)
示例4: _set_py_limited_api
# 需要导入模块: from distutils import core [as 别名]
# 或者: from distutils.core import Extension [as 别名]
def _set_py_limited_api(Extension, kwds):
"""
Add py_limited_api to kwds if setuptools >= 26 is in use.
Do not alter the setting if it already exists.
Setuptools takes care of ignoring the flag on Python 2 and PyPy.
CPython itself should ignore the flag in a debugging version
(by not listing .abi3.so in the extensions it supports), but
it doesn't so far, creating troubles. That's why we check
for "not sys.flags.debug". (http://bugs.python.org/issue28401)
"""
if 'py_limited_api' not in kwds and not sys.flags.debug:
import setuptools
try:
setuptools_major_version = int(setuptools.__version__.partition('.')[0])
if setuptools_major_version >= 26:
kwds['py_limited_api'] = True
except ValueError: # certain development versions of setuptools
# If we don't know the version number of setuptools, we
# try to set 'py_limited_api' anyway. At worst, we get a
# warning.
kwds['py_limited_api'] = True
return kwds
示例5: make_extension
# 需要导入模块: from distutils import core [as 别名]
# 或者: from distutils.core import Extension [as 别名]
def make_extension(name, files, *args, **kwargs):
"""
Make a new extension. Automatically sets include_dirs and
library_dirs to the base directories appropriate for this
platform.
`name` is the name of the extension.
`files` is a list of source files.
Any additional arguments are passed to the
`distutils.core.Extension` constructor.
"""
ext = DelayedExtension(name, files, *args, **kwargs)
for dir in get_base_dirs():
include_dir = os.path.join(dir, 'include')
if os.path.exists(include_dir):
ext.include_dirs.append(include_dir)
for lib in ('lib', 'lib64'):
lib_dir = os.path.join(dir, lib)
if os.path.exists(lib_dir):
ext.library_dirs.append(lib_dir)
ext.include_dirs.append('.')
return ext
示例6: include_dirs_hook
# 需要导入模块: from distutils import core [as 别名]
# 或者: from distutils.core import Extension [as 别名]
def include_dirs_hook():
if hasattr(builtins, '__NUMPY_SETUP__'):
del builtins.__NUMPY_SETUP__
import numpy
importlib.reload(numpy)
ext = Extension('test', [])
# ext.include_dirs.append(numpy.get_include())
#iOS:
ext.include_dirs.append('../../onIpad/lib/python3.7/site-packages/numpy-1.16.0-py3.7-macosx-10.9-x86_64.egg/numpy/core/include/')
print("Include dirs found: ", numpy.get_include())
if not has_include_file(
ext.include_dirs, os.path.join("numpy", "arrayobject.h")):
warnings.warn(
"The C headers for numpy could not be found. "
"You may need to install the development package")
#iOS:
return ['../../onIpad/lib/python3.7/site-packages/numpy-1.16.0-py3.7-macosx-10.9-x86_64.egg/numpy/core/include/']
# return [numpy.get_include()]
示例7: generate
# 需要导入模块: from distutils import core [as 别名]
# 或者: from distutils.core import Extension [as 别名]
def generate(self, run_cc=True, build_python=False, generate_c=True):
filename = ('py'+self.name if build_python else self.name) + '.c'
if generate_c:
with open(filename, 'w') as f:
print('Generating C code to %s...' % f.name, file=sys.stderr)
self.c_emit(f, build_python)
f.flush()
if run_cc and not build_python:
command = [self.cc] + self.cflags + [
'-I', os.path.realpath(os.path.dirname(sys.argv[0])),
'-o', self.name, filename]
print(' '.join(command), file=sys.stderr)
subprocess.call(command)
elif run_cc and build_python:
from distutils.core import setup, Extension
tagger = Extension(
self.name,
sources = [filename],
libraries = [],
extra_compile_args = self.cflags,
extra_link_args = [])
setup(name = self.name, ext_modules = [tagger],
script_args = ['build_ext', '--inplace'])
示例8: _set_py_limited_api
# 需要导入模块: from distutils import core [as 别名]
# 或者: from distutils.core import Extension [as 别名]
def _set_py_limited_api(Extension, kwds):
"""
Add py_limited_api to kwds if setuptools >= 26 is in use.
Do not alter the setting if it already exists.
Setuptools takes care of ignoring the flag on Python 2 and PyPy.
CPython itself should ignore the flag in a debugging version
(by not listing .abi3.so in the extensions it supports), but
it doesn't so far, creating troubles. That's why we check
for "not hasattr(sys, 'gettotalrefcount')" (the 2.7 compatible equivalent
of 'd' not in sys.abiflags). (http://bugs.python.org/issue28401)
"""
if 'py_limited_api' not in kwds and not hasattr(sys, 'gettotalrefcount'):
import setuptools
try:
setuptools_major_version = int(setuptools.__version__.partition('.')[0])
if setuptools_major_version >= 26:
kwds['py_limited_api'] = True
except ValueError: # certain development versions of setuptools
# If we don't know the version number of setuptools, we
# try to set 'py_limited_api' anyway. At worst, we get a
# warning.
kwds['py_limited_api'] = True
return kwds
示例9: test_build_ext
# 需要导入模块: from distutils import core [as 别名]
# 或者: from distutils.core import Extension [as 别名]
def test_build_ext(self):
global ALREADY_TESTED
support.copy_xxmodule_c(self.tmp_dir)
self.xx_created = True
xx_c = os.path.join(self.tmp_dir, 'xxmodule.c')
xx_ext = Extension('xx', [xx_c])
dist = Distribution({'name': 'xx', 'ext_modules': [xx_ext]})
dist.package_dir = self.tmp_dir
cmd = build_ext(dist)
support.fixup_build_ext(cmd)
cmd.build_lib = self.tmp_dir
cmd.build_temp = self.tmp_dir
old_stdout = sys.stdout
if not test_support.verbose:
# silence compiler output
sys.stdout = StringIO()
try:
cmd.ensure_finalized()
cmd.run()
finally:
sys.stdout = old_stdout
if ALREADY_TESTED:
self.skipTest('Already tested in %s' % ALREADY_TESTED)
else:
ALREADY_TESTED = type(self).__name__
import xx
for attr in ('error', 'foo', 'new', 'roj'):
self.assertTrue(hasattr(xx, attr))
self.assertEqual(xx.foo(2, 5), 7)
self.assertEqual(xx.foo(13,15), 28)
self.assertEqual(xx.new().demo(), None)
if test_support.HAVE_DOCSTRINGS:
doc = 'This is a template module just for instruction.'
self.assertEqual(xx.__doc__, doc)
self.assertIsInstance(xx.Null(), xx.Null)
self.assertIsInstance(xx.Str(), xx.Str)
示例10: test_get_source_files
# 需要导入模块: from distutils import core [as 别名]
# 或者: from distutils.core import Extension [as 别名]
def test_get_source_files(self):
modules = [Extension('foo', ['xxx'])]
dist = Distribution({'name': 'xx', 'ext_modules': modules})
cmd = build_ext(dist)
cmd.ensure_finalized()
self.assertEqual(cmd.get_source_files(), ['xxx'])
示例11: test_build_ext_inplace
# 需要导入模块: from distutils import core [as 别名]
# 或者: from distutils.core import Extension [as 别名]
def test_build_ext_inplace(self):
etree_c = os.path.join(self.tmp_dir, 'lxml.etree.c')
etree_ext = Extension('lxml.etree', [etree_c])
dist = Distribution({'name': 'lxml', 'ext_modules': [etree_ext]})
cmd = build_ext(dist)
cmd.ensure_finalized()
cmd.inplace = 1
cmd.distribution.package_dir = {'': 'src'}
cmd.distribution.packages = ['lxml', 'lxml.html']
curdir = os.getcwd()
ext = sysconfig.get_config_var("SO")
wanted = os.path.join(curdir, 'src', 'lxml', 'etree' + ext)
path = cmd.get_ext_fullpath('lxml.etree')
self.assertEqual(wanted, path)
示例12: test_setuptools_compat
# 需要导入模块: from distutils import core [as 别名]
# 或者: from distutils.core import Extension [as 别名]
def test_setuptools_compat(self):
import distutils.core, distutils.extension, distutils.command.build_ext
saved_ext = distutils.extension.Extension
try:
# on some platforms, it loads the deprecated "dl" module
test_support.import_module('setuptools_build_ext', deprecated=True)
# theses import patch Distutils' Extension class
from setuptools_build_ext import build_ext as setuptools_build_ext
from setuptools_extension import Extension
etree_c = os.path.join(self.tmp_dir, 'lxml.etree.c')
etree_ext = Extension('lxml.etree', [etree_c])
dist = Distribution({'name': 'lxml', 'ext_modules': [etree_ext]})
cmd = setuptools_build_ext(dist)
cmd.ensure_finalized()
cmd.inplace = 1
cmd.distribution.package_dir = {'': 'src'}
cmd.distribution.packages = ['lxml', 'lxml.html']
curdir = os.getcwd()
ext = sysconfig.get_config_var("SO")
wanted = os.path.join(curdir, 'src', 'lxml', 'etree' + ext)
path = cmd.get_ext_fullpath('lxml.etree')
self.assertEqual(wanted, path)
finally:
# restoring Distutils' Extension class otherwise its broken
distutils.extension.Extension = saved_ext
distutils.core.Extension = saved_ext
distutils.command.build_ext.Extension = saved_ext
示例13: _set_py_limited_api
# 需要导入模块: from distutils import core [as 别名]
# 或者: from distutils.core import Extension [as 别名]
def _set_py_limited_api(Extension, kwds):
"""
Add py_limited_api to kwds if setuptools >= 26 is in use.
Do not alter the setting if it already exists.
Setuptools takes care of ignoring the flag on Python 2 and PyPy.
CPython itself should ignore the flag in a debugging version
(by not listing .abi3.so in the extensions it supports), but
it doesn't so far, creating troubles. That's why we check
for "not hasattr(sys, 'gettotalrefcount')" (the 2.7 compatible equivalent
of 'd' not in sys.abiflags). (http://bugs.python.org/issue28401)
On Windows, it's better not to use py_limited_api until issue #355
can be resolved (by having virtualenv copy PYTHON3.DLL). See also
the start of _cffi_include.h.
"""
if ('py_limited_api' not in kwds and not hasattr(sys, 'gettotalrefcount')
and sys.platform != 'win32'):
import setuptools
try:
setuptools_major_version = int(setuptools.__version__.partition('.')[0])
if setuptools_major_version >= 26:
kwds['py_limited_api'] = True
except ValueError: # certain development versions of setuptools
# If we don't know the version number of setuptools, we
# try to set 'py_limited_api' anyway. At worst, we get a
# warning.
kwds['py_limited_api'] = True
return kwds
示例14: get_extension
# 需要导入模块: from distutils import core [as 别名]
# 或者: from distutils.core import Extension [as 别名]
def get_extension(srcfilename, modname, sources=(), **kwds):
_hack_at_distutils()
from distutils.core import Extension
allsources = [srcfilename]
for src in sources:
allsources.append(os.path.normpath(src))
return Extension(name=modname, sources=allsources, **kwds)
示例15: get_extension
# 需要导入模块: from distutils import core [as 别名]
# 或者: from distutils.core import Extension [as 别名]
def get_extension(srcfilename, modname, sources=(), **kwds):
from distutils.core import Extension
allsources = [srcfilename]
for src in sources:
allsources.append(os.path.normpath(src))
return Extension(name=modname, sources=allsources, **kwds)