def get_include():
"""
Return the directory that contains the NumPy \\*.h header files.
Extension modules that need to compile against NumPy should use this
function to locate the appropriate include directory.
Notes
-----
When using ``distutils``, for example in ``setup.py``.
::
import numpy as np
...
Extension('extension_name', ...
include_dirs=[np.get_include()])
...
"""
import numpy
if numpy.show_config is None:
# running from numpy source directory
d = os.path.join(os.path.dirname(numpy.__file__), 'core', 'include')
else:
# using installed numpy core headers
import numpy.core as core
d = os.path.join(os.path.dirname(core.__file__), 'include')
return d
python类get_include()的实例源码
def get_numpy_include_dirs():
# numpy_include_dirs are set by numpy/core/setup.py, otherwise []
include_dirs = Configuration.numpy_include_dirs[:]
if not include_dirs:
import numpy
include_dirs = [ numpy.get_include() ]
# else running numpy/core/setup.py
return include_dirs
def compile_(self):
"""Translate cython code to C code and compile it."""
from Cython import Build
argv = copy.deepcopy(sys.argv)
sys.argv = [sys.argv[0], 'build_ext', '--build-lib='+self.buildpath]
exc_modules = [
distutils.extension.Extension(
'hydpy.cythons.autogen.'+self.cyname,
[self.cyfilepath], extra_compile_args=['-O2'])]
distutils.core.setup(ext_modules=Build.cythonize(exc_modules),
include_dirs=[numpy.get_include()])
sys.argv = argv
def finalize_options(self):
try:
import cython
import numpy
except ImportError:
raise ImportError(
"""Could not import cython or numpy. Building yt from source requires
cython and numpy to be installed. Please install these packages using
the appropriate package manager for your python environment.""")
if LooseVersion(cython.__version__) < LooseVersion('0.24'):
raise RuntimeError(
"""Building yt from source requires Cython 0.24 or newer but
Cython %s is installed. Please update Cython using the appropriate
package manager for your python environment.""" %
cython.__version__)
if LooseVersion(numpy.__version__) < LooseVersion('1.10.4'):
raise RuntimeError(
"""Building yt from source requires NumPy 1.10.4 or newer but
NumPy %s is installed. Please update NumPy using the appropriate
package manager for your python environment.""" %
numpy.__version__)
from Cython.Build import cythonize
self.distribution.ext_modules[:] = cythonize(
self.distribution.ext_modules)
_build_ext.finalize_options(self)
# Prevent numpy from thinking it is still in its setup process
# see http://stackoverflow.com/a/21621493/1382869
if isinstance(__builtins__, dict):
# sometimes this is a dict so we need to check for that
# https://docs.python.org/3/library/builtins.html
__builtins__["__NUMPY_SETUP__"] = False
else:
__builtins__.__NUMPY_SETUP__ = False
self.include_dirs.append(numpy.get_include())
def configuration(parent_package='', top_path=None):
from numpy.distutils.misc_util import Configuration
config = Configuration('randomkit', parent_package, top_path)
libs = []
if sys.platform == 'win32':
libs.append('Advapi32')
extensions = [Extension('modl.utils.randomkit.random_fast',
sources=['modl/utils/randomkit/random_fast.pyx',
'modl/utils/randomkit/randomkit.c',
'modl/utils/randomkit/distributions.c',
],
language="c++",
include_dirs=[numpy.get_include(),
'modl/utils/randomkit'],
),
Extension('modl.utils.randomkit.sampler',
sources=['modl/utils/randomkit/sampler.pyx'],
language="c++",
include_dirs=[numpy.get_include()]
)]
config.ext_modules += extensions
config.add_subpackage('tests')
return config
def configuration(parent_package='', top_path=None):
from numpy.distutils.misc_util import Configuration
config = Configuration('math', parent_package, top_path)
extensions = [Extension('modl.utils.math.enet',
sources=['modl/utils/math/enet.pyx'],
include_dirs=[numpy.get_include()],
),
]
config.ext_modules += extensions
config.add_subpackage('tests')
return config
def __str__(self):
import pybind11
return pybind11.get_include(self.user)
def __str__(self):
import numpy as np
return np.get_include()
def extension_modules():
import numpy as np
libraries, library_dirs = BuildFortranThenExt.get_library_dirs()
extensions = []
for name, dependencies in FORTRAN_MODULES.items():
if name in ('types', 'status'): # No speedup.
continue
mod_name = 'bezier._{}_speedup'.format(name)
path = SPEEDUP_FILENAME.format(name)
if BuildFortranThenExt.USE_SHARED_LIBRARY:
# Here we don't depend on object files since the functionality
# is contained in the shared library.
extra_objects = []
else:
# NOTE: These may be treated as relative paths and replaced
# before the extension is actually built.
extra_objects = [
OBJECT_FILENAME.format(dependency)
for dependency in dependencies
]
# NOTE: Copy ``libraries`` and ``library_dirs`` so they
# aren't shared (and mutable) between extensions.
extension = setuptools.Extension(
mod_name,
[path],
extra_objects=extra_objects,
include_dirs=[
np.get_include(),
os.path.join('src', 'bezier', 'include'),
],
libraries=copy.deepcopy(libraries),
library_dirs=copy.deepcopy(library_dirs),
)
extensions.append(extension)
return extensions
def __str__(self):
import pybind11
return pybind11.get_include(self.user)
def __str__(self):
import numpy as np
return np.get_include()
# As of Python 3.6, CCompiler has a `has_flag` method.
# cf http://bugs.python.org/issue26689
def finalize_options(self):
global libnumpythia
#global external_fastjet
_build_ext.finalize_options(self)
# Prevent numpy from thinking it is still in its setup process
try:
del builtins.__NUMPY_SETUP__
except AttributeError:
pass
import numpy
libnumpythia.include_dirs.append(numpy.get_include())
def get_include():
return os.path.join(sys.prefix, 'include')
misc_util.py 文件源码
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda
作者: SignalMedia
项目源码
文件源码
阅读 35
收藏 0
点赞 0
评论 0
def get_numpy_include_dirs():
# numpy_include_dirs are set by numpy/core/setup.py, otherwise []
include_dirs = Configuration.numpy_include_dirs[:]
if not include_dirs:
import numpy
include_dirs = [ numpy.get_include() ]
# else running numpy/core/setup.py
return include_dirs
def finalize_options(self):
_build_ext.finalize_options(self)
# Prevent numpy from thinking it is still in its setup process:
__builtins__.__NUMPY_SETUP__ = False
import numpy
self.include_dirs.append(numpy.get_include())
# # This can be loosen probably, though it's fine I think
# min_cython_ver = '0.24.0'
# try:
# import Cython
# ver = Cython.__version__
# _CYTHON_INSTALLED = ver >= LooseVersion(min_cython_ver)
# except ImportError:
# _CYTHON_INSTALLED = False
# try:
# if not _CYTHON_INSTALLED:
# raise ImportError('No supported version of Cython installed.')
# from Cython.Distutils import build_ext
# cython = True
# except ImportError:
# cython = False
# if cython:
# ext = '.pyx'
# cmdclass = {'build_ext': build_ext}
# else:
# ext = '.cpp'
# cmdclass = {}
# if not os.path.exists(join("pyworld", "pyworld" + ext)):
# raise RuntimeError("Cython is required to generate C++ wrapper")
def test_include_dirs(self):
# As a sanity check, just test that get_include
# includes something reasonable. Somewhat
# related to ticket #1405.
include_dirs = [np.get_include()]
for path in include_dirs:
assert_(isinstance(path, (str, unicode)))
assert_(path != '')
def get_include():
"""
Return the directory that contains the NumPy \\*.h header files.
Extension modules that need to compile against NumPy should use this
function to locate the appropriate include directory.
Notes
-----
When using ``distutils``, for example in ``setup.py``.
::
import numpy as np
...
Extension('extension_name', ...
include_dirs=[np.get_include()])
...
"""
import numpy
if numpy.show_config is None:
# running from numpy source directory
d = os.path.join(os.path.dirname(numpy.__file__), 'core', 'include')
else:
# using installed numpy core headers
import numpy.core as core
d = os.path.join(os.path.dirname(core.__file__), 'include')
return d
def get_numpy_include_dirs():
# numpy_include_dirs are set by numpy/core/setup.py, otherwise []
include_dirs = Configuration.numpy_include_dirs[:]
if not include_dirs:
import numpy
include_dirs = [ numpy.get_include() ]
# else running numpy/core/setup.py
return include_dirs
def configuration(parent_package='', top_path=None):
from numpy.distutils.misc_util import Configuration
config = Configuration('sdtw', parent_package, top_path)
config.add_extension('soft_dtw_fast', sources=['soft_dtw_fast.c'],
include_dirs=[numpy.get_include()])
config.add_subpackage('tests')
return config
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()
# cos_module_np = Extension('cos_module_np',
# sources=['PcgComp/kernels/cos_module_np.c'],
# include_dirs=[numpy.get_include()])