def configure_pyexe(exe, config_cmd): from distutils import sysconfig if sys.platform.startswith('win'): return if (sys.platform == 'darwin' and ('Anaconda' in sys.version or 'Continuum Analytics' in sys.version)): py_version = sysconfig.get_python_version() py_abiflags = getattr(sys, 'abiflags', '') exe.libraries += ['python' + py_version + py_abiflags] return # from distutils.util import split_quoted cfg_vars = sysconfig.get_config_vars() libraries = [] library_dirs = [] link_args = [] if not sysconfig.get_config_var('Py_ENABLE_SHARED'): py_version = sysconfig.get_python_version() py_abiflags = getattr(sys, 'abiflags', '') libraries = ['python' + py_version + py_abiflags] if sys.platform == 'darwin': fwkdir = cfg_vars.get('PYTHONFRAMEWORKDIR') if (fwkdir and fwkdir != 'no-framework' and fwkdir in cfg_vars.get('LINKFORSHARED', '')): del libraries[:] for var in ('LIBDIR', 'LIBPL'): library_dirs += split_quoted(cfg_vars.get(var, '')) for var in ('LDFLAGS', 'LIBS', 'MODLIBS', 'SYSLIBS', 'LDLAST'): link_args += split_quoted(cfg_vars.get(var, '')) exe.libraries += libraries exe.library_dirs += library_dirs exe.extra_link_args += link_args
def configure_compiler(self, compiler): if compiler.compiler_type != 'unix': return getenv = os.environ.get # distutils C/C++ compiler (cc, cflags, ccshared, cxx) = get_config_vars( 'CC', 'CFLAGS', 'CCSHARED', 'CXX') ccshared = getenv('CCSHARED', ccshared or '') cflags = getenv('CFLAGS', cflags or '') cflags = cflags.replace('-Wstrict-prototypes', '') # distutils linker (ldflags, ldshared, so_ext) = get_config_vars( 'LDFLAGS', 'LDSHARED', 'SO') ld = cc ldshared = getenv('LDSHARED', ldshared) ldflags = getenv('LDFLAGS', cflags + ' ' + (ldflags or '')) ldcmd = split_quoted(ld) + split_quoted(ldflags) ldshared = [flg for flg in split_quoted(ldshared) if flg not in ldcmd] ldshared = str.join(' ', ldshared) # def get_flags(cmd): try: return ' '.join(split_quoted(cmd)[1:]) except: return '' # PETSc C compiler PCC = self['PCC'] PCC_FLAGS = get_flags(cc) + ' ' + self['PCC_FLAGS'] PCC_FLAGS = PCC_FLAGS.replace('-fvisibility=hidden', '') PCC = getenv('PCC', PCC) + ' ' + getenv('PCCFLAGS', PCC_FLAGS) PCC_SHARED = str.join(' ', (PCC, ccshared, cflags)) # PETSc C++ compiler PCXX = PCC if self.language == 'c++' else self.get('CXX', cxx) # PETSc linker PLD = self['PCC_LINKER'] PLD_FLAGS = get_flags(ld) + ' ' + self['PCC_LINKER_FLAGS'] PLD_FLAGS = PLD_FLAGS.replace('-fvisibility=hidden', '') PLD = getenv('PLD', PLD) + ' ' + getenv('PLDFLAGS', PLD_FLAGS) PLD_SHARED = str.join(' ', (PLD, ldshared, ldflags)) # compiler.set_executables( compiler = PCC, compiler_cxx = PCXX, linker_exe = PLD, compiler_so = PCC_SHARED, linker_so = PLD_SHARED, ) compiler.shared_lib_extension = so_ext # if sys.platform == 'darwin': for attr in ('preprocessor', 'compiler', 'compiler_cxx', 'compiler_so', 'linker_so', 'linker_exe'): compiler_cmd = getattr(compiler, attr, []) while '-mno-fused-madd' in compiler_cmd: compiler_cmd.remove('-mno-fused-madd')
def bootstrap(): # Set PETSC_DIR and PETSC_ARCH PETSC_DIR = os.path.abspath(os.getcwd()) PETSC_ARCH = 'arch-python-' + get_platform() os.environ['PETSC_DIR'] = PETSC_DIR os.environ['PETSC_ARCH'] = PETSC_ARCH sys.path.insert(0, os.path.join(PETSC_DIR, 'config')) sys.path.insert(0, os.path.join(PETSC_DIR, 'lib','petsc','conf')) # Generate package __init__.py file from distutils.dir_util import mkpath pkgdir = os.path.join('config', 'pypi') if not os.path.exists(pkgdir): mkpath(pkgdir) pkgfile = os.path.join(pkgdir, '__init__.py') fh = open(pkgfile, 'w') fh.write(init_py) fh.close() # Configure options options = os.environ.get('PETSC_CONFIGURE_OPTIONS', '') CONFIGURE_OPTIONS.extend(split_quoted(options)) if '--with-mpi=0' not in CONFIGURE_OPTIONS: # Simple-minded lookup for MPI and mpi4py mpi4py = mpicc = None try: import mpi4py conf = mpi4py.get_config() mpicc = conf.get('mpicc') except ImportError: # mpi4py is not installed mpi4py = None mpicc = (os.environ.get('MPICC') or find_executable('mpicc')) except AttributeError: # mpi4py is too old pass if not mpi4py and mpicc: metadata['install_requires'] = ['mpi4py>=1.2.2']
def set_command(self, key, value): if not key in self._executable_keys: raise ValueError("unknown executable '%s' for class %s" % (key, self.__class__.__name__)) if is_string(value): value = split_quoted(value) assert value is None or is_sequence_of_strings(value[1:]), (key, value) self.executables[key] = value
def customize_compiler(compiler, lang=None, mpicc=None, mpicxx=None, mpild=None): """ Implements the compiler configuration. """ # Unix specific compilation customization assert compiler.compiler_type == 'unix' sysconfig.customize_compiler(compiler) ld = compiler.linker_exe for envvar in ('LDFLAGS', 'CFLAGS', 'CPPFLAGS'): if envvar in os.environ: ld += split_quoted(os.environ[envvar]) # Compiler command overriding if mpicc: fix_compiler_cmd(compiler.compiler, mpicc) if lang in ('c', None): fix_compiler_cmd(compiler.compiler_so, mpicc) if mpicxx: fix_compiler_cmd(compiler.compiler_cxx, mpicxx) if lang == 'c++': fix_compiler_cmd(compiler.compiler_so, mpicxx) if mpild: for ld in [compiler.linker_so, compiler.linker_exe]: fix_linker_cmd(ld, mpild) badcxxflags = ['-Wimplicit', '-Wstrict-prototypes'] for flag in badcxxflags: while flag in compiler.compiler_cxx: compiler.compiler_cxx.remove(flag) if lang == 'c++': while flag in compiler.compiler_so: compiler.compiler_so.remove(flag)
def read_setup_file (filename): from distutils.sysconfig import \ parse_makefile, expand_makefile_vars, _variable_rx from distutils.text_file import TextFile from distutils.util import split_quoted # First pass over the file to gather "VAR = VALUE" assignments. vars = parse_makefile(filename) # Second pass to gobble up the real content: lines of the form # <module> ... [<sourcefile> ...] [<cpparg> ...] [<library> ...] file = TextFile(filename, strip_comments=1, skip_blanks=1, join_lines=1, lstrip_ws=1, rstrip_ws=1) extensions = [] while 1: line = file.readline() if line is None: # eof break if _variable_rx.match(line): # VAR=VALUE, handled in first pass continue if line[0] == line[-1] == "*": file.warn("'%s' lines not handled yet" % line) continue #print "original line: " + line line = expand_makefile_vars(line, vars) words = split_quoted(line) #print "expanded line: " + line # NB. this parses a slightly different syntax than the old # makesetup script: here, there must be exactly one extension per # line, and it must be the first word of the line. I have no idea # why the old syntax supported multiple extensions per line, as # they all wind up being the same. module = words[0] ext = Extension(module, []) append_next_word = None for word in words[1:]: if append_next_word is not None: append_next_word.append(word) append_next_word = None continue suffix = os.path.splitext(word)[1] switch = word[0:2] ; value = word[2:] if suffix in (".c", ".cc", ".cpp", ".cxx", ".c++", ".m", ".mm"): # hmm, should we do something about C vs. C++ sources? # or leave it up to the CCompiler implementation to # worry about? ext.sources.append(word) elif switch == "-I": ext.include_dirs.append(value) elif
def finalize_options(self): build.finalize_options(self) self.optimize_dimensions = (parse_ranges(self.optimize_dimensions) if self.optimize_dimensions is not None else DEFAULT_OPTIMIZED_DIMENSIONS) self.cpp_opts = split_quoted(self.cpp_opts) self.copy_mingw_deps = strtobool(self.copy_mingw_deps) if self.copy_mingw_deps is not None else True
def find_exe(cmd, path=None): if not cmd: return None parts = split_quoted(cmd) exe, args = parts[0], parts[1:] if not os.path.isabs(exe) and path: exe = os.path.basename(exe) exe = find_executable(exe, path) if not exe: return None return ' '.join([exe]+args)
def fix_compiler_cmd(cc, mpicc): if not mpicc: return i = 0 while os.path.basename(cc[i]) == 'env': i = i + 1 while '=' in cc[i]: i = i + 1 while os.path.basename(cc[i]) == 'ccache': i = i + 1 cc[i:i+1] = split_quoted(mpicc)
def finalize_options(self): if isinstance(self.templates, basestring): self.templates = split_quoted(self.templates) self.templates += getattr(self.distribution.metadata, 'templates', None) or [] for tmpl in self.templates: if not tmpl.endswith(self.template_ext): raise ValueError("Template file '%s' does not have expected " "extension '%s'." % (tmpl, self.template_ext))
def get_mysql_config(self, option): args = [self.mysql_config, '--%s' % option] print ' '.join(args) try: proc = subprocess.Popen(args, stdout=subprocess.PIPE) except: print 'failed to execute', args[0] raise stdout, _ = proc.communicate() return split_quoted(stdout.strip())
def run_command(exe, args): from distutils.spawn import find_executable from distutils.util import split_quoted cmd = find_executable(exe) if not cmd: return [] if not isinstance(args, str): args = ' '.join(args) try: with os.popen(cmd + ' ' + args) as f: return split_quoted(f.read()) except: return []
def detect_ssl_backend(self): ssl_lib_detected = None if 'PYCURL_SSL_LIBRARY' in os.environ: ssl_lib = os.environ['PYCURL_SSL_LIBRARY'] if ssl_lib in ['openssl', 'gnutls', 'nss', 'mbedtls']: ssl_lib_detected = ssl_lib getattr(self, 'using_%s' % ssl_lib)() else: raise ConfigurationError( 'Invalid value "%s" for PYCURL_SSL_LIBRARY' % ssl_lib) option = self.detect_ssl_option() if option: ssl_lib_detected = option.replace('--with-', '') self.ssl_options()[option]() # ssl detection - ssl libraries are added if not ssl_lib_detected: libcurl_dll_path = scan_argv(self.argv, "--libcurl-dll=") if libcurl_dll_path is not None: ssl_lib_detected = self.detect_ssl_lib_from_libcurl_dll( libcurl_dll_path) if not ssl_lib_detected: # self.sslhintbuf is a hack for arg in split_quoted(self.sslhintbuf): if arg[:2] == "-l": if arg[2:] == 'ssl': self.using_openssl() ssl_lib_detected = 'openssl' break if arg[2:] == 'gnutls': self.using_gnutls() ssl_lib_detected = 'gnutls' break if arg[2:] == 'ssl3': self.using_nss() ssl_lib_detected = 'nss' break if arg[2:] == 'mbedtls': self.using_mbedtls() ssl_lib_detected = 'mbedtls' break if not ssl_lib_detected and len(self.argv) == len(self.original_argv) \ and not os.environ.get('PYCURL_CURL_CONFIG') \ and not os.environ.get('PYCURL_SSL_LIBRARY'): # this path should only be taken when no options or # configuration environment variables are given to setup.py ssl_lib_detected = self.detect_ssl_lib_on_centos6() self.ssl_lib_detected = ssl_lib_detected
def fix_linker_cmd(ld, mpild): if not mpild: return i = 0 if (sys.platform.startswith('aix') and os.path.basename(ld[i]) == 'ld_so_aix'): i = 1 while os.path.basename(ld[i]) == 'env': i = i + 1 while '=' in ld[i]: i = i + 1 while os.path.basename(ld[i]) == 'ccache': del ld[i] ld[i:i+1] = split_quoted(mpild)
def configure_pyexe(exe, config_cmd): from distutils import sysconfig if sys.platform.startswith('win'): return if (sys.platform == 'darwin' and ('Anaconda' in sys.version or 'Continuum Analytics' in sys.version)): py_version = sysconfig.get_python_version() py_abiflags = getattr(sys, 'abiflags', '') exe.libraries += ['python' + py_version + py_abiflags] return # from distutils.util import split_quoted cfg_vars = sysconfig.get_config_vars() libraries = [] library_dirs = [] link_args = [] if not sysconfig.get_config_var('Py_ENABLE_SHARED'): py_version = sysconfig.get_python_version() py_abiflags = getattr(sys, 'abiflags', '') libraries = ['python' + py_version + py_abiflags] if hasattr(sys, 'pypy_version_info'): py_tag = py_version[0].replace('2', '') libraries = ['pypy%s-c' % py_tag] if sys.platform == 'darwin': fwkdir = cfg_vars.get('PYTHONFRAMEWORKDIR') if (fwkdir and fwkdir != 'no-framework' and fwkdir in cfg_vars.get('LINKFORSHARED', '')): del libraries[:] for var in ('LIBDIR', 'LIBPL'): library_dirs += split_quoted(cfg_vars.get(var, '')) for var in ('LDFLAGS', 'LIBS', 'MODLIBS', 'SYSLIBS', 'LDLAST'): link_args += split_quoted(cfg_vars.get(var, '')) exe.libraries += libraries exe.library_dirs += library_dirs exe.extra_link_args += link_args
def configure_extension(self, extension): # define macros macros = [('PETSC_DIR', self['PETSC_DIR'])] extension.define_macros.extend(macros) # includes and libraries petsc_inc = flaglist(self['PETSC_CC_INCLUDES']) petsc_lib = flaglist('-L%s %s' % (self['PETSC_LIB_DIR'], self['PETSC_LIB_BASIC'])) petsc_lib['runtime_library_dirs'].append(self['PETSC_LIB_DIR']) petsc_ext_lib = split_quoted(self['PETSC_EXTERNAL_LIB_BASIC']) petsc_lib['extra_link_args'].extend(petsc_ext_lib) # self._configure_ext(extension, petsc_inc, preppend=True) self._configure_ext(extension, petsc_lib)
def __get_flags(self, command, envvar=None, confvar=None): if command is None: var = [] elif is_string(command): var = self.executables[command][1:] else: var = command() if envvar is not None: var = os.environ.get(envvar, var) if confvar is not None: var = confvar[0].get(confvar[1], [None,var])[1] if is_string(var): var = split_quoted(var) return var
def configure_extension(self, extension): # define macros macros = [('PETSC_DIR', self['PETSC_DIR'])] extension.define_macros.extend(macros) # includes and libraries petsc_inc = flaglist(self['PETSC_CC_INCLUDES']) petsc_lib = flaglist( '-L%s %s' % (self['PETSC_LIB_DIR'], self['PETSC_LIB_BASIC'])) petsc_lib['runtime_library_dirs'].append(self['PETSC_LIB_DIR']) petsc_ext_lib = split_quoted(self['PETSC_EXTERNAL_LIB_BASIC']) petsc_lib['extra_link_args'].extend(petsc_ext_lib) # self._configure_ext(extension, petsc_inc, preppend=True) self._configure_ext(extension, petsc_lib)
def __get_flags(self, command, envvar=None, confvar=None): if command is None: var = [] elif type(command) is type(''): var = self.executables[command][1:] else: var = command() if envvar is not None: var = os.environ.get(envvar, var) if confvar is not None: var = confvar[0].get(confvar[1], [None,var])[1] if type(var) is type(''): var = split_quoted(var) return var
def bootstrap(): # Set PETSC_DIR and PETSC_ARCH PETSC_DIR = os.path.abspath(os.getcwd()) PETSC_ARCH = 'arch-python-' + get_platform() os.environ['PETSC_DIR'] = PETSC_DIR os.environ['PETSC_ARCH'] = PETSC_ARCH sys.path.insert(0, os.path.join(PETSC_DIR, 'config')) sys.path.insert(0, os.path.join(PETSC_DIR, 'lib', 'petsc', 'conf')) # Generate package __init__.py file from distutils.dir_util import mkpath pkgdir = os.path.join('config', 'pypi') if not os.path.exists(pkgdir): mkpath(pkgdir) pkgfile = os.path.join(pkgdir, '__init__.py') fh = open(pkgfile, 'w') fh.write(init_py) fh.close() # Configure options options = os.environ.get('PETSC_CONFIGURE_OPTIONS', '') CONFIGURE_OPTIONS.extend(split_quoted(options)) for i in CONFIGURE_OPTIONS: if i.startswith('--with-mpi-dir='): raise RuntimeError( "Do not use --with-mpi-dir, use the environmental variables MPICC, MPICXX, MPIF90" ) if i.startswith('--with-cc='): raise RuntimeError( "Do not use --with-cc, use the environmental variable MPICC") if i.startswith('--with-cxx=') and i != "--with-cxx=0": raise RuntimeError( "Do not use --with-cxx, use the environmental variable MPICXX") if i.startswith('--with-fc=') and i != "--with-fc=0": raise RuntimeError( "Do not use --with-fc, use the environmental variable MPIF90") if '--with-mpi=0' not in CONFIGURE_OPTIONS: # Simple-minded lookup for MPI and mpi4py mpi4py = mpicc = None try: import mpi4py conf = mpi4py.get_config() mpicc = conf.get('mpicc') except ImportError: # mpi4py is not installed mpi4py = None mpicc = (os.environ.get('MPICC') or find_executable('mpicc')) except AttributeError: # mpi4py is too old pass if not mpi4py and mpicc: metadata['install_requires'] = ['mpi4py>=1.2.2']
def detect_ssl_backend(self): ssl_lib_detected = False if 'PYCURL_SSL_LIBRARY' in os.environ: ssl_lib = os.environ['PYCURL_SSL_LIBRARY'] if ssl_lib in ['openssl', 'gnutls', 'nss']: ssl_lib_detected = True getattr(self, 'using_%s' % ssl_lib)() else: raise ConfigurationError('Invalid value "%s" for PYCURL_SSL_LIBRARY' % ssl_lib) option = self.detect_ssl_option() if option: ssl_lib_detected = True self.ssl_options()[option]() # ssl detection - ssl libraries are added if not ssl_lib_detected: libcurl_dll_path = scan_argv(self.argv, "--libcurl-dll=") if libcurl_dll_path is not None: if self.detect_ssl_lib_from_libcurl_dll(libcurl_dll_path): ssl_lib_detected = True if not ssl_lib_detected: # self.sslhintbuf is a hack for arg in split_quoted(self.sslhintbuf): if arg[:2] == "-l": if arg[2:] == 'ssl': self.using_openssl() ssl_lib_detected = True break if arg[2:] == 'gnutls': self.using_gnutls() ssl_lib_detected = True break if arg[2:] == 'ssl3': self.using_nss() ssl_lib_detected = True break if not ssl_lib_detected and len(self.argv) == len(self.original_argv) \ and not os.environ.get('PYCURL_CURL_CONFIG') \ and not os.environ.get('PYCURL_SSL_LIBRARY'): # this path should only be taken when no options or # configuration environment variables are given to setup.py ssl_lib_detected = self.detect_ssl_lib_on_centos6() self.ssl_lib_detected = ssl_lib_detected
def configure_extension(self, extension): # includes and libraries petsc_inc = flaglist(self['PETSC_CC_INCLUDES']) petsc_lib = flaglist('-L%s %s' % (self['PETSC_LIB_DIR'], self['PETSC_LIB_BASIC'])) # runtime_library_dirs is not supported on Windows if sys.platform != 'win32': petsc_lib['runtime_library_dirs'].append(self['PETSC_LIB_DIR']) # Link in extra libraries on static builds if self['BUILDSHAREDLIB'] != 'yes': petsc_ext_lib = split_quoted(self['PETSC_EXTERNAL_LIB_BASIC']) petsc_lib['extra_link_args'].extend(petsc_ext_lib) self._configure_ext(extension, petsc_inc, preppend=True) self._configure_ext(extension, petsc_lib)
def config(dry_run=False): log.info('PETSc: configure') options = [ 'PETSC_ARCH='+os.environ['PETSC_ARCH'], '--with-shared-libraries=1', '--with-debugging=0', '--with-c2html=0', # not needed ] # MPI try: import mpi4py conf = mpi4py.get_config() mpicc = conf.get('mpicc') mpicxx = conf.get('mpicxx') mpif90 = conf.get('mpif90') except (ImportError, AttributeError): mpicc = os.environ.get('MPICC') or find_executable('mpicc') mpicxx = os.environ.get('MPICXX') or find_executable('mpicxx') mpif90 = os.environ.get('MPIF90') or find_executable('mpif90') if mpicc: options.append('--with-cc='+mpicc) if mpicxx: options.append('--with-cxx='+mpicxx) else: options.append('--with-cxx=0') if mpif90: options.append('--with-fc='+mpif90) else: options.append('--with-fc=0') options.append('--with-sowing=0') else: options.append('--with-mpi=0') # Extra configure options config_opts = os.environ.get('PETSC_CONFIGURE_OPTIONS', '') config_opts = split_quoted(config_opts) options.extend(config_opts) log.info('configure options:') for opt in options: log.info(' '*4 + opt) # Run PETSc configure if dry_run: return import configure configure.petsc_configure(options) import logger logger.Logger.defaultLog = None
def detect_features(self): p = subprocess.Popen((self.curl_config(), '--features'), stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() if p.wait() != 0: msg = "Problem running `%s' --features" % self.curl_config() if stderr: msg += ":\n" + stderr.decode() raise ConfigurationError(msg) curl_has_ssl = False for feature in split_quoted(stdout.decode()): if feature == 'SSL': # this means any ssl library, not just openssl. # we set the ssl flag to check for ssl library mismatch # at link time and run time self.define_macros.append(('HAVE_CURL_SSL', 1)) curl_has_ssl = True self.curl_has_ssl = curl_has_ssl
def _fix_options(opt): if not isinstance(opt, str): return opt try: opt = split_quoted(opt) except: return opt try: i = opt.index('-B') del opt[i:i + 2] except ValueError: pass try: i = opt.index('-Wl,--sysroot=/') del opt[i] except ValueError: pass return " ".join(opt)
def get_f77flags(src): """ Search the first 20 lines of fortran 77 code for line pattern `CF77FLAGS(<fcompiler type>)=<f77 flags>` Return a dictionary {<fcompiler type>:<f77 flags>}. """ flags = {} with open(src, encoding='latin1') as f: i = 0 for line in f: i += 1 if i>20: break m = _f77flags_re.match(line) if not m: continue fcname = m.group('fcname').strip() fflags = m.group('fflags').strip() flags[fcname] = split_quoted(fflags) return flags
def get_f77flags(src): """ Search the first 20 lines of fortran 77 code for line pattern `CF77FLAGS(<fcompiler type>)=<f77 flags>` Return a dictionary {<fcompiler type>:<f77 flags>}. """ flags = {} f = open_latin1(src, 'r') i = 0 for line in f: i += 1 if i>20: break m = _f77flags_re.match(line) if not m: continue fcname = m.group('fcname').strip() fflags = m.group('fflags').strip() flags[fcname] = split_quoted(fflags) f.close() return flags
def get_f77flags(src): """ Search the first 20 lines of fortran 77 code for line pattern `CF77FLAGS(<fcompiler type>)=<f77 flags>` Return a dictionary {<fcompiler type>:<f77 flags>}. """ flags = {} f = open_latin1(src, 'r') i = 0 for line in f.readlines(): i += 1 if i > 20: break m = _f77flags_re.match(line) if not m: continue fcname = m.group('fcname').strip() fflags = m.group('fflags').strip() flags[fcname] = split_quoted(fflags) f.close() return flags
def configure_extension(self, extension): # define macros macros = [('PETSC_DIR', self['PETSC_DIR'])] extension.define_macros.extend(macros) # includes and libraries petsc_inc = flaglist(self['PETSC_CC_INCLUDES']) petsc_lib = flaglist( '-L%s %s' % (self['PETSC_LIB_DIR'], self['PETSC_LIB_BASIC'])) # runtime_library_dirs is not supported on Windows if sys.platform != 'win32': petsc_lib['runtime_library_dirs'].append(self['PETSC_LIB_DIR']) # Link in extra libraries on static builds if self['BUILDSHAREDLIB'] != 'yes': petsc_ext_lib = split_quoted(self['PETSC_EXTERNAL_LIB_BASIC']) petsc_lib['extra_link_args'].extend(petsc_ext_lib) self._configure_ext(extension, petsc_inc, preppend=True) self._configure_ext(extension, petsc_lib)
def config(dry_run=False): log.info('PETSc: configure') options = [ 'PETSC_ARCH=' + os.environ['PETSC_ARCH'], '--with-shared-libraries=1', '--with-debugging=0', '--with-c2html=0', # not needed #'--with-sowing=0', #'--with-cmake=0', ] # MPI try: import mpi4py conf = mpi4py.get_config() mpicc = conf.get('mpicc') mpicxx = conf.get('mpicxx') mpif90 = conf.get('mpif90') except (ImportError, AttributeError): mpicc = os.environ.get('MPICC') or find_executable('mpicc') mpicxx = os.environ.get('MPICXX') or find_executable('mpicxx') mpif90 = os.environ.get('MPIF90') or find_executable('mpif90') if mpicc: options.append('--with-cc=' + mpicc) if mpicxx: options.append('--with-cxx=' + mpicxx) if mpif90: options.append('--with-fc=' + mpif90) else: options.append('--with-mpi=0') # Extra configure options config_opts = os.environ.get('PETSC_CONFIGURE_OPTIONS', '') config_opts = split_quoted(config_opts) options.extend(config_opts) log.info('configure options:') for opt in options: log.info(' ' * 4 + opt) # Run PETSc configure if dry_run: return import configure configure.petsc_configure(options) import logger logger.Logger.defaultLog = None
def bootstrap(): from os.path import join, isdir, abspath # Set SLEPC_DIR SLEPC_DIR = abspath(os.getcwd()) os.environ['SLEPC_DIR'] = SLEPC_DIR # Check PETSC_DIR/PETSC_ARCH PETSC_DIR = os.environ.get('PETSC_DIR', "") PETSC_ARCH = os.environ.get('PETSC_ARCH', "") if not (PETSC_DIR and isdir(PETSC_DIR)): PETSC_DIR = None try: del os.environ['PETSC_DIR'] except KeyError: pass PETSC_ARCH = None try: del os.environ['PETSC_ARCH'] except KeyError: pass elif not (PETSC_ARCH and isdir(join(PETSC_DIR, PETSC_ARCH))): PETSC_ARCH = None try: del os.environ['PETSC_ARCH'] except KeyError: pass # Generate package __init__.py file from distutils.dir_util import mkpath pkgdir = os.path.join(SLEPC_DIR, 'pypi') pkgfile = os.path.join(pkgdir, '__init__.py') if not os.path.exists(pkgdir): mkpath(pkgdir) fh = open(pkgfile, 'wt') fh.write(init_py) fh.close() # Configure options options = os.environ.get('PETSC_CONFIGURE_OPTIONS', '') CONFIGURE_OPTIONS.extend(split_quoted(options)) # if not PETSC_DIR: vstr = version().split('.')[:2] x, y = int(vstr[0]), int(vstr[1]) reqs = ">=%s.%s,<%s.%s" % (x, y, x, y + 1) metadata['install_requires'] = ['petsc' + reqs]
def _lsub(self): if self._lsub_cache is not None: return self._lsub_cache # im.lsub() returns a relatively raw response like # ['(\Nochildren \Seen \Bacon) "/" "INBOX"', # '() "/" "lists/reddit-dev_googlegroups_com"', # '() "/" "lists/commits.couchdb.apache.org"' ] folders_descr = im_resp(im.lsub()) folders = [] for x in folders_descr: folders_descr = [ split_quoted(x) for x in folders_descr ] # we're going to force the use of / as a separator, even if # the server disagrees folders = [ '/'.join(x[2].split(x[1])) for x in folders_descr ] self._lsub_cache = folders return self._lsub_cache def _copymove(self, new_folder, delete): if new_folder not in self._lsub(): print "I can't find \"%s\" on the remote side" % newfolder return next_msg_num = self._find_next_msg_num() im_resp.copy(self.messages[self.current_message_index][0], new_folder) if delete: self._set_flag('\\Deleted') self._reload() self._try_select_msg_num(next_msg_num) if self.messages: self.do_messages(None) self.do_show(None)
def config(prefix, dry_run=False): log.info('UW: configure') options = [ '--prefix=' + prefix, '--with-debugging=0', ] try: import mpi4py conf = mpi4py.get_config() mpicc = conf.get('mpicc') mpicxx = conf.get('mpicxx') except AttributeError: mpicc = os.environ.get('MPICC') or find_executable('mpicc') mpicxx = os.environ.get('MPICXX') or find_executable('mpicxx') if mpicc: options.append('--cc=' + mpicc) if mpicxx: options.append('--cxx=' + mpicxx) options.extend(split_quoted(os.environ.get('UW_CONFIGURE_OPTIONS', ''))) if 'PETSC_DIR' in os.environ: options.append('--petsc-dir=' + os.environ['PETSC_DIR']) else: try: import petsc options.append('--petsc-dir=' + petsc.get_config()['PETSC_DIR']) except: pass log.info('configure options:') for opt in options: log.info(' ' * 4 + opt) # Run UW configure if dry_run: return python = find_executable('python3') command = [python, './configure.py'] + options status = os.system(" ".join(command)) if status != 0: raise RuntimeError(status)
def configure_extension(self, extension): # includes and libraries # paths in PETSc config files point to final installation location, but # we might be building against PETSc in staging location (DESTDIR) when # DESTDIR is set, so append DESTDIR (if nonempty) to those paths petsc_inc = flaglist(prepend_to_flags(self.DESTDIR, self['PETSC_CC_INCLUDES'])) lib_flags = prepend_to_flags(self.DESTDIR, '-L%s %s' % \ (self['PETSC_LIB_DIR'], self['PETSC_LIB_BASIC'])) petsc_lib = flaglist(lib_flags) # runtime_library_dirs is not supported on Windows if sys.platform != 'win32': # if DESTDIR is set, then we're building against PETSc in a staging # directory, but rpath needs to point to final install directory. rpath = strip_prefix(self.DESTDIR, self['PETSC_LIB_DIR']) petsc_lib['runtime_library_dirs'].append(rpath) # Link in extra libraries on static builds if self['BUILDSHAREDLIB'] != 'yes': petsc_ext_lib = split_quoted(self['PETSC_EXTERNAL_LIB_BASIC']) petsc_lib['extra_link_args'].extend(petsc_ext_lib) self._configure_ext(extension, petsc_inc, preppend=True) self._configure_ext(extension, petsc_lib)
def set_exe(exe_key, f77=None, f90=None): cmd = self.executables.get(exe_key, None) if not cmd: return None # Note that we get cmd[0] here if the environment doesn't # have anything set exe_from_environ = getattr(self.command_vars, exe_key) if not exe_from_environ: possibles = [f90, f77] + self.possible_executables else: possibles = [exe_from_environ] + self.possible_executables seen = set() unique_possibles = [] for e in possibles: if e == '<F77>': e = f77 elif e == '<F90>': e = f90 if not e or e in seen: continue seen.add(e) unique_possibles.append(e) for exe in unique_possibles: # Chaquopy: handle multi-word executables like LDSHARED="path/to/gcc -shared" exe_split = split_quoted(exe) fc_exe = cached_find_executable(exe_split[0]) if fc_exe: cmd[0] = fc_exe for arg in exe_split[1:]: if arg not in cmd: cmd.append(arg) return fc_exe self.set_command(exe_key, None) return None
def read_setup_file(filename): """Reads a Setup file and returns Extension instances.""" from distutils.sysconfig import (parse_makefile, expand_makefile_vars, _variable_rx) from distutils.text_file import TextFile from distutils.util import split_quoted # First pass over the file to gather "VAR = VALUE" assignments. vars = parse_makefile(filename) # Second pass to gobble up the real content: lines of the form # <module> ... [<sourcefile> ...] [<cpparg> ...] [<library> ...] file = TextFile(filename, strip_comments=1, skip_blanks=1, join_lines=1, lstrip_ws=1, rstrip_ws=1) extensions = [] while True: line = file.readline() if line is None: # eof break if _variable_rx.match(line): # VAR=VALUE, handled in first pass continue if line[0] == line[-1] == "*": file.warn("'%s' lines not handled yet" % line) continue line = expand_makefile_vars(line, vars) words = split_quoted(line) # NB. this parses a slightly different syntax than the old # makesetup script: here, there must be exactly one extension per # line, and it must be the first word of the line. I have no idea # why the old syntax supported multiple extensions per line, as # they all wind up being the same. module = words[0] ext = Extension(module, []) append_next_word = None for word in words[1:]: if append_next_word is not None: append_next_word.append(word) append_next_word = None continue suffix = os.path.splitext(word)[1] switch = word[0:2] ; value = word[2:] if suffix in (".c", ".cc", ".cpp", ".cxx", ".c++", ".m", ".mm"): # hmm, should we do something about C vs. C++ sources? # or leave it up to the CCompiler implementation to # worry about? ext.sources.append(word) elif switch == "-I": ext.include_dirs.append(value) elif switch == "-D": equals = value.find("=") if equals == -1: # bare "-DFOO" -- no value ext.define_macros.append((value, None)) else: # "-DFOO=blah" ext.define_macros.append((value[0:equals], value[equals+2:])) elif switch == "-U": ext.undef_macros.append(value) elif switch == "-C": # only here 'cause makesetup has it! ext.extra_compile_args.append(word) elif switch == "-l": ext.libraries.append(value) elif switch == "-L": ext.library_dirs.append(value) elif switch == "-R": ext.runtime_library_dirs.append(value) elif word == "-rpath": append_next_word = ext.runtime_library_dirs elif word == "-Xlinker": append_next_word = ext.extra_link_args elif word == "-Xcompiler": append_next_word = ext.extra_compile_args elif switch == "-u": ext.extra_link_args.append(word) if not value: append_next_word = ext.extra_link_args elif suffix in (".a", ".so", ".sl", ".o", ".dylib"): # NB. a really faithful emulation of makesetup would # append a .o file to extra_objects only if it # had a slash in it; otherwise, it would s/.o/.c/ # and append it to sources. Hmmmm. ext.extra_objects.append(word) else: file.warn("unrecognized argument '%s'" % word) extensions.append(ext) return extensions
def set_executable(self, key, value): if type(value) is StringType: setattr(self, key, split_quoted(value)) else: setattr(self, key, value)
def flaglist(s): if is_string(s): return split_quoted(s) else: return s
def get_flags(cmd): try: return ' '.join(split_quoted(cmd)[1:]) except: return ''
def read_setup_file(filename): """Reads a Setup file and returns Extension instances.""" from distutils.sysconfig import (parse_makefile, expand_makefile_vars, _variable_rx) from distutils.text_file import TextFile from distutils.util import split_quoted # First pass over the file to gather "VAR = VALUE" assignments. vars = parse_makefile(filename) # Second pass to gobble up the real content: lines of the form # <module> ... [<sourcefile> ...] [<cpparg> ...] [<library> ...] file = TextFile(filename, strip_comments=1, skip_blanks=1, join_lines=1, lstrip_ws=1, rstrip_ws=1) try: extensions = [] while True: line = file.readline() if line is None: # eof break if _variable_rx.match(line): # VAR=VALUE, handled in first pass continue if line[0] == line[-1] == "*": file.warn("'%s' lines not handled yet" % line) continue line = expand_makefile_vars(line, vars) words = split_quoted(line) # NB. this parses a slightly different syntax than the old # makesetup script: here, there must be exactly one extension per # line, and it must be the first word of the line. I have no idea # why the old syntax supported multiple extensions per line, as # they all wind up being the same. module = words[0] ext = Extension(module, []) append_next_word = None for word in words[1:]: if append_next_word is not None: append_next_word.append(word) append_next_word = None continue suffix = os.path.splitext(word)[1] switch = word[0:2] value = word[2:] if suffix in (".c", ".cc", ".cpp", ".cxx", ".c++", ".m", ".mm"): # hmm, should we do something about C vs. C++ sources? # or leave it up to the CCompiler implementation to # worry about? ext.sources.append(word) elif switch == "-I": ext.include_dirs.append(value) elif switch == "-D": equals = value.find("=") if equals == -1: # bare "-DFOO" -- no value ext.define_macros.append((value, None)) else: # "-DFOO=blah" ext.define_macros.append( (value[0:equals], value[equals + 2:])) elif switch == "-U": ext.undef_macros.append(value) elif switch == "-C": # only here 'cause makesetup has it! ext.extra_compile_args.append(word) elif switch == "-l": ext.libraries.append(value) elif switch == "-L": ext.library_dirs.append(value) elif switch == "-R": ext.runtime_library_dirs.append(value) elif word == "-rpath": append_next_word = ext.runtime_library_dirs elif word == "-Xlinker": append_next_word = ext.extra_link_args elif word == "-Xcompiler": append_next_word = ext.extra_compile_args elif switch == "-u": ext.extra_link_args.append(word) if not value: append_next_word = ext.extra_link_args elif suffix in (".a", ".so", ".sl", ".o", ".dylib"): # NB. a really faithful emulation of makesetup would # append a .o file to extra_objects only if it # had a slash in it; otherwise, it would s/.o/.c/ # and append it to sources. Hmmmm. ext.extra_objects.append(word) else: file.warn("unrecognized argument '%s'" % word) extensions.append(ext) finally: file.close() return extensions
def test_split_quoted(self): self.assertEqual(split_quoted('""one"" "two" \'three\' \\four'), ['one', 'two', 'three', 'four'])
def configure_unix(self): OPENSSL_DIR = scan_argv(self.argv, "--openssl-dir=") if OPENSSL_DIR is not None: self.include_dirs.append(os.path.join(OPENSSL_DIR, "include")) self.library_dirs.append(os.path.join(OPENSSL_DIR, "lib")) CURL_CONFIG = os.environ.get('PYCURL_CURL_CONFIG', "curl-config") CURL_CONFIG = scan_argv(self.argv, "--curl-config=", CURL_CONFIG) try: p = subprocess.Popen((CURL_CONFIG, '--version'), stdout=subprocess.PIPE, stderr=subprocess.PIPE) except OSError: exc = sys.exc_info()[1] msg = 'Could not run curl-config: %s' % str(exc) raise ConfigurationError(msg) stdout, stderr = p.communicate() if p.wait() != 0: msg = "`%s' not found -- please install the libcurl development files or specify --curl-config=/path/to/curl-config" % CURL_CONFIG if stderr: msg += ":\n" + stderr.decode() raise ConfigurationError(msg) libcurl_version = stdout.decode().strip() print("Using %s (%s)" % (CURL_CONFIG, libcurl_version)) p = subprocess.Popen((CURL_CONFIG, '--cflags'), stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() if p.wait() != 0: msg = "Problem running `%s' --cflags" % CURL_CONFIG if stderr: msg += ":\n" + stderr.decode() raise ConfigurationError(msg) for arg in split_quoted(stdout.decode()): if arg[:2] == "-I": # do not add /usr/include if not re.search(r"^\/+usr\/+include\/*$", arg[2:]): self.include_dirs.append(arg[2:]) else: self.extra_compile_args.append(arg) # Obtain linker flags/libraries to link against. # In theory, all we should need is `curl-config --libs`. # Apparently on some platforms --libs fails and --static-libs works, # so try that. # If --libs succeeds do not try --static-libs; see # https://github.com/pycurl/pycurl/issues/52 for more details. # If neither --libs nor --static-libs work, fail. # # --libs/--static-libs are also used for SSL detection. # libcurl may be configured such that --libs only includes -lcurl # without any of libcurl's dependent libraries, but the dependent # libraries would be included in --static-libs (unless libcurl # was built with static libraries disabled). # Therefore we largely ignore (see below) --static-libs output for # libraries and flags if --libs succeeded, but consult both outputs # for hints as to which SSL library libcurl is linked against. # More information: https://github.com/pycurl/pycurl/pull/147 # # The final point is we should link agaist the SSL library in use # even if libcurl does not tell us to, because *we* invoke functions # in that SSL library. This means any SSL libraries found in # --static-libs are forwarded to our libraries. optbuf = '' sslhintbuf = '' errtext = '' for option in ["--libs", "--static-libs"]: p = subprocess.Popen((CURL_CONFIG, option), stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() if p.wait() == 0: if optbuf == '': # first successful call optbuf = stdout.decode() # optbuf only has output from this call sslhintbuf += optbuf else: # second successful call sslhintbuf += stdout.decode() else: if optbuf == '': # no successful call yet errtext += stderr.decode() else: # first call succeeded and second call failed # ignore stderr and the error exit pass if optbuf == "": msg = "Neither curl-config --libs nor curl-config --static-libs" +\ " succeeded and produced output" if errtext: msg += ":\n" + errtext raise ConfigurationError(msg) ssl_lib_detected = False if 'PYCURL_SSL_LIBRARY' in os.environ: ssl_lib = os.environ['PYCURL_SSL_LIBRARY'] if ssl_lib in ['openssl', 'gnutls', 'nss']: ssl_lib_detected = True getattr(self, 'using_%s' % ssl_lib)() else: raise ConfigurationError('Invalid value "%s" for PYCURL_SSL_LIBRARY' % ssl_lib) ssl_options = { '--with-openssl': self.using_openssl, '--with-ssl': self.using_openssl, '--with-gnutls': self.using_gnutls, '--with-nss': self.using_nss, } for option in ssl_options: if scan_argv(self.argv, option) is not None: for other_option in ssl_options: if option != other_option: if scan_argv(self.argv, other_option) is not None: raise ConfigurationError('Cannot give both %s and %s' % (option, other_option)) ssl_lib_detected = True ssl_options[option]() break # libraries and options - all libraries and options are forwarded # but if --libs succeeded, --static-libs output is ignored for arg in split_quoted(optbuf): if arg[:2] == "-l": self.libraries.append(arg[2:]) elif arg[:2] == "-L": self.library_dirs.append(arg[2:]) else: self.extra_link_args.append(arg) # ssl detection - ssl libraries are added if not ssl_lib_detected: libcurl_dll_path = scan_argv(self.argv, "--libcurl-dll=") if libcurl_dll_path is not None: if self.detect_ssl_lib_from_libcurl_dll(libcurl_dll_path): ssl_lib_detected = True if not ssl_lib_detected: for arg in split_quoted(sslhintbuf): if arg[:2] == "-l": if arg[2:] == 'ssl': self.using_openssl() ssl_lib_detected = True break if arg[2:] == 'gnutls': self.using_gnutls() ssl_lib_detected = True break if arg[2:] == 'ssl3': self.using_nss() ssl_lib_detected = True break if not ssl_lib_detected and len(self.argv) == len(self.original_argv) \ and not os.environ.get('PYCURL_CURL_CONFIG') \ and not os.environ.get('PYCURL_SSL_LIBRARY'): # this path should only be taken when no options or # configuration environment variables are given to setup.py ssl_lib_detected = self.detect_ssl_lib_on_centos6() if not ssl_lib_detected: p = subprocess.Popen((CURL_CONFIG, '--features'), stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() if p.wait() != 0: msg = "Problem running `%s' --features" % CURL_CONFIG if stderr: msg += ":\n" + stderr.decode() raise ConfigurationError(msg) for feature in split_quoted(stdout.decode()): if feature == 'SSL': # this means any ssl library, not just openssl. # we set the ssl flag to check for ssl library mismatch # at link time and run time self.define_macros.append(('HAVE_CURL_SSL', 1)) if not self.libraries: self.libraries.append("curl") # Add extra compile flag for MacOS X if sys.platform[:-1] == "darwin": self.extra_link_args.append("-flat_namespace") # Recognize --avoid-stdio on Unix so that it can be tested self.check_avoid_stdio()
def main(QEMU, BINDIRBASE, HEXFILE, DEBUGGER=None): def run_shell(): nonlocal result while 1: try: line = input() if line == 'quit': result = 0 raise EOFError() except EOFError: qemu.kill() return client_file.write((line + '\r\n').encode('UTF-8')) def read_terminal(): for line in client_file: print('{}: {}'.format( get_timestamp(), line.decode('UTF-8', 'replace').rstrip("\r\n"))) if isinstance(QEMU, str): QEMU = split_quoted(QEMU) if DEBUGGER and isinstance(DEBUGGER, str): DEBUGGER = split_quoted(DEBUGGER) histfile = os.path.join(BINDIRBASE, '.qemu-term.hist') try: readline.read_history_file(histfile) except IOError: pass result = 1 try: sock = socket.socket() sock.settimeout(60) sock.bind(('', 0)) sock.listen(1) host, port = sock.getsockname() args = QEMU + [ '-serial', 'tcp:{}:{}'.format(host, port), '-nographic', '-monitor', '/dev/null', '-kernel', HEXFILE, ] if DEBUGGER: args += ['-s', '-S'] try: qemu = popen(args) if DEBUGGER: ignore_sig_int = lambda: signal.signal(signal.SIGINT, signal. SIG_IGN) popen(DEBUGGER, preexec_fn=ignore_sig_int) client_sock, _ = sock.accept() client_file = client_sock.makefile('rwb', 1) sock.close() threading.Thread(target=run_shell, daemon=True).start() threading.Thread(target=read_terminal, daemon=True).start() try: result = qemu.wait() and result except KeyboardInterrupt: print('Interrupted ...') result = 0 finally: try: qemu.kill() except: pass finally: try: readline.write_history_file(histfile) except: pass try: client_sock.close() except: pass return result
def read_setup_file(filename): from distutils.sysconfig import parse_makefile, expand_makefile_vars, _variable_rx from distutils.text_file import TextFile from distutils.util import split_quoted vars = parse_makefile(filename) file = TextFile(filename, strip_comments=1, skip_blanks=1, join_lines=1, lstrip_ws=1, rstrip_ws=1) try: extensions = [] while 1: line = file.readline() if line is None: break if _variable_rx.match(line): continue if line[0] == line[-1] == '*': file.warn("'%s' lines not handled yet" % line) continue line = expand_makefile_vars(line, vars) words = split_quoted(line) module = words[0] ext = Extension(module, []) append_next_word = None for word in words[1:]: if append_next_word is not None: append_next_word.append(word) append_next_word = None continue suffix = os.path.splitext(word)[1] switch = word[0:2] value = word[2:] if suffix in ('.c', '.cc', '.cpp', '.cxx', '.c++', '.m', '.mm'): ext.sources.append(word) elif switch == '-I': ext.include_dirs.append(value) elif switch == '-D': equals = string.find(value, '=') if equals == -1: ext.define_macros.append((value, None)) else: ext.define_macros.append((value[0:equals], value[equals + 2:])) elif switch == '-U': ext.undef_macros.append(value) elif switch == '-C': ext.extra_compile_args.append(word) elif switch == '-l': ext.libraries.append(value) elif switch == '-L': ext.library_dirs.append(value) elif switch == '-R': ext.runtime_library_dirs.append(value) elif word == '-rpath': append_next_word = ext.runtime_library_dirs elif word == '-Xlinker': append_next_word = ext.extra_link_args elif word == '-Xcompiler': append_next_word = ext.extra_compile_args elif switch == '-u': ext.extra_link_args.append(word) if not value: append_next_word = ext.extra_link_args elif word == '-Xcompiler': append_next_word = ext.extra_compile_args elif switch == '-u': ext.extra_link_args.append(word) if not value: append_next_word = ext.extra_link_args elif suffix in ('.a', '.so', '.sl', '.o', '.dylib'): ext.extra_objects.append(word) else: file.warn("unrecognized argument '%s'" % word) extensions.append(ext) finally: file.close() return extensions
def test_split_quoted(self): self.assertEquals(split_quoted('""one"" "two" \'three\' \\four'), ['one', 'two', 'three', 'four'])
def configure_unix(self): OPENSSL_DIR = scan_argv(self.argv, "--openssl-dir=") if OPENSSL_DIR is not None: self.include_dirs.append(os.path.join(OPENSSL_DIR, "include")) self.library_dirs.append(os.path.join(OPENSSL_DIR, "lib")) try: p = subprocess.Popen((self.curl_config(), '--version'), stdout=subprocess.PIPE, stderr=subprocess.PIPE) except OSError: exc = sys.exc_info()[1] msg = 'Could not run curl-config: %s' % str(exc) raise ConfigurationError(msg) stdout, stderr = p.communicate() if p.wait() != 0: msg = "`%s' not found -- please install the libcurl development files or specify --curl-config=/path/to/curl-config" % self.curl_config( ) if stderr: msg += ":\n" + stderr.decode() raise ConfigurationError(msg) libcurl_version = stdout.decode().strip() print("Using %s (%s)" % (self.curl_config(), libcurl_version)) p = subprocess.Popen((self.curl_config(), '--cflags'), stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() if p.wait() != 0: msg = "Problem running `%s' --cflags" % self.curl_config() if stderr: msg += ":\n" + stderr.decode() raise ConfigurationError(msg) for arg in split_quoted(stdout.decode()): if arg[:2] == "-I": # do not add /usr/include if not re.search(r"^\/+usr\/+include\/*$", arg[2:]): self.include_dirs.append(arg[2:]) else: self.extra_compile_args.append(arg) # Obtain linker flags/libraries to link against. # In theory, all we should need is `curl-config --libs`. # Apparently on some platforms --libs fails and --static-libs works, # so try that. # If --libs succeeds do not try --static-libs; see # https://github.com/pycurl/pycurl/issues/52 for more details. # If neither --libs nor --static-libs work, fail. # # --libs/--static-libs are also used for SSL detection. # libcurl may be configured such that --libs only includes -lcurl # without any of libcurl's dependent libraries, but the dependent # libraries would be included in --static-libs (unless libcurl # was built with static libraries disabled). # Therefore we largely ignore (see below) --static-libs output for # libraries and flags if --libs succeeded, but consult both outputs # for hints as to which SSL library libcurl is linked against. # More information: https://github.com/pycurl/pycurl/pull/147 # # The final point is we should link agaist the SSL library in use # even if libcurl does not tell us to, because *we* invoke functions # in that SSL library. This means any SSL libraries found in # --static-libs are forwarded to our libraries. optbuf = '' sslhintbuf = '' errtext = '' for option in ["--libs", "--static-libs"]: p = subprocess.Popen((self.curl_config(), option), stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() if p.wait() == 0: if optbuf == '': # first successful call optbuf = stdout.decode() # optbuf only has output from this call sslhintbuf += optbuf else: # second successful call sslhintbuf += stdout.decode() else: if optbuf == '': # no successful call yet errtext += stderr.decode() else: # first call succeeded and second call failed # ignore stderr and the error exit pass if optbuf == "": msg = "Neither curl-config --libs nor curl-config --static-libs" +\ " succeeded and produced output" if errtext: msg += ":\n" + errtext raise ConfigurationError(msg) # hack self.sslhintbuf = sslhintbuf self.detect_features() if self.curl_has_ssl: self.detect_ssl_backend() if not self.ssl_lib_detected: raise ConfigurationError('''\ Curl is configured to use SSL, but we have not been able to determine \ which SSL backend it is using. Please see PycURL documentation for how to \ specify the SSL backend manually.''') else: if self.detect_ssl_option(): sys.stderr.write( "Warning: SSL backend specified manually but libcurl does not use SSL\n" ) # libraries and options - all libraries and options are forwarded # but if --libs succeeded, --static-libs output is ignored for arg in split_quoted(optbuf): if arg[:2] == "-l": self.libraries.append(arg[2:]) elif arg[:2] == "-L": self.library_dirs.append(arg[2:]) else: self.extra_link_args.append(arg) if not self.libraries: self.libraries.append("curl") # Add extra compile flag for MacOS X if sys.platform[:-1] == "darwin": self.extra_link_args.append("-flat_namespace") # Recognize --avoid-stdio on Unix so that it can be tested self.check_avoid_stdio()
def configure_compiler(self, compiler): if compiler.compiler_type != 'unix': return (cc, cxx, cflags, ccshared, ldflags, ldshared, so_ext) = get_config_vars( 'CC', 'CXX', 'CFLAGS', 'CCSHARED', 'LDFLAGS', 'LDSHARED', 'SO') cflags = cflags or '' ldflags = ldflags or '' cflags = cflags.replace('-Wstrict-prototypes', '') ld = cc ldshared = ldshared.replace(ld, '', 1).strip() ldshared = [flg for flg in split_quoted(ldshared) if flg not in split_quoted(ldflags)] ldshared = str.join(' ', ldshared) # getenv = os.environ.get def get_flags(cmd): try: return ' '.join(split_quoted(cmd)[1:]) except: return '' # C compiler PCC = self['PCC'] PCC_FLAGS = get_flags(cc) + ' ' + self['PCC_FLAGS'] PCC_FLAGS = PCC_FLAGS.replace('-fvisibility=hidden', '') if sys.version_info[:2] < (2, 5): PCC_FLAGS = PCC_FLAGS.replace('-Wwrite-strings', '') PCC = getenv('PCC', PCC) + ' ' + getenv('PCCFLAGS', PCC_FLAGS) ccshared = getenv('CCSHARED', ccshared) cflags = getenv('CFLAGS', cflags) PCC_SHARED = str.join(' ', (PCC, ccshared, cflags)) # C++ compiler if self.language == 'c++': PCXX = PCC else: try: PCXX = self['CXX'] except KeyError: PCXX = cxx # linker PLD = self['PCC_LINKER'] PLD_FLAGS = get_flags(ld) + ' ' + self['PCC_LINKER_FLAGS'] PLD_FLAGS = PLD_FLAGS.replace('-fvisibility=hidden', '') PLD = getenv('PLD', PLD) + ' ' + getenv('PLDFLAGS', PLD_FLAGS) ldshared = getenv('LDSHARED', ldshared) ldflags = getenv('LDFLAGS', cflags + ' ' + ldflags) PLD_SHARED = str.join(' ', (PLD, ldshared, ldflags)) # compiler.set_executables( compiler = PCC, compiler_cxx = PCXX, linker_exe = PLD, compiler_so = PCC_SHARED, linker_so = PLD_SHARED, ) compiler.shared_lib_extension = so_ext # if sys.platform == 'darwin': for attr in ('preprocessor', 'compiler', 'compiler_cxx', 'compiler_so', 'linker_so', 'linker_exe'): compiler_cmd = getattr(compiler, attr, []) while '-mno-fused-madd' in compiler_cmd: compiler_cmd.remove('-mno-fused-madd')
def set_executable(self, key, value): if isinstance(value, str): setattr(self, key, split_quoted(value)) else: setattr(self, key, value)
def finalize_options(self): if self.args: self.args = split_quoted(self.args) else: self.args = []
else: # Find out the rest the hard way OPENSSL_DIR = scan_argv("--openssl-dir=", "") if OPENSSL_DIR != "": include_dirs.append(os.path.join(OPENSSL_DIR, "include")) CURL_CONFIG = "curl-config" CURL_CONFIG = scan_argv("--curl-config=", CURL_CONFIG) d = os.popen("'%s' --version" % CURL_CONFIG).read() if d: d = str.strip(d) if not d: raise Exception( "`%s' not found -- please install the libcurl development files" % CURL_CONFIG) print("Using %s (%s)" % (CURL_CONFIG, d)) for e in split_quoted(os.popen("'%s' --cflags" % CURL_CONFIG).read()): if e[:2] == "-I": # do not add /usr/include if not re.search(r"^\/+usr\/+include\/*$", e[2:]): include_dirs.append(e[2:]) else: extra_compile_args.append(e) # Run curl-config --libs and --static-libs. Some platforms may not # support one or the other of these curl-config options, so gracefully # tolerate failure of either, but not both. optbuf = "" for option in ["--libs", "--static-libs"]: p = subprocess.Popen("'%s' %s" % (CURL_CONFIG, option), shell=True, stdout=subprocess.PIPE)
def load(self, filename="mpi.cfg", section='mpi'): if isinstance(filename, str): filenames = filename.split(os.path.pathsep) else: filenames = list(filename) if isinstance(section, str): sections = section.split(',') else: sections = list(section) # try: parser = ConfigParser(dict_type=OrderedDict) except TypeError: parser = ConfigParser() try: read_ok = parser.read(filenames) except ConfigParserError: self.log.error( "error: parsing configuration file/s '%s'", os.path.pathsep.join(filenames)) return None for section in sections: if parser.has_section(section): break section = None if not section: self.log.error( "error: section/s '%s' not found in file/s '%s'", ','.join(sections), os.path.pathsep.join(filenames)) return None parser_items = list(parser.items(section, vars=None)) # compiler_info = type(self.compiler_info)() for option, value in parser_items: if option in self.compiler_info: compiler_info[option] = value # pathsep = os.path.pathsep expanduser = os.path.expanduser expandvars = os.path.expandvars library_info = type(self.library_info)() for k, v in parser_items: if k in ('define_macros', 'undef_macros', ): macros = [e.strip() for e in v.split(',')] if k == 'define_macros': for i, m in enumerate(macros): try: # -DFOO=bar idx = m.index('=') macro = (m[:idx], m[idx+1:] or None) except ValueError: # -DFOO macro = (m, None) macros[i] = macro library_info[k] = macros elif k in ('include_dirs', 'library_dirs', 'runtime_dirs', 'runtime_library_dirs', ): if k == 'runtime_dirs': k = 'runtime_library_dirs' pathlist = [p.strip() for p in v.split(pathsep)] library_info[k] = [expanduser(expandvars(p)) for p in pathlist if p] elif k == 'libraries': library_info[k] = [e.strip() for e in split_quoted(v)] elif k in ('extra_compile_args', 'extra_link_args', ): library_info[k] = split_quoted(v) elif k == 'extra_objects': library_info[k] = [expanduser(expandvars(e)) for e in split_quoted(v)] elif hasattr(self, k): library_info[k] = v.strip() else: pass # self.section = section self.filename = read_ok self.compiler_info.update(compiler_info) self.library_info.update(library_info) return compiler_info, library_info, section, read_ok
"`%s' not found -- please install the libcurl development files or specify --curl-config=/path/to/curl-config" % CURL_CONFIG ) if stderr: msg += ":\n" + stderr.decode() raise ConfigurationError(msg) libcurl_version = stdout.decode().strip() print("Using %s (%s)" % (CURL_CONFIG, libcurl_version)) p = subprocess.Popen((CURL_CONFIG, "--cflags"), stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() if p.wait() != 0: msg = "Problem running `%s' --cflags" % CURL_CONFIG if stderr: msg += ":\n" + stderr.decode() raise ConfigurationError(msg) for arg in split_quoted(stdout.decode()): if arg[:2] == "-I": # do not add /usr/include if not re.search(r"^\/+usr\/+include\/*$", arg[2:]): include_dirs.append(arg[2:]) else: extra_compile_args.append(arg) # Obtain linker flags/libraries to link against. # In theory, all we should need is `curl-config --libs`. # Apparently on some platforms --libs fails and --static-libs works, # so try that. # If --libs succeeds do not try --static libs; see # https://github.com/pycurl/pycurl/issues/52 for more details. # If neither --libs nor --static-libs work, fail. optbuf = ""
def load(self, filename="mpi.cfg", section='mpi'): if isinstance(filename, str): filenames = filename.split(os.path.pathsep) else: filenames = list(filename) if isinstance(section, str): sections = section.split(',') else: sections = list(section) # try: parser = ConfigParser(dict_type=OrderedDict) except TypeError: parser = ConfigParser() try: read_ok = parser.read(filenames) except ConfigParserError: self.log.error("error: parsing configuration file/s '%s'", os.path.pathsep.join(filenames)) return None for section in sections: if parser.has_section(section): break section = None if not section: self.log.error("error: section/s '%s' not found in file/s '%s'", ','.join(sections), os.path.pathsep.join(filenames)) return None parser_items = list(parser.items(section, vars=None)) # compiler_info = type(self.compiler_info)() for option, value in parser_items: if option in self.compiler_info: compiler_info[option] = value # pathsep = os.path.pathsep expanduser = os.path.expanduser expandvars = os.path.expandvars library_info = type(self.library_info)() for k, v in parser_items: if k in ( 'define_macros', 'undef_macros', ): macros = [e.strip() for e in v.split(',')] if k == 'define_macros': for i, m in enumerate(macros): try: # -DFOO=bar idx = m.index('=') macro = (m[:idx], m[idx + 1:] or None) except ValueError: # -DFOO macro = (m, None) macros[i] = macro library_info[k] = macros elif k in ( 'include_dirs', 'library_dirs', 'runtime_dirs', 'runtime_library_dirs', ): if k == 'runtime_dirs': k = 'runtime_library_dirs' pathlist = [p.strip() for p in v.split(pathsep)] library_info[k] = [ expanduser(expandvars(p)) for p in pathlist if p ] elif k == 'libraries': library_info[k] = [e.strip() for e in split_quoted(v)] elif k in ( 'extra_compile_args', 'extra_link_args', ): library_info[k] = split_quoted(v) elif k == 'extra_objects': library_info[k] = [ expanduser(expandvars(e)) for e in split_quoted(v) ] elif hasattr(self, k): library_info[k] = v.strip() else: pass # self.section = section self.filename = read_ok self.compiler_info.update(compiler_info) self.library_info.update(library_info) return compiler_info, library_info, section, read_ok