本文整理汇总了Python中Cython.Build方法的典型用法代码示例。如果您正苦于以下问题:Python Cython.Build方法的具体用法?Python Cython.Build怎么用?Python Cython.Build使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cython
的用法示例。
在下文中一共展示了Cython.Build方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_cython_status
# 需要导入模块: import Cython [as 别名]
# 或者: from Cython import Build [as 别名]
def get_cython_status():
"""
Returns a dictionary containing a boolean specifying whether Cython is
up-to-date, along with the version string (empty string if not installed).
"""
cython_status = {}
try:
import Cython
from Cython.Build import cythonize
cython_version = Cython.__version__
cython_status['up_to_date'] = parse_version(
cython_version) >= parse_version(CYTHON_MIN_VERSION)
cython_status['version'] = cython_version
except ImportError:
traceback.print_exc()
cython_status['up_to_date'] = False
cython_status['version'] = ""
return cython_status
示例2: maybe_cythonize_extensions
# 需要导入模块: import Cython [as 别名]
# 或者: from Cython import Build [as 别名]
def maybe_cythonize_extensions(top_path, config):
"""Tweaks for building extensions between release and development mode."""
is_release = os.path.exists(os.path.join(top_path, 'PKG-INFO'))
if is_release:
build_from_c_and_cpp_files(config.ext_modules)
else:
message = ('Please install cython with a version >= {0} in order '
'to build a scikit-multiflow development version.').format(
CYTHON_MIN_VERSION)
try:
import Cython
if LooseVersion(Cython.__version__) < CYTHON_MIN_VERSION:
message += ' Your version of Cython was {0}.'.format(
Cython.__version__)
raise ValueError(message)
from Cython.Build import cythonize
except ImportError as exc:
exc.args += (message,)
raise
config.ext_modules = cythonize(config.ext_modules,
compiler_directives={'language_level': 3})
示例3: maybe_cythonize_extensions
# 需要导入模块: import Cython [as 别名]
# 或者: from Cython import Build [as 别名]
def maybe_cythonize_extensions(top_path, config):
"""Tweaks for building extensions between release and development mode."""
is_release = os.path.exists(os.path.join(top_path, 'PKG-INFO'))
if is_release:
build_from_c_and_cpp_files(config.ext_modules)
else:
message = ('Please install cython with a version >= {0} in order '
'to build a scikit-learn development version.').format(
CYTHON_MIN_VERSION)
try:
import Cython
if LooseVersion(Cython.__version__) < CYTHON_MIN_VERSION:
message += ' Your version of Cython was {0}.'.format(
Cython.__version__)
raise ValueError(message)
from Cython.Build import cythonize
except ImportError as exc:
exc.args += (message,)
raise
config.ext_modules = cythonize(config.ext_modules)
示例4: setup_cython_extension
# 需要导入模块: import Cython [as 别名]
# 或者: from Cython import Build [as 别名]
def setup_cython_extension():
try:
from Cython.Build import cythonize
except:
return []
# see tenpy/tools/optimization.py for details on "TENPY_OPTIMIZE"
TENPY_OPTIMIZE = int(os.getenv('TENPY_OPTIMIZE', 1))
include_dirs = [numpy.get_include()]
libs = []
lib_dirs = []
extensions = [
Extension("*", ["tenpy/linalg/*.pyx"],
include_dirs=include_dirs,
libraries=libs,
library_dirs=lib_dirs,
language='c++')
]
comp_direct = { # compiler_directives
'language_level': 3, # use python 3
'embedsignature': True, # write function signature in doc-strings
}
if TENPY_OPTIMIZE > 1:
comp_direct['initializedcheck'] = False
comp_direct['boundscheck'] = False
if TENPY_OPTIMIZE < 1:
comp_direct['profile'] = True
comp_direct['linetrace'] = True
# compile time flags (#DEF ...)
comp_flags = {'TENPY_OPTIMIZE': TENPY_OPTIMIZE}
ext_modules = cythonize(extensions,
compiler_directives=comp_direct,
compile_time_env=comp_flags)
return ext_modules
示例5: run
# 需要导入模块: import Cython [as 别名]
# 或者: from Cython import Build [as 别名]
def run(self):
import Cython
from Cython.Build import cythonize
cythonize(define_extensions(cythonize=True))
示例6: cythonize_extensions
# 需要导入模块: import Cython [as 别名]
# 或者: from Cython import Build [as 别名]
def cythonize_extensions(top_path, config):
"""Check that a recent Cython is available and cythonize extensions"""
_check_cython_version()
from Cython.Build import cythonize
# Fast fail before cythonization if compiler fails compiling basic test
# code even without OpenMP
basic_check_build()
# check simple compilation with OpenMP. If it fails scikit-learn will be
# built without OpenMP and the test test_openmp_supported in the test suite
# will fail.
# `check_openmp_support` compiles a small test program to see if the
# compilers are properly configured to build with OpenMP. This is expensive
# and we only want to call this function once.
# The result of this check is cached as a private attribute on the sklearn
# module (only at build-time) to be used twice:
# - First to set the value of SKLEARN_OPENMP_PARALLELISM_ENABLED, the
# cython build-time variable passed to the cythonize() call.
# - Then in the build_ext subclass defined in the top-level setup.py file
# to actually build the compiled extensions with OpenMP flags if needed.
n_jobs = 1
with contextlib.suppress(ImportError):
import joblib
if LooseVersion(joblib.__version__) > LooseVersion("0.13.0"):
# earlier joblib versions don't account for CPU affinity
# constraints, and may over-estimate the number of available
# CPU particularly in CI (cf loky#114)
n_jobs = joblib.cpu_count()
config.ext_modules = cythonize(
config.ext_modules,
nthreads=n_jobs,
compiler_directives={'language_level': 3})
示例7: maybe_cythonize_extensions
# 需要导入模块: import Cython [as 别名]
# 或者: from Cython import Build [as 别名]
def maybe_cythonize_extensions(top_path, config):
"""Tweaks for building extensions between release and development mode."""
with_openmp = check_openmp_support()
is_release = os.path.exists(os.path.join(top_path, 'PKG-INFO'))
if is_release:
build_from_c_and_cpp_files(config.ext_modules)
else:
message = ('Please install cython with a version >= {0} in order '
'to build a scikit-learn development version.').format(
CYTHON_MIN_VERSION)
try:
import Cython
if LooseVersion(Cython.__version__) < CYTHON_MIN_VERSION:
message += ' Your version of Cython was {0}.'.format(
Cython.__version__)
raise ValueError(message)
from Cython.Build import cythonize
except ImportError as exc:
exc.args += (message,)
raise
config.ext_modules = cythonize(
config.ext_modules,
compile_time_env={'SKLEARN_OPENMP_SUPPORTED': with_openmp},
compiler_directives={'language_level': 3})
示例8: cythonize
# 需要导入模块: import Cython [as 别名]
# 或者: from Cython import Build [as 别名]
def cythonize(extensions, arg_options):
directive_keys = ('linetrace', 'profile')
directives = {key: arg_options[key] for key in directive_keys}
# Embed signatures for Sphinx documentation.
directives['embedsignature'] = True
cythonize_option_keys = ('annotate',)
cythonize_options = {key: arg_options[key]
for key in cythonize_option_keys}
return Cython.Build.cythonize(
extensions, verbose=True, language_level=3,
compiler_directives=directives, **cythonize_options)
示例9: maybe_cythonize_extensions
# 需要导入模块: import Cython [as 别名]
# 或者: from Cython import Build [as 别名]
def maybe_cythonize_extensions(top_path, config):
"""Tweaks for building extensions between release and development mode."""
is_release = os.path.exists(os.path.join(top_path, 'PKG-INFO'))
if is_release:
print("Release detected--building from source files")
build_from_c_f_and_cpp_files(config.ext_modules)
else:
print("Development build detected--building from .pyx & .pyf")
message = ('Please install cython with a version >= {0} in order '
'to build a {1} development version.').format(
CYTHON_MIN_VERSION, DEFAULT_ROOT)
try:
import Cython
loose_cython_ver = LooseVersion(Cython.__version__) # type: str
if loose_cython_ver < CYTHON_MIN_VERSION:
message += ' Your version of Cython was {0}.'.format(
Cython.__version__)
raise ValueError(message)
from Cython.Build import cythonize
except ImportError as exc:
exc.args += (message,)
raise
# cythonize or fortranize...
config.ext_modules = cythonize(config.ext_modules)
示例10: maybe_cythonize_extensions
# 需要导入模块: import Cython [as 别名]
# 或者: from Cython import Build [as 别名]
def maybe_cythonize_extensions(top_path, config):
"""Tweaks for building extensions between release and development mode."""
with_openmp = check_openmp_support()
is_release = os.path.exists(os.path.join(top_path, 'PKG-INFO'))
if is_release:
build_from_c_and_cpp_files(config.ext_modules)
else:
message = ('Please install Cython with a version >= {0} in order '
'to build a sktime development version.').format(
CYTHON_MIN_VERSION)
try:
import Cython
if LooseVersion(Cython.__version__) < CYTHON_MIN_VERSION:
message += ' Your version of Cython was {0}.'.format(
Cython.__version__)
raise ValueError(message)
from Cython.Build import cythonize
except ImportError as exc:
exc.args += (message,)
raise
n_jobs = 1
with contextlib.suppress(ImportError):
import joblib
if LooseVersion(joblib.__version__) > LooseVersion("0.13.0"):
# earlier joblib versions don't account for CPU affinity
# constraints, and may over-estimate the number of available
# CPU particularly in CI (cf loky#114)
n_jobs = joblib.effective_n_jobs()
config.ext_modules = cythonize(
config.ext_modules,
nthreads=n_jobs,
compile_time_env={'SKTIME_OPENMP_SUPPORTED': with_openmp},
compiler_directives={'language_level': 3}
)
示例11: finalize_options
# 需要导入模块: import Cython [as 别名]
# 或者: from Cython import Build [as 别名]
def finalize_options(self):
# finalize_options() may be called multiple times on the
# same command object, so make sure not to override previously
# set options.
if getattr(self, '_initialized', False):
return
import pkg_resources
# Double check Cython presence in case setup_requires
# didn't go into effect (most likely because someone
# imported Cython before setup_requires injected the
# correct egg into sys.path.
try:
import Cython
except ImportError:
raise RuntimeError(
'please install {} to compile edgedb from source'.format(
CYTHON_DEPENDENCY))
cython_dep = pkg_resources.Requirement.parse(CYTHON_DEPENDENCY)
if Cython.__version__ not in cython_dep:
raise RuntimeError(
'edgedb requires {}, got Cython=={}'.format(
CYTHON_DEPENDENCY, Cython.__version__
))
from Cython.Build import cythonize
directives = {
'language_level': '3'
}
if self.cython_directives:
for directive in self.cython_directives.split(','):
k, _, v = directive.partition('=')
if v.lower() == 'false':
v = False
if v.lower() == 'true':
v = True
directives[k] = v
self.distribution.ext_modules[:] = cythonize(
self.distribution.ext_modules,
compiler_directives=directives,
annotate=self.cython_annotate,
include_path=["edb/server/pgproto/"])
super(build_ext, self).finalize_options()
示例12: finalize_options
# 需要导入模块: import Cython [as 别名]
# 或者: from Cython import Build [as 别名]
def finalize_options(self):
# finalize_options() may be called multiple times on the
# same command object, so make sure not to override previously
# set options.
if getattr(self, '_initialized', False):
return
need_cythonize = self.cython_always
cfiles = {}
for extension in self.distribution.ext_modules:
for i, sfile in enumerate(extension.sources):
if sfile.endswith('.pyx'):
prefix, ext = os.path.splitext(sfile)
cfile = prefix + '.c'
if os.path.exists(cfile) and not self.cython_always:
extension.sources[i] = cfile
else:
if os.path.exists(cfile):
cfiles[cfile] = os.path.getmtime(cfile)
else:
cfiles[cfile] = 0
need_cythonize = True
if need_cythonize:
try:
import Cython
except ImportError:
raise RuntimeError(
'please install Cython to compile httptools from source')
if Cython.__version__ < '0.29':
raise RuntimeError(
'httptools requires Cython version 0.29 or greater')
from Cython.Build import cythonize
directives = {}
if self.cython_directives:
for directive in self.cython_directives.split(','):
k, _, v = directive.partition('=')
if v.lower() == 'false':
v = False
if v.lower() == 'true':
v = True
directives[k] = v
self.distribution.ext_modules[:] = cythonize(
self.distribution.ext_modules,
compiler_directives=directives,
annotate=self.cython_annotate)
super().finalize_options()
self._initialized = True