本文整理汇总了Python中numpy.distutils.ccompiler.new_compiler方法的典型用法代码示例。如果您正苦于以下问题:Python ccompiler.new_compiler方法的具体用法?Python ccompiler.new_compiler怎么用?Python ccompiler.new_compiler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy.distutils.ccompiler
的用法示例。
在下文中一共展示了ccompiler.new_compiler方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: have_compiler
# 需要导入模块: from numpy.distutils import ccompiler [as 别名]
# 或者: from numpy.distutils.ccompiler import new_compiler [as 别名]
def have_compiler():
""" Return True if there appears to be an executable compiler
"""
compiler = ccompiler.new_compiler()
try:
cmd = compiler.compiler # Unix compilers
except AttributeError:
try:
compiler.initialize() # MSVC is different
except DistutilsError:
return False
cmd = [compiler.cc]
try:
p = Popen(cmd, stdout=PIPE, stderr=PIPE)
p.stdout.close()
p.stderr.close()
p.wait()
except OSError:
return False
return True
示例2: have_compiler
# 需要导入模块: from numpy.distutils import ccompiler [as 别名]
# 或者: from numpy.distutils.ccompiler import new_compiler [as 别名]
def have_compiler():
""" Return True if there appears to be an executable compiler
"""
compiler = ccompiler.new_compiler()
try:
cmd = compiler.compiler # Unix compilers
except AttributeError:
try:
compiler.initialize() # MSVC is different
except DistutilsError:
return False
cmd = [compiler.cc]
try:
Popen(cmd, stdout=PIPE, stderr=PIPE)
except OSError:
return False
return True
示例3: create_compiler_instance
# 需要导入模块: from numpy.distutils import ccompiler [as 别名]
# 或者: from numpy.distutils.ccompiler import new_compiler [as 别名]
def create_compiler_instance(dist):
# build_ext is in charge of building C/C++ files.
# We are using it and dist to parse config files, and command line
# configurations. There may be other ways to handle this, but I'm
# worried I may miss one of the steps in distutils if I do it my self.
#ext_builder = build_ext(dist)
#ext_builder.finalize_options ()
# For some reason the build_ext stuff wasn't picking up the compiler
# setting, so we grab it manually from the distribution object instead.
opts = dist.command_options.get('build_ext',None)
compiler_name = ''
if opts:
comp = opts.get('compiler',('',''))
compiler_name = comp[1]
# Create a new compiler, customize it based on the build settings,
# and return it.
if not compiler_name:
compiler_name = None
#print compiler_name
compiler = new_compiler(compiler=compiler_name)
customize_compiler(compiler)
return compiler
示例4: have_compiler
# 需要导入模块: from numpy.distutils import ccompiler [as 别名]
# 或者: from numpy.distutils.ccompiler import new_compiler [as 别名]
def have_compiler():
""" Return True if there appears to be an executable compiler
"""
compiler = ccompiler.new_compiler()
compiler.customize(None)
try:
cmd = compiler.compiler # Unix compilers
except AttributeError:
try:
if not compiler.initialized:
compiler.initialize() # MSVC is different
except DistutilsError:
return False
cmd = [compiler.cc]
try:
p = Popen(cmd, stdout=PIPE, stderr=PIPE)
p.stdout.close()
p.stderr.close()
p.wait()
except OSError:
return False
return True
示例5: test_compile2
# 需要导入模块: from numpy.distutils import ccompiler [as 别名]
# 或者: from numpy.distutils.ccompiler import new_compiler [as 别名]
def test_compile2(self):
# Compile source and link the second source
tsi = self.c_temp2
c = ccompiler.new_compiler()
c.customize(None)
extra_link_args = tsi.calc_extra_info()['extra_link_args']
previousDir = os.getcwd()
try:
# Change directory to not screw up directories
os.chdir(self._dir2)
c.compile([os.path.basename(self._src2)], output_dir=self._dir2,
extra_postargs=extra_link_args)
# Ensure that the object exists
assert_(os.path.isfile(self._src2.replace('.c', '.o')))
finally:
os.chdir(previousDir)
示例6: test_compile1
# 需要导入模块: from numpy.distutils import ccompiler [as 别名]
# 或者: from numpy.distutils.ccompiler import new_compiler [as 别名]
def test_compile1(self):
# Compile source and link the first source
c = ccompiler.new_compiler()
previousDir = os.getcwd()
try:
# Change directory to not screw up directories
os.chdir(self._dir1)
c.compile([os.path.basename(self._src1)], output_dir=self._dir1)
# Ensure that the object exists
assert_(os.path.isfile(self._src1.replace('.c', '.o')) or
os.path.isfile(self._src1.replace('.c', '.obj')))
finally:
os.chdir(previousDir)
示例7: test_compile2
# 需要导入模块: from numpy.distutils import ccompiler [as 别名]
# 或者: from numpy.distutils.ccompiler import new_compiler [as 别名]
def test_compile2(self):
# Compile source and link the second source
tsi = self.c_temp2
c = ccompiler.new_compiler()
extra_link_args = tsi.calc_extra_info()['extra_link_args']
previousDir = os.getcwd()
try:
# Change directory to not screw up directories
os.chdir(self._dir2)
c.compile([os.path.basename(self._src2)], output_dir=self._dir2,
extra_postargs=extra_link_args)
# Ensure that the object exists
assert_(os.path.isfile(self._src2.replace('.c', '.o')))
finally:
os.chdir(previousDir)
示例8: test_compile1
# 需要导入模块: from numpy.distutils import ccompiler [as 别名]
# 或者: from numpy.distutils.ccompiler import new_compiler [as 别名]
def test_compile1(self):
# Compile source and link the first source
c = ccompiler.new_compiler()
c.customize(None)
previousDir = os.getcwd()
try:
# Change directory to not screw up directories
os.chdir(self._dir1)
c.compile([os.path.basename(self._src1)], output_dir=self._dir1)
# Ensure that the object exists
assert_(os.path.isfile(self._src1.replace('.c', '.o')) or
os.path.isfile(self._src1.replace('.c', '.obj')))
finally:
os.chdir(previousDir)
示例9: compile_test_program
# 需要导入模块: from numpy.distutils import ccompiler [as 别名]
# 或者: from numpy.distutils.ccompiler import new_compiler [as 别名]
def compile_test_program(code, extra_preargs=[], extra_postargs=[]):
"""Check that some C code can be compiled and run"""
ccompiler = new_compiler()
customize_compiler(ccompiler)
# extra_(pre/post)args can be a callable to make it possible to get its
# value from the compiler
if callable(extra_preargs):
extra_preargs = extra_preargs(ccompiler)
if callable(extra_postargs):
extra_postargs = extra_postargs(ccompiler)
start_dir = os.path.abspath('.')
with tempfile.TemporaryDirectory() as tmp_dir:
try:
os.chdir(tmp_dir)
# Write test program
with open('test_program.c', 'w') as f:
f.write(code)
os.mkdir('objects')
# Compile, test program
ccompiler.compile(['test_program.c'], output_dir='objects',
extra_postargs=extra_postargs)
# Link test program
objects = glob.glob(
os.path.join('objects', '*' + ccompiler.obj_extension))
ccompiler.link_executable(objects, 'test_program',
extra_preargs=extra_preargs,
extra_postargs=extra_postargs)
# Run test program
# will raise a CalledProcessError if return code was non-zero
output = subprocess.check_output('./test_program')
output = output.decode(sys.stdout.encoding or 'utf-8').splitlines()
except Exception:
raise
finally:
os.chdir(start_dir)
return output