Python distutils.errors.CompileError() Examples
The following are 30
code examples of distutils.errors.CompileError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
distutils.errors
, or try the search function
.
Example #1
Source File: setup.py From training_results_v0.6 with Apache License 2.0 | 6 votes |
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)
Example #2
Source File: compat.py From chalice with Apache License 2.0 | 6 votes |
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.
Example #3
Source File: unixccompiler.py From ImageFusion with MIT License | 6 votes |
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)
Example #4
Source File: setup.py From training_results_v0.6 with Apache License 2.0 | 6 votes |
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)
Example #5
Source File: setup.py From xrayutilities with GNU General Public License v2.0 | 6 votes |
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
Example #6
Source File: unixccompiler.py From Computable with MIT License | 6 votes |
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)
Example #7
Source File: unixccompiler.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
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)
Example #8
Source File: cuda_setup.py From implicit with MIT License | 6 votes |
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
Example #9
Source File: setup.py From psutil with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #10
Source File: cygwinccompiler.py From canape with GNU General Public License v3.0 | 5 votes |
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
Example #11
Source File: cygwinccompiler.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
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
Example #12
Source File: emxccompiler.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
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
Example #13
Source File: emxccompiler.py From unity-python with MIT License | 5 votes |
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
Example #14
Source File: cygwinccompiler.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
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
Example #15
Source File: emxccompiler.py From canape with GNU General Public License v3.0 | 5 votes |
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
Example #16
Source File: cygwinccompiler.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
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
Example #17
Source File: emxccompiler.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
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
Example #18
Source File: unixccompiler.py From keras-lambda with MIT License | 5 votes |
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)
Example #19
Source File: cygwinccompiler.py From unity-python with MIT License | 5 votes |
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
Example #20
Source File: emxccompiler.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
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
Example #21
Source File: dist.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def _compile_helper(self, content): conftest = open("conftest.c", "w") try: conftest.write(content) conftest.close() try: self.compiler.compile(["conftest.c"], output_dir='') except CompileError: return False return True finally: self._remove_conftest()
Example #22
Source File: emxccompiler.py From medicare-demo with Apache License 2.0 | 5 votes |
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
Example #23
Source File: cygwinccompiler.py From medicare-demo with Apache License 2.0 | 5 votes |
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
Example #24
Source File: dist.py From python-for-android with Apache License 2.0 | 5 votes |
def _compile_helper(self, content): conftest = open("conftest.c", "w") try: conftest.write(content) conftest.close() try: self.compiler.compile(["conftest.c"], output_dir='') except CompileError: return False return True finally: self._remove_conftest()
Example #25
Source File: emxccompiler.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
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
Example #26
Source File: cygwinccompiler.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
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
Example #27
Source File: emxccompiler.py From datafari with Apache License 2.0 | 5 votes |
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
Example #28
Source File: cygwinccompiler.py From datafari with Apache License 2.0 | 5 votes |
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
Example #29
Source File: setup.py From openTSNE with BSD 3-Clause "New" or "Revised" License | 5 votes |
def has_c_library(library, extension=".c"): """Check whether a C/C++ library is available on the system to the compiler. Parameters ---------- library: str The library we want to check for e.g. if we are interested in FFTW3, we want to check for `fftw3.h`, so this parameter will be `fftw3`. extension: str If we want to check for a C library, the extension is `.c`, for C++ `.cc`, `.cpp` or `.cxx` are accepted. Returns ------- bool Whether or not the library is available. """ with tempfile.TemporaryDirectory(dir=".") as directory: name = join(directory, "%s%s" % (library, extension)) with open(name, "w") as f: f.write("#include <%s.h>\n" % library) f.write("int main() {}\n") # Get a compiler instance compiler = ccompiler.new_compiler() # Configure compiler to do all the platform specific things customize_compiler(compiler) # Add conda include dirs for inc_dir in get_include_dirs(): compiler.add_include_dir(inc_dir) assert isinstance(compiler, ccompiler.CCompiler) try: # Try to compile the file using the C compiler compiler.link_executable(compiler.compile([name]), name) return True except (CompileError, LinkError): return False
Example #30
Source File: setup_utils.py From nvtx-plugins with Apache License 2.0 | 5 votes |
def get_tf_abi(build_ext, include_dirs, lib_dirs, libs, cpp_flags): 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_compile_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)