本文整理汇总了Python中distutils.errors.CompileError方法的典型用法代码示例。如果您正苦于以下问题:Python errors.CompileError方法的具体用法?Python errors.CompileError怎么用?Python errors.CompileError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类distutils.errors
的用法示例。
在下文中一共展示了errors.CompileError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _compile_cu
# 需要导入模块: from distutils import errors [as 别名]
# 或者: from distutils.errors import CompileError [as 别名]
def _compile_cu(self, sources, output_dir=None, macros=None,
include_dirs=None, debug=0, extra_preargs=None,
extra_postargs=None, depends=None):
# Compile CUDA C files, mainly derived from UnixCCompiler._compile().
macros, objects, extra_postargs, pp_opts, _build = \
self._setup_compile(output_dir, macros, include_dirs, sources,
depends, extra_postargs)
compiler_so = CUDA['nvcc']
cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)
post_args = CUDA['post_args']
for obj in objects:
try:
src, _ = _build[obj]
except KeyError:
continue
try:
self.spawn([compiler_so] + cc_args + [src, '-o', obj] + post_args)
except errors.DistutilsExecError as e:
raise errors.CompileError(str(e))
return objects
示例2: get_ethtool_macro
# 需要导入模块: from distutils import errors [as 别名]
# 或者: from distutils.errors import CompileError [as 别名]
def get_ethtool_macro():
# see: https://github.com/giampaolo/psutil/issues/659
from distutils.unixccompiler import UnixCCompiler
from distutils.errors import CompileError
with tempfile.NamedTemporaryFile(
suffix='.c', delete=False, mode="wt") as f:
f.write("#include <linux/ethtool.h>")
output_dir = tempfile.mkdtemp()
try:
compiler = UnixCCompiler()
# https://github.com/giampaolo/psutil/pull/1568
if os.getenv('CC'):
compiler.set_executable('compiler_so', os.getenv('CC'))
with silenced_output('stderr'):
with silenced_output('stdout'):
compiler.compile([f.name], output_dir=output_dir)
except CompileError:
return ("PSUTIL_ETHTOOL_MISSING_TYPES", 1)
else:
return None
finally:
os.remove(f.name)
shutil.rmtree(output_dir)
示例3: UnixCCompiler__compile
# 需要导入模块: from distutils import errors [as 别名]
# 或者: from distutils.errors import CompileError [as 别名]
def UnixCCompiler__compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
"""Compile a single source files with a Unix-style compiler."""
# HP ad-hoc fix, see ticket 1383
ccomp = self.compiler_so
if ccomp[0] == 'aCC':
# remove flags that will trigger ANSI-C mode for aCC
if '-Ae' in ccomp:
ccomp.remove('-Ae')
if '-Aa' in ccomp:
ccomp.remove('-Aa')
# add flags for (almost) sane C++ handling
ccomp += ['-AA']
self.compiler_so = ccomp
display = '%s: %s' % (os.path.basename(self.compiler_so[0]), src)
try:
self.spawn(self.compiler_so + cc_args + [src, '-o', obj] +
extra_postargs, display = display)
except DistutilsExecError:
msg = str(get_exception())
raise CompileError(msg)
示例4: get_cpp_flags
# 需要导入模块: from distutils import errors [as 别名]
# 或者: from distutils.errors import CompileError [as 别名]
def get_cpp_flags(build_ext):
last_err = None
default_flags = ['-std=c++11', '-fPIC', '-O2']
if sys.platform == 'darwin':
# Darwin most likely will have Clang, which has libc++.
flags_to_try = [default_flags + ['-stdlib=libc++'], default_flags]
else:
flags_to_try = [default_flags, default_flags + ['-stdlib=libc++']]
for cpp_flags in flags_to_try:
try:
test_compile(build_ext, 'test_cpp_flags', extra_preargs=cpp_flags,
code=textwrap.dedent('''\
#include <unordered_map>
void test() {
}
'''))
return cpp_flags
except (CompileError, LinkError):
last_err = 'Unable to determine C++ compilation flags (see error above).'
except Exception:
last_err = 'Unable to determine C++ compilation flags. ' \
'Last error:\n\n%s' % traceback.format_exc()
raise DistutilsPlatformError(last_err)
示例5: get_tf_libs
# 需要导入模块: from distutils import errors [as 别名]
# 或者: from distutils.errors import CompileError [as 别名]
def get_tf_libs(build_ext, lib_dirs, cpp_flags):
last_err = None
for tf_libs in [['tensorflow_framework'], []]:
try:
lib_file = test_compile(build_ext, 'test_tensorflow_libs',
library_dirs=lib_dirs, libraries=tf_libs,
extra_preargs=cpp_flags,
code=textwrap.dedent('''\
void test() {
}
'''))
from tensorflow.python.framework import load_library
load_library.load_op_library(lib_file)
return tf_libs
except (CompileError, LinkError):
last_err = 'Unable to determine -l link flags to use with TensorFlow (see error above).'
except Exception:
last_err = 'Unable to determine -l link flags to use with TensorFlow. ' \
'Last error:\n\n%s' % traceback.format_exc()
raise DistutilsPlatformError(last_err)
示例6: has_flag
# 需要导入模块: from distutils import errors [as 别名]
# 或者: from distutils.errors import CompileError [as 别名]
def has_flag(compiler, flagname, output_dir=None):
# see https://bugs.python.org/issue26689
"""Return a boolean indicating whether a flag name is supported on
the specified compiler.
"""
with tempfile.NamedTemporaryFile('w', suffix='.c', delete=False) as f:
f.write('int main (int argc, char **argv) { return 0; }')
f.close()
try:
obj = compiler.compile([f.name], output_dir=output_dir,
extra_postargs=[flagname])
os.remove(*obj)
except CompileError:
return False
finally:
os.remove(f.name)
return True
示例7: prevent_msvc_compiling_patch
# 需要导入模块: from distutils import errors [as 别名]
# 或者: from distutils.errors import CompileError [as 别名]
def prevent_msvc_compiling_patch(): # type: ignore
import distutils
import distutils._msvccompiler
import distutils.msvc9compiler
import distutils.msvccompiler
from distutils.errors import CompileError
def raise_compile_error(*args, **kwargs): # type: ignore
raise CompileError('Chalice blocked C extension compiling.')
distutils._msvccompiler.MSVCCompiler.compile = raise_compile_error
distutils.msvc9compiler.MSVCCompiler.compile = raise_compile_error
distutils.msvccompiler.MSVCCompiler.compile = raise_compile_error
# This is the setuptools shim used to execute setup.py by pip.
# Lines 2 and 3 have been added to call the above function
# `prevent_msvc_compiling_patch` and extra escapes have been added on line
# 5 because it is passed through another layer of string parsing before it
# is executed.
示例8: _compile
# 需要导入模块: from distutils import errors [as 别名]
# 或者: from distutils.errors import CompileError [as 别名]
def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
if ext == '.rc' or ext == '.res':
# gcc needs '.res' and '.rc' compiled to object files !!!
try:
self.spawn(["windres", "-i", src, "-o", obj])
except DistutilsExecError, msg:
raise CompileError, msg
示例9: _compile
# 需要导入模块: from distutils import errors [as 别名]
# 或者: from distutils.errors import CompileError [as 别名]
def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
if ext == '.rc':
# gcc requires '.rc' compiled to binary ('.res') files !!!
try:
self.spawn(["rc", "-r", src])
except DistutilsExecError, msg:
raise CompileError, msg
示例10: UnixCCompiler__compile
# 需要导入模块: from distutils import errors [as 别名]
# 或者: from distutils.errors import CompileError [as 别名]
def UnixCCompiler__compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
"""Compile a single source files with a Unix-style compiler."""
# HP ad-hoc fix, see ticket 1383
ccomp = self.compiler_so
if ccomp[0] == 'aCC':
# remove flags that will trigger ANSI-C mode for aCC
if '-Ae' in ccomp:
ccomp.remove('-Ae')
if '-Aa' in ccomp:
ccomp.remove('-Aa')
# add flags for (almost) sane C++ handling
ccomp += ['-AA']
self.compiler_so = ccomp
# ensure OPT environment variable is read
if 'OPT' in os.environ:
from distutils.sysconfig import get_config_vars
opt = " ".join(os.environ['OPT'].split())
gcv_opt = " ".join(get_config_vars('OPT')[0].split())
ccomp_s = " ".join(self.compiler_so)
if opt not in ccomp_s:
ccomp_s = ccomp_s.replace(gcv_opt, opt)
self.compiler_so = ccomp_s.split()
llink_s = " ".join(self.linker_so)
if opt not in llink_s:
self.linker_so = llink_s.split() + opt.split()
display = '%s: %s' % (os.path.basename(self.compiler_so[0]), src)
try:
self.spawn(self.compiler_so + cc_args + [src, '-o', obj] +
extra_postargs, display = display)
except DistutilsExecError:
msg = str(get_exception())
raise CompileError(msg)
示例11: build_extension
# 需要导入模块: from distutils import errors [as 别名]
# 或者: from distutils.errors import CompileError [as 别名]
def build_extension(self, ext):
try:
build_ext.build_extension(self, ext)
except (CCompilerError, CompileError, DistutilsExecError) as e:
self._unavailable(e)
self.extensions = [] # avoid copying missing files (it would fail).
示例12: _compile_helper
# 需要导入模块: from distutils import errors [as 别名]
# 或者: from distutils.errors import CompileError [as 别名]
def _compile_helper(self, content):
conftest = open("conftest.c", "w")
try:
with conftest:
conftest.write(content)
try:
self.compiler.compile(["conftest.c"], output_dir='')
except CompileError:
return False
return True
finally:
self._remove_conftest()
示例13: has_flag
# 需要导入模块: from distutils import errors [as 别名]
# 或者: from distutils.errors import CompileError [as 别名]
def has_flag(compiler, flagname):
"""Return a boolean indicating whether a flag name is supported on
the specified compiler.
"""
import tempfile
with tempfile.NamedTemporaryFile("w", suffix=".cpp") as f:
f.write("int main (int argc, char **argv) { return 0; }")
try:
compiler.compile([f.name], extra_postargs=[flagname])
except setuptools.distutils.errors.CompileError:
return False
return True
示例14: get_tf_abi
# 需要导入模块: from distutils import errors [as 别名]
# 或者: from distutils.errors import CompileError [as 别名]
def get_tf_abi(build_ext, include_dirs, lib_dirs, libs, cpp_flags):
last_err = None
cxx11_abi_macro = '_GLIBCXX_USE_CXX11_ABI'
for cxx11_abi in ['0', '1']:
try:
lib_file = test_compile(build_ext, 'test_tensorflow_abi',
macros=[(cxx11_abi_macro, cxx11_abi)],
include_dirs=include_dirs, library_dirs=lib_dirs,
libraries=libs, extra_preargs=cpp_flags,
code=textwrap.dedent('''\
#include <string>
#include "tensorflow/core/framework/op.h"
#include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/framework/shape_inference.h"
void test() {
auto ignore = tensorflow::strings::StrCat("a", "b");
}
'''))
from tensorflow.python.framework import load_library
load_library.load_op_library(lib_file)
return cxx11_abi_macro, cxx11_abi
except (CompileError, LinkError):
last_err = 'Unable to determine CXX11 ABI to use with TensorFlow (see error above).'
except Exception:
last_err = 'Unable to determine CXX11 ABI to use with TensorFlow. ' \
'Last error:\n\n%s' % traceback.format_exc()
raise DistutilsPlatformError(last_err)
示例15: get_cuda_dirs
# 需要导入模块: from distutils import errors [as 别名]
# 或者: from distutils.errors import CompileError [as 别名]
def get_cuda_dirs(build_ext, cpp_flags):
cuda_include_dirs = []
cuda_lib_dirs = []
cuda_home = os.environ.get('HOROVOD_CUDA_HOME')
if cuda_home:
cuda_include_dirs += ['%s/include' % cuda_home]
cuda_lib_dirs += ['%s/lib' % cuda_home, '%s/lib64' % cuda_home]
cuda_include = os.environ.get('HOROVOD_CUDA_INCLUDE')
if cuda_include:
cuda_include_dirs += [cuda_include]
cuda_lib = os.environ.get('HOROVOD_CUDA_LIB')
if cuda_lib:
cuda_lib_dirs += [cuda_lib]
if not cuda_include_dirs and not cuda_lib_dirs:
# default to /usr/local/cuda
cuda_include_dirs += ['/usr/local/cuda/include']
cuda_lib_dirs += ['/usr/local/cuda/lib', '/usr/local/cuda/lib64']
try:
test_compile(build_ext, 'test_cuda', libraries=['cudart'], include_dirs=cuda_include_dirs,
library_dirs=cuda_lib_dirs, extra_preargs=cpp_flags, code=textwrap.dedent('''\
#include <cuda_runtime.h>
void test() {
cudaSetDevice(0);
}
'''))
except (CompileError, LinkError):
raise DistutilsPlatformError(
'CUDA library was not found (see error above).\n'
'Please specify correct CUDA location with the HOROVOD_CUDA_HOME '
'environment variable or combination of HOROVOD_CUDA_INCLUDE and '
'HOROVOD_CUDA_LIB environment variables.\n\n'
'HOROVOD_CUDA_HOME - path where CUDA include and lib directories can be found\n'
'HOROVOD_CUDA_INCLUDE - path to CUDA include directory\n'
'HOROVOD_CUDA_LIB - path to CUDA lib directory')
return cuda_include_dirs, cuda_lib_dirs