def get_include_dirs(): """Get includes to pass to the compiler.""" include_dirs = [] include_dirs.extend(pkgconfig.parse("eigen3")["include_dirs"]) include_dirs.extend(pkgconfig.parse("hdf5")["include_dirs"]) include_dirs.append(get_pybind_include()) include_dirs.append(get_pybind_include(user=True)) return include_dirs
def _find_hdf5_compiler_settings(self, olds, mpi): """Returns (include_dirs, lib_dirs, define_macros)""" # Specified lib/include dirs explicitly if self.hdf5_includedir or self.hdf5_libdir: inc_dirs = [self.hdf5_includedir] if self.hdf5_includedir else [] lib_dirs = [self.hdf5_libdir] if self.hdf5_libdir else [] return (inc_dirs, lib_dirs, []) # Specified a prefix dir (e.g. '/usr/local') if self.hdf5: inc_dirs = [op.join(self.hdf5, 'include')] lib_dirs = [op.join(self.hdf5, 'lib')] if sys.platform.startswith('win'): lib_dirs.append(op.join(self.hdf5, 'bin')) return (inc_dirs, lib_dirs, []) # Specified a name to be looked up in pkgconfig if self.hdf5_pkgconfig_name: import pkgconfig if not pkgconfig.exists(self.hdf5_pkgconfig_name): raise ValueError( f"No pkgconfig information for {self.hdf5_pkgconfig_name}" ) pc = pkgconfig.parse(self.hdf5_pkgconfig_name) return (pc['include_dirs'], pc['library_dirs'], pc['define_macros']) # Re-use previously specified settings if olds.get('hdf5_includedirs') and olds.get('hdf5_libdirs'): return ( olds['hdf5_includedirs'], olds['hdf5_libdirs'], olds.get('hdf5_define_macros', []), ) # Fallback: query pkgconfig for default hdf5 names import pkgconfig pc_name = 'hdf5-openmpi' if mpi else 'hdf5' pc = {} try: if pkgconfig.exists(pc_name): pc = pkgconfig.parse(pc_name) except EnvironmentError: if os.name != 'nt': print( "Building h5py requires pkg-config unless the HDF5 path " "is explicitly specified", file=sys.stderr ) raise return ( pc.get('include_dirs', []), pc.get('library_dirs', []), pc.get('define_macros', []), )
def test_parse(): config = pkgconfig.parse("fake-gtk+-3.0 fake-python") assert ('GSEAL_ENABLE', None) in config['define_macros'] assert '/usr/include/gtk-3.0' in config['include_dirs'] assert '/usr/lib_gtk_foo' in config['library_dirs'] assert '/usr/lib_python_foo' in config['library_dirs'] assert 'gtk-3' in config['libraries'] assert '/usr/include/python2.7' in config['include_dirs'] with pytest.raises(pkgconfig.PackageNotFoundError): pkgconfig.parse('doesnotexist')
def make_config(): from pkgconfig import parse # Process the `pkg-config` utility and discover include and library # directories. config = defaultdict(set) for lib in ['zlib', 'libtiff-4', 'freetype2']: for key, value in parse(lib).items(): config[key].update(value) # Add libjpeg (no .pc file). config['libraries'].add('jpeg') # List-ify config for setuptools. for key in config: config[key] = list(config[key]) # Add hummus. config['include_dirs'].insert(0, 'lib/hummus/PDFWriter') config['include_dirs'].insert(0, 'lib/python') # Add local library. config['include_dirs'].insert(0, 'src') # Return built config. return config
def make_extension(name, cython=True): from pkgconfig import parse # Declare the crypto implementation. XMLSEC_CRYPTO = 'openssl' # Process the `pkg-config` utility and discover include and library # directories. config = {} for lib in ['libxml-2.0', 'xmlsec1-%s' % XMLSEC_CRYPTO]: config.update(parse(lib)) config['extra_compile_args'] = ['-DXMLSEC_CRYPTO_OPENSSL=1'] # List-ify config for setuptools. for key in config: config[key] = list(config[key]) if 'include_dirs' not in config: config['include_dirs'] = [] # Add the source directories for inclusion. config['include_dirs'].insert(0, 'src') # Resolve extension location from name. location = path.join('src', *name.split('.')) location += '.pyx' if cython else '.c' # Create and return the extension. return Extension(name, [location], **config)
def make_extension(name, cython=True): from pkgconfig import parse # Declare the crypto implementation. xmlsec_crypto = 'openssl' # Process the `pkg-config` utility and discover include and library # directories. config = {} for lib in ['libxml-2.0', 'xmlsec1-%s' % xmlsec_crypto]: config.update(parse(lib)) config['extra_compile_args'] = ['-DXMLSEC_CRYPTO_OPENSSL=1', '-DXMLSEC_NO_CRYPTO_DYNAMIC_LOADING=1'] # List-ify config for setuptools. for key in config: config[key] = list(config[key]) if 'include_dirs' not in config: config['include_dirs'] = [] # Add the source directories for inclusion. import lxml config['include_dirs'].insert(0, path.dirname(lxml.__file__)) config['include_dirs'].insert(0, path.join(path.dirname(lxml.__file__), 'includes')) config['include_dirs'].insert(0, 'src') # Resolve extension location from name. location = path.join('src', *name.split('.')) location += '.pyx' if cython else '.c' # Create and return the extension. return Extension(name, [location], **config)
def get_blas_config() -> PackageInfo: """ Find CBLAS-compatible BLAS :return: blas related package information """ blaspkgcfg = { 'include_dirs': [], 'library_dirs': [], 'libraries': [], 'define_macros': [], 'extra_compile_args': [], 'extra_link_args': [] } # Check environment variables if 'BLAS_CFLAGS' in os.environ: blaspkgcfg['extra_compile_args'].extend( shlex.split(os.environ['BLAS_CFLAGS'])) if 'BLAS_LIBS' in os.environ: blaspkgcfg['extra_link_args'].extend( shlex.split(os.environ['BLAS_LIBS'])) if 'BLAS_CFLAGS' in os.environ or 'BLAS_LIBS' in os.environ: # If options have been provided by the user, we don't try to detect # anything by ourselves return blaspkgcfg # Try environment modules # MKL if 'MKLROOT' in os.environ: if 'MKL_INC' in os.environ: blaspkgcfg['extra_compile_args'].extend( shlex.split(os.environ['MKL_INC'])) if 'MKL_LIB' in os.environ: blaspkgcfg['extra_link_args'].extend( shlex.split(os.environ['MKL_LIB'])) blaspkgcfg['define_macros'].append(('AMICI_BLAS_MKL', None), ) return blaspkgcfg # Try pkgconfig if pkgconfig: for blas_name in ['cblas', 'openblas']: if pkgconfig.exists(blas_name): blaspkgcfg = pkgconfig.parse(blas_name) blaspkgcfg['extra_compile_args'] = [ pkgconfig.cflags(blas_name) ] blaspkgcfg['extra_link_args'] = [pkgconfig.libs(blas_name)] return blaspkgcfg # If none of the previous worked, fall back to libcblas in default paths blaspkgcfg['libraries'] = ['cblas'] return blaspkgcfg
def autodetect_version(hdf5_dir=None): """ Detect the current version of HDF5, and return X.Y.Z version string. Intended for Unix-ish platforms (Linux, OS X, BSD). Does not support Windows. Raises an exception if anything goes wrong. hdf5_dir: optional HDF5 install directory to look in (containing "lib") """ import os import sys import os.path as op import re import ctypes from ctypes import byref import pkgconfig if sys.platform.startswith('darwin'): regexp = re.compile(r'^libhdf5.dylib') else: regexp = re.compile(r'^libhdf5.so') libdirs = ['/usr/local/lib', '/opt/local/lib'] try: if pkgconfig.exists("hdf5"): libdirs.extend(pkgconfig.parse("hdf5")['library_dirs']) except EnvironmentError: pass if hdf5_dir is not None: libdirs.insert(0, op.join(hdf5_dir, 'lib')) path = None for d in libdirs: try: candidates = [x for x in os.listdir(d) if regexp.match(x)] except Exception: continue # Skip invalid entries if len(candidates) != 0: candidates.sort( key=lambda x: len(x)) # Prefer libfoo.so to libfoo.so.X.Y.Z path = op.abspath(op.join(d, candidates[0])) break if path is None: path = "libhdf5.so" lib = ctypes.cdll.LoadLibrary(path) major = ctypes.c_uint() minor = ctypes.c_uint() release = ctypes.c_uint() lib.H5get_libversion(byref(major), byref(minor), byref(release)) return "{0}.{1}.{2}".format(int(major.value), int(minor.value), int(release.value))
def test_parse_static(): config = pkgconfig.parse("fake-python", static=True) assert '/usr/lib_python_foo' in config['library_dirs'] assert '/usr/include/python2.7' in config['include_dirs'] assert 'python2.7' in config['libraries'] assert 'pthread' in config['libraries'] assert 'dl' in config['libraries'] assert 'util' in config['libraries']
def getHdf5Config(): """Find HDF5 include dir and libs Arguments: Returns: Raises: """ if pkgconfig: h5pkgcfg = pkgconfig.parse('hdf5') # NOTE: Cannot use pkgconfig.exists('hdf5f'), since this is true # althoughno libraries or include dirs are available h5pkgcfg['found'] = 'include_dirs' in h5pkgcfg \ and h5pkgcfg['include_dirs'] if h5pkgcfg['found']: return h5pkgcfg h5pkgcfg = { 'include_dirs': [], 'library_dirs': [], 'libraries': [], 'define_macros': [] } # try for hdf5 in standard locations hdf5_include_dir_hints = [ '/usr/include/hdf5/serial', '/usr/local/include', '/usr/include', # travis ubuntu xenial '/usr/local/Cellar/hdf5/1.10.2_1/include' # travis macOS ] hdf5_library_dir_hints = [ '/usr/lib/x86_64-linux-gnu/', # travis ubuntu xenial '/usr/lib/x86_64-linux-gnu/hdf5/serial', '/usr/local/lib', '/usr/local/Cellar/hdf5/1.10.2_1/lib' # travis macOS ] for hdf5_include_dir_hint in hdf5_include_dir_hints: hdf5_include_dir_found = os.path.isfile( os.path.join(hdf5_include_dir_hint, 'hdf5.h')) if hdf5_include_dir_found: print('hdf5.h found in %s' % hdf5_include_dir_hint) h5pkgcfg['include_dirs'] = [hdf5_include_dir_hint] break for hdf5_library_dir_hint in hdf5_library_dir_hints: hdf5_library_dir_found = os.path.isfile( os.path.join(hdf5_library_dir_hint, 'libhdf5.a')) if hdf5_library_dir_found: print('libhdf5.a found in %s' % hdf5_library_dir_hint) h5pkgcfg['library_dirs'] = [hdf5_library_dir_hint] break h5pkgcfg['found'] = hdf5_include_dir_found and hdf5_library_dir_found return h5pkgcfg
def find_pybind11(hint=None): r''' Try to find the pybind11 library. If successful the include directory is returned. ''' # search with "get_include" # ------------------------- if hint is None: import pybind11 incl = pybind11.get_include(False) if len(incl) > 0: return incl incl = pybind11.get_include(True) if len(incl) > 0: return incl # search with pkgconfig # --------------------- if hint is None: import pkgconfig if pkgconfig.exists('pybind11'): return pkgconfig.parse('pybind11')['include_dirs'][0] # manual search # ------------- search_dirs = [] if hint is None else hint search_dirs += [ "/usr/local/include", "/usr/local/homebrew/include", "/opt/local/var/macports/software", "/opt/local/include", "/usr/include", "/usr/include/local", "/usr/include", ] for d in search_dirs: path = os.path.join(d, "pybind11", "xtensor_config.hpp") if os.path.exists(path): src = open(path, "r").read() v1 = re.findall("#define PYBIND11_VERSION_MAJOR (.+)", src) v2 = re.findall("#define PYBIND11_VERSION_MINOR (.+)", src) v3 = re.findall("#define PYBIND11_VERSION_PATCH (.+)", src) if not len(v1) or not len(v2) or not len(v3): continue v = "{0}.{1}.{2}".format(v1[0], v2[0], v3[0]) print("Found pybind11 version {0} in: {1}".format(v, d)) return d return None
def cython_aliases(): """ Return the aliases for compiling Cython code. These aliases are macros which can occur in ``# distutils`` headers. EXAMPLES:: sage: from sage.env import cython_aliases sage: cython_aliases() {...} sage: sorted(cython_aliases().keys()) ['ARB_LIBRARY', 'FFLASFFPACK_CFLAGS', 'FFLASFFPACK_INCDIR', 'FFLASFFPACK_LIBDIR', 'FFLASFFPACK_LIBRARIES', 'GIVARO_CFLAGS', 'GIVARO_INCDIR', 'GIVARO_LIBDIR', 'GIVARO_LIBRARIES', 'GSL_CFLAGS', 'GSL_INCDIR', 'GSL_LIBDIR', 'GSL_LIBRARIES', 'LINBOX_CFLAGS', 'LINBOX_INCDIR', 'LINBOX_LIBDIR', 'LINBOX_LIBRARIES', 'SINGULAR_CFLAGS', 'SINGULAR_INCDIR', 'SINGULAR_LIBDIR', 'SINGULAR_LIBRARIES'] """ import pkgconfig aliases = {} for lib in ['fflas-ffpack', 'givaro', 'gsl', 'linbox', 'Singular']: var = lib.upper().replace("-", "") + "_" aliases[var + "CFLAGS"] = pkgconfig.cflags(lib).split() pc = pkgconfig.parse(lib) # INCDIR should be redundant because the -I options are also # passed in CFLAGS aliases[var + "INCDIR"] = pc['include_dirs'] aliases[var + "LIBDIR"] = pc['library_dirs'] aliases[var + "LIBRARIES"] = pc['libraries'] # LinBox needs special care because it actually requires C++11 with # GNU extensions: -std=c++11 does not work, you need -std=gnu++11 # (this is true at least with GCC 7.2.0). # # Further, note that LinBox does not add any C++11 flag in its .pc # file (possibly because of confusion between CFLAGS and CXXFLAGS?). # This is not a problem in practice since LinBox depends on # fflas-ffpack and fflas-ffpack does add such a C++11 flag. aliases["LINBOX_CFLAGS"].append("-std=gnu++11") aliases["ARB_LIBRARY"] = os.environ.get('SAGE_ARB_LIBRARY', 'arb') return aliases
def test_parse(): config = pkgconfig.parse("fake-gtk+-3.0 fake-python") nt.assert_true(('GSEAL_ENABLE', '') in config['define_macros']) nt.assert_true('/usr/include/gtk-3.0' in config['include_dirs']) nt.assert_true('/usr/lib64' in config['library_dirs'] or not config['library_dirs']) nt.assert_true('gtk-3' in config['libraries']) nt.assert_true('/usr/include/python2.7' in config['include_dirs'])
def autodetect_version(hdf5_dir=None): """ Detect the current version of HDF5, and return X.Y.Z version string. Intended for Unix-ish platforms (Linux, OS X, BSD). Does not support Windows. Raises an exception if anything goes wrong. hdf5_dir: optional HDF5 install directory to look in (containing "lib") """ import os import sys import os.path as op import re import ctypes from ctypes import byref import pkgconfig if sys.platform.startswith('darwin'): regexp = re.compile(r'^libhdf5.dylib') else: regexp = re.compile(r'^libhdf5.so') libdirs = ['/usr/local/lib', '/opt/local/lib'] try: if pkgconfig.exists("hdf5"): libdirs.extend(pkgconfig.parse("hdf5")['library_dirs']) except EnvironmentError: pass if hdf5_dir is not None: libdirs.insert(0, op.join(hdf5_dir, 'lib')) path = None for d in libdirs: try: candidates = [x for x in os.listdir(d) if regexp.match(x)] except Exception: continue # Skip invalid entries if len(candidates) != 0: candidates.sort(key=lambda x: len(x)) # Prefer libfoo.so to libfoo.so.X.Y.Z path = op.abspath(op.join(d, candidates[0])) break if path is None: path = "libhdf5.so" lib = ctypes.cdll.LoadLibrary(path) major = ctypes.c_uint() minor = ctypes.c_uint() release = ctypes.c_uint() lib.H5get_libversion(byref(major), byref(minor), byref(release)) return "{0}.{1}.{2}".format(int(major.value), int(minor.value), int(release.value))
def check_lib(name, version): lib_installed = pkgconfig.exists(name) if not lib_installed: raise RuntimeError("lib{0} not installed".format(name)) lib_min = pkgconfig.installed(name, version) if not lib_min: raise RuntimeError("requires lib{0} {1} ".format(name, version)) return pkgconfig.parse(name)
def cython_aliases(): """ Return the aliases for compiling Cython code. These aliases are macros which can occur in ``# distutils`` headers. EXAMPLES:: sage: from sage.env import cython_aliases sage: cython_aliases() {...} sage: sorted(cython_aliases().keys()) ['FFLASFFPACK_CFLAGS', 'FFLASFFPACK_INCDIR', 'FFLASFFPACK_LIBDIR', 'FFLASFFPACK_LIBRARIES', 'GIVARO_CFLAGS', 'GIVARO_INCDIR', 'GIVARO_LIBDIR', 'GIVARO_LIBRARIES', 'GSL_CFLAGS', 'GSL_INCDIR', 'GSL_LIBDIR', 'GSL_LIBRARIES', 'LINBOX_CFLAGS', 'LINBOX_INCDIR', 'LINBOX_LIBDIR', 'LINBOX_LIBRARIES', 'SINGULAR_CFLAGS', 'SINGULAR_INCDIR', 'SINGULAR_LIBDIR', 'SINGULAR_LIBRARIES'] """ import pkgconfig aliases = {} for lib in ['fflas-ffpack', 'givaro', 'gsl', 'linbox', 'Singular']: var = lib.upper().replace("-", "") + "_" aliases[var + "CFLAGS"] = pkgconfig.cflags(lib).split() pc = pkgconfig.parse(lib) # INCDIR should be redundant because the -I options are also # passed in CFLAGS aliases[var + "INCDIR"] = pc['include_dirs'] aliases[var + "LIBDIR"] = pc['library_dirs'] aliases[var + "LIBRARIES"] = pc['libraries'] # LinBox needs special care because it actually requires C++11 with # GNU extensions: -std=c++11 does not work, you need -std=gnu++11 # (this is true at least with GCC 7.2.0). # # Further, note that LinBox does not add any C++11 flag in its .pc # file (possibly because of confusion between CFLAGS and CXXFLAGS?). # This is not a problem in practice since LinBox depends on # fflas-ffpack and fflas-ffpack does add such a C++11 flag. aliases["LINBOX_CFLAGS"].append("-std=gnu++11") return aliases
def compile_cpp_code(cpp_code): """Compile a user C(++) string to a Python object with pybind11. Note this is still experimental. """ if not pkgconfig.exists('dolfin'): raise RuntimeError( "Could not find DOLFIN pkg-config file. Please make sure appropriate paths are set." ) # Get pkg-config data for DOLFIN d = pkgconfig.parse('dolfin') # Set compiler/build options # FIXME: need to locate Python libs and pybind11 from distutils import sysconfig params = dijitso.params.default_params() pyversion = "python" + sysconfig.get_config_var("LDVERSION") params['cache']['lib_prefix'] = "" params['cache']['lib_basename'] = "" params['cache']['lib_loader'] = "import" params['build']['include_dirs'] = d["include_dirs"] + get_pybind_include( ) + [sysconfig.get_config_var("INCLUDEDIR") + "/" + pyversion] params['build']['libs'] = d["libraries"] + [pyversion] params['build']['lib_dirs'] = d["library_dirs"] + [ sysconfig.get_config_var("LIBDIR") ] params['build']['cxxflags'] += ('-fno-lto', ) # enable all define macros from DOLFIN dmacros = () for dm in d['define_macros']: if len(dm[1]) == 0: dmacros += ('-D' + dm[0], ) else: dmacros += ('-D' + dm[0] + '=' + dm[1], ) params['build']['cxxflags'] += dmacros # This seems to be needed by OSX but not in Linux # FIXME: probably needed for other libraries too if cpp.common.has_petsc(): import os params['build']['libs'] += ['petsc'] params['build']['lib_dirs'] += [os.environ["PETSC_DIR"] + "/lib"] module_hash = hashlib.md5(cpp_code.encode('utf-8')).hexdigest() module_name = "dolfin_cpp_module_" + module_hash module, signature = dijitso.jit(cpp_code, module_name, params, generate=jit_generate) return module
def _make_extensions(config): """ Produce a list of Extension instances which can be passed to cythonize(). This is the point at which custom directories, MPI options, etc. enter the build process. """ import numpy import pkgconfig settings = COMPILER_SETTINGS.copy() # Ensure that if a custom HDF5 location is specified, prevent # pkg-config and fallback locations from appearing in the settings if config.hdf5 is not None: settings['include_dirs'].insert(0, op.join(config.hdf5, 'include')) settings['library_dirs'].insert(0, op.join(config.hdf5, 'lib')) else: try: if pkgconfig.exists('hdf5'): pkgcfg = pkgconfig.parse("hdf5") settings['include_dirs'].extend(pkgcfg['include_dirs']) settings['library_dirs'].extend(pkgcfg['library_dirs']) settings['define_macros'].extend(pkgcfg['define_macros']) except EnvironmentError: if os.name != 'nt': print( "h5py requires pkg-config unless the HDF5 path is explicitly specified", file=sys.stderr) raise settings['include_dirs'].extend(FALLBACK_PATHS['include_dirs']) settings['library_dirs'].extend(FALLBACK_PATHS['library_dirs']) try: numpy_includes = numpy.get_include() except AttributeError: # if numpy is not installed get the headers from the .egg directory import numpy.core numpy_includes = os.path.join(os.path.dirname(numpy.core.__file__), 'include') settings['include_dirs'] += [numpy_includes] if config.mpi: import mpi4py settings['include_dirs'] += [mpi4py.get_include()] # TODO: should this only be done on UNIX? if os.name != 'nt': settings['runtime_library_dirs'] = settings['library_dirs'] def make_extension(module): sources = [localpath('h5py', module + '.pyx')] + EXTRA_SRC.get( module, []) return Extension('h5py.' + module, sources, **settings) return [make_extension(m) for m in MODULES]
def test_parse(): config = pkgconfig.parse("fake-gtk+-3.0 fake-python") nt.assert_true(('GSEAL_ENABLE', '') in config['define_macros']) nt.assert_true('/usr/include/gtk-3.0' in config['include_dirs']) nt.assert_true('/usr/lib_gtk_foo' in config['library_dirs']) nt.assert_true('/usr/lib_python_foo' in config['library_dirs']) nt.assert_true('gtk-3' in config['libraries']) nt.assert_true('/usr/include/python2.7' in config['include_dirs'])
def test_parse(): config = pkgconfig.parse("fake-gtk+-3.0 fake-python") assert ('GSEAL_ENABLE', None) in config['define_macros'] assert '/usr/include/gtk-3.0' in config['include_dirs'] assert '/usr/lib_gtk_foo' in config['library_dirs'] assert '/usr/lib_python_foo' in config['library_dirs'] assert 'gtk-3' in config['libraries'] assert '/usr/include/python2.7' in config['include_dirs']
def make_static_extension(name, **kwargs): libraries = kwargs.pop('libraries', []) pkg_config = pkgconfig.parse(' '.join(libraries), static=True) libraries = pkg_config['libraries'] library_dirs = pkg_config['library_dirs'] include_dirs = kwargs.pop("include_dirs", []) + pkg_config['include_dirs'] return Extension(name, libraries=libraries, library_dirs=library_dirs, include_dirs=include_dirs, **kwargs)
def get_systemd_lib(key): try: return pkgconfig.parse("libsystemd")[key] except KeyError: return None except Exception: # Package config is not installed or system pkg-config # Default to systemd if key == "libraries": return ["systemd"] else: return None
def _make_extensions(config): """ Produce a list of Extension instances which can be passed to cythonize(). This is the point at which custom directories, MPI options, etc. enter the build process. """ import numpy import pkgconfig settings = COMPILER_SETTINGS.copy() try: if pkgconfig.exists('hdf5'): pkgcfg = pkgconfig.parse("hdf5") settings['include_dirs'].extend(pkgcfg['include_dirs']) settings['library_dirs'].extend(pkgcfg['library_dirs']) settings['define_macros'].extend(pkgcfg['define_macros']) except EnvironmentError: pass try: numpy_includes = numpy.get_include() except AttributeError: # if numpy is not installed get the headers from the .egg directory import numpy.core numpy_includes = os.path.join(os.path.dirname(numpy.core.__file__), 'include') settings['include_dirs'] += [numpy_includes] if config.mpi: import mpi4py settings['include_dirs'] += [mpi4py.get_include()] # Ensure a custom location appears first, so we don't get a copy of # HDF5 from some default location in COMPILER_SETTINGS if config.hdf5 is not None: settings['include_dirs'].insert(0, op.join(config.hdf5, 'include')) settings['library_dirs'].insert(0, op.join(config.hdf5, 'lib')) # TODO: should this only be done on UNIX? if os.name != 'nt': settings['runtime_library_dirs'] = settings['library_dirs'] def make_extension(module): sources = [localpath('h5py', module + '.pyx')] + EXTRA_SRC.get( module, []) return Extension('h5py.' + module, sources, **settings) return [make_extension(m) for m in MODULES]
def libs_target(self, pkg, target): if target.built: return target.built = True for dn, to in target.link.items(): self.libs_target(to.pm, to) self.log.info('PMContext.libs_target()', pkg=pkg.name, target=target.name) libs = pkgconfig.parse(' '.join(target.pkg_config))['libraries'] + target.libs for lib in libs: lp = find_lib('lib' + lib + '.so', libpaths + self.library_dirs) if os.path.isfile('./dumbcpm-build/lib' + lib + '.so') and (os.path.getmtime('./dumbcpm-build/lib' + lib + '.so') > os.path.getmtime(lp)): continue system('cp ' + lp + ' ./dumbcpm-build/lib' + lib + '.so') system('patchelf --set-rpath \'$ORIGIN\' ./dumbcpm-build/lib' + lib + '.so')
def _make_extensions(config): """ Produce a list of Extension instances which can be passed to cythonize(). This is the point at which custom directories, MPI options, etc. enter the build process. """ import numpy import pkgconfig settings = COMPILER_SETTINGS.copy() # Ensure that if a custom HDF5 location is specified, prevent # pkg-config and fallback locations from appearing in the settings if config.hdf5 is not None: settings['include_dirs'].insert(0, op.join(config.hdf5, 'include')) settings['library_dirs'].insert(0, op.join(config.hdf5, 'lib')) else: try: if pkgconfig.exists('hdf5'): pkgcfg = pkgconfig.parse("hdf5") settings['include_dirs'].extend(pkgcfg['include_dirs']) settings['library_dirs'].extend(pkgcfg['library_dirs']) settings['define_macros'].extend(pkgcfg['define_macros']) except EnvironmentError: pass settings['include_dirs'].extend(FALLBACK_PATHS['include_dirs']) settings['library_dirs'].extend(FALLBACK_PATHS['library_dirs']) try: numpy_includes = numpy.get_include() except AttributeError: # if numpy is not installed get the headers from the .egg directory import numpy.core numpy_includes = os.path.join(os.path.dirname(numpy.core.__file__), 'include') settings['include_dirs'] += [numpy_includes] if config.mpi: import mpi4py settings['include_dirs'] += [mpi4py.get_include()] # TODO: should this only be done on UNIX? if os.name != 'nt': settings['runtime_library_dirs'] = settings['library_dirs'] def make_extension(module): sources = [localpath('h5py', module+'.pyx')] + EXTRA_SRC.get(module, []) return Extension('h5py.'+module, sources, **settings) return [make_extension(m) for m in MODULES]
def _make_extensions(config): """ Produce a list of Extension instances which can be passed to cythonize(). This is the point at which custom directories, MPI options, etc. enter the build process. """ import numpy import pkgconfig settings = COMPILER_SETTINGS.copy() try: if pkgconfig.exists("hdf5"): pkgcfg = pkgconfig.parse("hdf5") settings["include_dirs"].extend(pkgcfg["include_dirs"]) settings["library_dirs"].extend(pkgcfg["library_dirs"]) settings["define_macros"].extend(pkgcfg["define_macros"]) except EnvironmentError: pass try: numpy_includes = numpy.get_include() except AttributeError: # if numpy is not installed get the headers from the .egg directory import numpy.core numpy_includes = os.path.join(os.path.dirname(numpy.core.__file__), "include") settings["include_dirs"] += [numpy_includes] if config.mpi: import mpi4py settings["include_dirs"] += [mpi4py.get_include()] # Ensure a custom location appears first, so we don't get a copy of # HDF5 from some default location in COMPILER_SETTINGS if config.hdf5 is not None: settings["include_dirs"].insert(0, op.join(config.hdf5, "include")) settings["library_dirs"].insert(0, op.join(config.hdf5, "lib")) # TODO: should this only be done on UNIX? if os.name != "nt": settings["runtime_library_dirs"] = settings["library_dirs"] def make_extension(module): sources = [localpath("h5py", module + ".pyx")] + EXTRA_SRC.get(module, []) return Extension("h5py." + module, sources, **settings) return [make_extension(m) for m in MODULES]
def find_eigen(hint=None): r''' Try to find the Eigen library. If successful the include directory is returned. ''' # search with pkgconfig # --------------------- try: import pkgconfig if pkgconfig.installed('eigen3', '>3.0.0'): return pkgconfig.parse('eigen3')['include_dirs'][0] except: pass # manual search # ------------- search_dirs = [] if hint is None else hint search_dirs += [ "/usr/local/include/eigen3", "/usr/local/homebrew/include/eigen3", "/opt/local/var/macports/software/eigen3", "/opt/local/include/eigen3", "/usr/include/eigen3", "/usr/include/local", "/usr/include", ] for d in search_dirs: path = os.path.join(d, "Eigen", "Dense") if os.path.exists(path): vf = os.path.join(d, "Eigen", "src", "Core", "util", "Macros.h") if not os.path.exists(vf): continue src = open(vf, "r").read() v1 = re.findall("#define EIGEN_WORLD_VERSION (.+)", src) v2 = re.findall("#define EIGEN_MAJOR_VERSION (.+)", src) v3 = re.findall("#define EIGEN_MINOR_VERSION (.+)", src) if not len(v1) or not len(v2) or not len(v3): continue v = "{0}.{1}.{2}".format(v1[0], v2[0], v3[0]) print("Found Eigen version {0} in: {1}".format(v, d)) return d return None
def get_libraries(): """Get libraries for building EM2. This is mostly just finding hdf5. Boost doesn't seem to work with pkg-config. """ all_libraries = list(BOOST_LIBRARIES) if pkgconfig.exists("hdf5"): all_libraries.extend(pkgconfig.parse("hdf5")['libraries']) else: all_libraries.append("hdf5") all_libraries.append("hdf5_cpp") return all_libraries
def find_xsimd(hint=None): r''' Try to find the xsimd library. If successful the include directory is returned. ''' # search with pkgconfig # --------------------- if hint is None: import pkgconfig if pkgconfig.exists('xsimd'): return pkgconfig.parse('xsimd')['include_dirs'][0] # manual search # ------------- search_dirs = [] if hint is None else hint search_dirs += [ "/usr/local/include", "/usr/local/homebrew/include", "/opt/local/var/macports/software", "/opt/local/include", "/usr/include", "/usr/include/local", "/usr/include", ] for d in search_dirs: path = os.path.join(d, "xsimd", "config", "xsimd_config.hpp") print(path) if os.path.exists(path): src = open(path, "r").read() v1 = re.findall("#define XSIMD_VERSION_MAJOR (.+)", src) v2 = re.findall("#define XSIMD_VERSION_MINOR (.+)", src) v3 = re.findall("#define XSIMD_VERSION_PATCH (.+)", src) if not len(v1) or not len(v2) or not len(v3): continue v = "{0}.{1}.{2}".format(v1[0], v2[0], v3[0]) print("Found xsimd version {0} in: {1}".format(v, d)) return d return None
def _fetch_pkgconfig(self, extension): """Convert the pkgconfig keys in the dict to the proper arguments for Extension and then create the actual Extension""" # If no 'pkgconfig' key, add as-is try: libs = extension['pkgconfig'] except KeyError: return Extension(**extension) import pkgconfig # Add pkgconfig info del extension['pkgconfig'] for k, v in pkgconfig.parse(libs).items(): try: extension[k].extend(v) except KeyError: extension[k] = v return Extension(**extension)
def _make_extensions(config): """ Produce a list of Extension instances which can be passed to cythonize(). This is the point at which custom directories, MPI options, etc. enter the build process. """ import numpy import pkgconfig settings = COMPILER_SETTINGS.copy() try: if pkgconfig.exists('hdf5'): pkgcfg = pkgconfig.parse("hdf5") settings['include_dirs'].extend(pkgcfg['include_dirs']) settings['library_dirs'].extend(pkgcfg['library_dirs']) settings['define_macros'].extend(pkgcfg['define_macros']) except EnvironmentError: pass settings['include_dirs'] += [numpy.get_include()] if config.mpi: import mpi4py settings['include_dirs'] += [mpi4py.get_include()] # Ensure a custom location appears first, so we don't get a copy of # HDF5 from some default location in COMPILER_SETTINGS if config.hdf5 is not None: settings['include_dirs'].insert(0, op.join(config.hdf5, 'include')) settings['library_dirs'].insert(0, op.join(config.hdf5, 'lib')) # TODO: should this only be done on UNIX? if os.name != 'nt': settings['runtime_library_dirs'] = settings['library_dirs'] def make_extension(module): sources = [localpath('h5py', module+'.pyx')] + EXTRA_SRC.get(module, []) return Extension('h5py.'+module, sources, **settings) return [make_extension(m) for m in MODULES]
def lib_ext_kwargs(pc, prefix_env_var, lib_name, lib_pkg_name, pc_version, lib_subdir='lib'): system_prefix = os.environ.get(prefix_env_var) if system_prefix: print( f"Detected and preferring {lib_pkg_name} [via {prefix_env_var}]" ) return dict(include_dirs=[os.path.join(system_prefix, 'include')], library_dirs=[os.path.join(system_prefix, lib_subdir)], libraries=[lib_name]) if pc and pc.installed(lib_pkg_name, pc_version): print(f"Detected and preferring {lib_pkg_name} [via pkg-config]") return pc.parse(lib_pkg_name) raise Exception( f"Could not find {lib_name} lib/headers, please set {prefix_env_var} " f"or ensure {lib_pkg_name}.pc is in PKG_CONFIG_PATH.")
def getBlasConfig(): """ Find CBLAS-compatible BLAS Arguments: Returns: Raises: """ blaspkgcfg = {'include_dirs': [], 'library_dirs': [], 'libraries': [], 'define_macros': [], 'extra_compile_args': [], 'extra_link_args': [] } if platform.system() in ['Linux', 'Darwin']: blaspkgcfg['libraries'] = ['cblas'] if pkgconfig: if pkgconfig.exists('cblas'): blaspkgcfg = pkgconfig.parse('cblas') blaspkgcfg['extra_compile_args'] = [pkgconfig.cflags('cblas')] blaspkgcfg['extra_link_args'] = [pkgconfig.libs('cblas')] if 'BLAS_CFLAGS' in os.environ: blaspkgcfg['extra_compile_args'].extend( shlex.split(os.environ['BLAS_CFLAGS']) ) if 'BLAS_LIBS' in os.environ: blaspkgcfg['extra_link_args'].extend( shlex.split(os.environ['BLAS_LIBS']) ) return blaspkgcfg
def build_extensions(self): import numpy import pkgconfig compiler_settings = pkgconfig.parse("fftw3") compiler_settings['include_dirs'].insert(0, "include") compiler_settings['include_dirs'].append(numpy.get_include()) if os.environ.get('STATIC_LAPACK', False): # For the manylinux wheels: we have to build and statically # link to lapack and blas. compiler_settings['extra_link_args'].extend(("/usr/src/lapack/liblapack.a", "/usr/src/lapack/librefblas.a", "-lgfortran")) else: compiler_settings['libraries'].append('lapack') c_opts = [] if has_flag(self.compiler, '-ffast-math'): c_opts.append('-ffast-math') for ext in self.extensions: for k, v in compiler_settings.items(): setattr(ext, k, v) ext.extra_compile_args.extend(c_opts) build_ext.build_extensions(self)
def build_extensions(self): import numpy import pkgconfig compiler_settings = pkgconfig.parse("fftw3") compiler_settings['include_dirs'].insert(0, "include") compiler_settings['include_dirs'].append(numpy.get_include()) if os.environ.get('STATIC_LAPACK', False): # For the manylinux wheels: we have to build and statically # link to lapack and blas. compiler_settings['extra_link_args'].extend( ("/usr/src/lapack/liblapack.a", "/usr/src/lapack/librefblas.a", "-lgfortran")) else: compiler_settings['libraries'].append('lapack') c_opts = [] if has_flag(self.compiler, '-ffast-math'): c_opts.append('-ffast-math') for ext in self.extensions: for k, v in compiler_settings.items(): setattr(ext, k, v) ext.extra_compile_args.extend(c_opts) build_ext.build_extensions(self)
Natural Language :: English """ short_desc = "Calculates multi-taper windowed and time-frequency reassignment spectrograms" long_desc = """ libtfr provides high-performance C and Python libraries for calculating multitaper time-frequency reassignment (TFR) spectrograms as well as conventional STFTs. TFR spectrograms have enhanced signal-to-noise characteristics and can provide very precise spectral estimates under many conditions. The library requires FFTW for the underlying FFT transformations. """ import pkgconfig compiler_settings = pkgconfig.parse("fftw3") compiler_settings['include_dirs'].append(numpy.get_include()) compiler_settings['libraries'].append('lapack') if sys.platform == 'darwin': compiler_settings['include_dirs'].append('/opt/local/include') compiler_settings = dict((k,list(v)) for k,v in compiler_settings.items()) sources = ['tfr.c','mtm.c', 'libtfr' + SUFFIX,] setup( name= 'libtfr', version= VERSION, ext_modules= [Extension('libtfr', sources=sources, **compiler_settings)], cmdclass={'build_ext': build_ext},
import sys import pkgconfig from distutils.core import setup from distutils.extension import Extension from Cython.Build import cythonize from pip.req import parse_requirements if pkgconfig.exists("watchy") is False: print >>sys.stderr, "Make sure pkg-config watchy --cflags --libs works." sys.exit(1) watchy = pkgconfig.parse("watchy") extensions = [ Extension( "pywatchy", ["bindings/python/pywatchy.pyx"], include_dirs=list(watchy["include_dirs"]), libraries=list(watchy["libraries"]), library_dirs=list(watchy["library_dirs"]), runtime_library_dirs=list(watchy["library_dirs"]), ) ] install_reqs = parse_requirements("./requirements.txt") reqs = [str(ir.req) for ir in install_reqs] setup( name="Watchy", version="0.2", url="https://github.com/redbrain/watchy", author="Philip Herron", author_email="*****@*****.**",
from setuptools import setup, Extension try: from Cython.Build import cythonize have_cython = True except ImportError: have_cython = False try: import pkgconfig have_pkgconfig = True except ImportError: have_pkgconfig = False if have_pkgconfig and pkgconfig.exists('libdiscid'): flags = pkgconfig.parse('libdiscid') define_macros = flags['define_macros'] include_dirs = flags['include_dirs'] library_dirs = flags['library_dirs'] libraries = list(flags['libraries']) else: define_macros = '' include_dirs = '' library_dirs = '' libraries = 'discid' if have_cython: # if Cython is available, rebuild _discid.c ext = cythonize([ Extension('libdiscid._discid', [
lib_headers = { "gmp": [ os.path.join(SAGE_INC, 'gmp.h') ], # cf. #8664, #9896 "gmpxx": [ os.path.join(SAGE_INC, 'gmpxx.h') ], "ntl": [ os.path.join(SAGE_INC, 'NTL', 'config.h') ] } print "include_dirs=",include_dirs r""" List of extension modules """ #from distutils.extension import Extension import os import pkgconfig # CBLAS can be one of multiple implementations cblas_pc = pkgconfig.parse('cblas') cblas_libs = list(cblas_pc['libraries']) cblas_library_dirs = list(cblas_pc['library_dirs']) cblas_include_dirs = list(cblas_pc['include_dirs']) # TODO: Remove Cygwin hack by installing a suitable cblas.pc if os.path.exists('/usr/lib/libblas.dll.a'): cblas_libs = ['gslcblas'] # GNU Scientific Library # Note we replace the built-in gslcblas with the above cblas gsl_pc = pkgconfig.parse('gsl') gsl_libs = list(set(gsl_pc['libraries']).difference(set(['gslcblas'])).union(set(cblas_libs))) gsl_library_dirs = list(gsl_pc['library_dirs']) gsl_include_dirs = list(gsl_pc['include_dirs']) aliases = dict( GSL_LIBRARIES=gsl_libs,
#!/usr/bin/env python import pkgconfig, os conf_file=open('site.cfg', 'w') conf_file.write('[ALL]\n') conf_file.write('library_dirs = '+ os.environ['SAGE_LOCAL']+ '/lib\n') conf_file.write('include_dirs = '+ os.environ['SAGE_LOCAL']+ '/include\n') pc_blas = pkgconfig.parse('cblas blas') pc_lapack = pkgconfig.parse('lapack') if not (os.environ['UNAME'] == 'Darwin'): conf_file.write('[blas]\n') inc_dir = pc_blas['include_dirs'] if len(inc_dir) > 0 : conf_file.write('include_dirs = '+ ':'.join(inc_dir)+'\n') lib_dir = pc_blas['library_dirs'] if len(lib_dir) > 0 : conf_file.write('library_dirs = '+ ':'.join(lib_dir)+'\n') conf_file.write('blas_libs = '+', '.join(pc_blas['libraries'])+'\n') conf_file.write('[lapack]\n') lib_dir = pc_lapack['library_dirs'] if len(lib_dir) > 0 : conf_file.write('library_dirs = '+ ':'.join(lib_dir)+'\n') conf_file.write('lapack_libs = '+', '.join(pc_lapack['libraries'])+'\n') conf_file.close()
def cython_aliases(required_modules=None, optional_modules=None): """ Return the aliases for compiling Cython code. These aliases are macros which can occur in ``# distutils`` headers. INPUT: - ``required_modules`` -- (default: taken from ``default_required_modules``) iterable of ``str`` values. - ``optional_modules`` -- (default: taken from ``default_optional_modules``) iterable of ``str`` values. EXAMPLES:: sage: from sage.env import cython_aliases sage: cython_aliases() {...} sage: sorted(cython_aliases().keys()) ['ARB_LIBRARY', 'CBLAS_CFLAGS', ..., 'ZLIB_LIBRARIES'] sage: cython_aliases(required_modules=('module-that-is-assumed-to-not-exist')) Traceback (most recent call last): ... PackageNotFoundError: ... sage: cython_aliases(required_modules=(), optional_modules=('module-that-is-assumed-to-not-exist')) {...} TESTS: We can use ``cython.parallel`` regardless of whether OpenMP is supported. This will run in parallel, if OpenMP is supported:: sage: cython(''' ....: #distutils: extra_compile_args = OPENMP_CFLAGS ....: #distutils: extra_link_args = OPENMP_CFLAGS ....: from cython.parallel import prange ....: ....: cdef int i ....: cdef int n = 30 ....: cdef int sum = 0 ....: ....: for i in prange(n, num_threads=4, nogil=True): ....: sum += i ....: ....: print(sum) ....: ''') 435 """ import pkgconfig import itertools if required_modules is None: required_modules = default_required_modules if optional_modules is None: optional_modules = default_optional_modules aliases = {} for lib, required in itertools.chain( ((lib, True) for lib in required_modules), ((lib, False) for lib in optional_modules)): var = lib.upper().replace("-", "") + "_" if lib == 'cblas': lib = get_cblas_pc_module_name() if lib == 'zlib': aliases[var + "CFLAGS"] = "" try: pc = pkgconfig.parse('zlib') libs = pkgconfig.libs(lib) except pkgconfig.PackageNotFoundError: from collections import defaultdict pc = defaultdict(list, {'libraries': ['z']}) libs = "-lz" else: try: aliases[var + "CFLAGS"] = pkgconfig.cflags(lib).split() pc = pkgconfig.parse(lib) libs = pkgconfig.libs(lib) except pkgconfig.PackageNotFoundError: if required: raise else: continue # It may seem that INCDIR is redundant because the -I options are also # passed in CFLAGS. However, "extra_compile_args" are put at the end # of the compiler command line. "include_dirs" go to the front; the # include search order matters. aliases[var + "INCDIR"] = pc['include_dirs'] aliases[var + "LIBDIR"] = pc['library_dirs'] aliases[var + "LIBEXTRA"] = list( filter(lambda s: not s.startswith(('-l', '-L')), libs.split())) aliases[var + "LIBRARIES"] = pc['libraries'] # uname-specific flags UNAME = os.uname() def uname_specific(name, value, alternative): if name in UNAME[0]: return value else: return alternative aliases["LINUX_NOEXECSTACK"] = uname_specific("Linux", ["-Wl,-z,noexecstack"], []) aliases["CYGWIN_SQLITE3_LIBS"] = uname_specific("CYGWIN", ["sqlite3"], []) # LinBox needs special care because it actually requires C++11 with # GNU extensions: -std=c++11 does not work, you need -std=gnu++11 # (this is true at least with GCC 7.2.0). # # Further, note that LinBox does not add any C++11 flag in its .pc # file (possibly because of confusion between CFLAGS and CXXFLAGS?). # This is not a problem in practice since LinBox depends on # fflas-ffpack and fflas-ffpack does add such a C++11 flag. if "LINBOX_CFLAGS" in aliases: aliases["LINBOX_CFLAGS"].append("-std=gnu++11") aliases["ARB_LIBRARY"] = ARB_LIBRARY # TODO: Remove Cygwin hack by installing a suitable cblas.pc if os.path.exists('/usr/lib/libblas.dll.a'): aliases["CBLAS_LIBS"] = ['gslcblas'] try: aliases["M4RI_CFLAGS"].remove("-pedantic") except (ValueError, KeyError): pass # Determine ecl-specific compiler arguments using the ecl-config script ecl_cflags = subprocess.run([ECL_CONFIG, "--cflags"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True).stdout.split() aliases["ECL_CFLAGS"] = list( filter(lambda s: not s.startswith('-I'), ecl_cflags)) aliases["ECL_INCDIR"] = list( map(lambda s: s[2:], filter(lambda s: s.startswith('-I'), ecl_cflags))) ecl_libs = subprocess.run([ECL_CONFIG, "--libs"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True).stdout.split() aliases["ECL_LIBDIR"] = list( map(lambda s: s[2:], filter(lambda s: s.startswith('-L'), ecl_libs))) aliases["ECL_LIBRARIES"] = list( map(lambda s: s[2:], filter(lambda s: s.startswith('-l'), ecl_libs))) aliases["ECL_LIBEXTRA"] = list( filter(lambda s: not s.startswith(('-l', '-L')), ecl_libs)) # NTL aliases["NTL_CFLAGS"] = ['-std=c++11'] aliases["NTL_INCDIR"] = [NTL_INCDIR] if NTL_INCDIR else [] aliases["NTL_LIBDIR"] = [NTL_LIBDIR] if NTL_LIBDIR else [] aliases["NTL_LIBRARIES"] = ['ntl'] aliases["NTL_LIBEXTRA"] = [] # OpenMP aliases["OPENMP_CFLAGS"] = OPENMP_CFLAGS.split() aliases["OPENMP_CXXFLAGS"] = OPENMP_CXXFLAGS.split() return aliases
VERSION = '1.1.0' if not pkgconfig.installed('pygobject-3.0', '>=3.2.2') and \ not pkgconfig.installed('pygobject-2.0', '>=2.28'): sys.exit("You must install pygobject-2.0 or pygobject-3.0") if not pkgconfig.installed('ufo', '>=0.4.0'): sys.exit("You must install ufo>=0.4.0") def listify(d): return {k: list(v) for k, v in d.items()} build_flags = listify(pkgconfig.parse('pygobject-3.0 ufo')) build_flags['include_dirs'].append(numpy.get_include()) build_flags['extra_compile_args'] = ['-std=c99'] setup( name='ufo', version=VERSION, author='Matthias Vogelgesang', author_email='*****@*****.**', url='http://ufo.kit.edu', license='GPL v3 (?)', description='ufo extension module', long_description='ufo extension module', packages=['ufo'], ext_modules=[Extension('_ufo', ['src/ufo.c'], **build_flags)],
import sys import pkgconfig from distutils.core import setup from distutils.extension import Extension from Cython.Build import cythonize from pip.req import parse_requirements if pkgconfig.exists ('watchy') is False: print >> sys.stderr, "Make sure pkg-config watchy --cflags --libs works." sys.exit (1) watchy = pkgconfig.parse ('watchy') extensions = [ Extension ('pywatchy', ['bindings/python/pywatchy.pyx'], include_dirs = list (watchy ['include_dirs']), libraries = list (watchy ['libraries']), library_dirs = list (watchy ['library_dirs']), runtime_library_dirs = list (watchy ['library_dirs'])) ] install_reqs = parse_requirements ('./requirements.txt') reqs = [str(ir.req) for ir in install_reqs] setup ( name = "Watchy", version = "0.2", url = 'https://github.com/redbrain/watchy', author = 'Philip Herron', author_email = '*****@*****.**', license = "MIT", description = 'A stats agregation daemon over UDP', platforms = ('Any',),
def _get_cython_ext(self): from numpy.distutils.system_info import get_info from setuptools import Extension base_path = join('scikits', 'odes', 'sundials') base_module = "scikits.odes.sundials" SUNDIALS_LIBRARIES = [] CVODE_LIBRARIES = [] IDA_LIBRARIES = [] SUNDIALS_LIBRARY_DIRS = [] CVODE_LIBRARY_DIRS = [] IDA_LIBRARY_DIRS = [] SUNDIALS_INCLUDE_DIRS = [] CVODE_INCLUDE_DIRS = [] IDA_INCLUDE_DIRS = [] SUNDIALS_LIBDIR = os.environ.get("SUNDIALS_LIBDIR") SUNDIALS_INCLUDEDIR = os.environ.get("SUNDIALS_INCLUDEDIR") SUNDIALS_INST_PREFIX = os.environ.get("SUNDIALS_INST") if SUNDIALS_LIBDIR or SUNDIALS_INCLUDEDIR: SUNDIALS_INCLUDE_DIRS.extend( [SUNDIALS_INCLUDEDIR] if SUNDIALS_INCLUDEDIR is not None else [] ) SUNDIALS_LIBRARY_DIRS.extend( [SUNDIALS_LIBDIR] if SUNDIALS_LIBDIR is not None else [] ) elif SUNDIALS_INST_PREFIX is not None: SUNDIALS_LIBRARY_DIRS.append(os.path.join(SUNDIALS_INST_PREFIX, "lib")) SUNDIALS_INCLUDE_DIRS.append(os.path.join(SUNDIALS_INST_PREFIX, "include")) info("SUNDIALS installation path set to `{}` via $SUNDIALS_INST.".format( SUNDIALS_INST_PREFIX)) else: info("Searching for SUNDIALS path...") # use pkgconfig to find sundials try: import pkgconfig try: cvode_pkgconf = pkgconfig.parse(PKGCONFIG_CVODE) for d in cvode_pkgconf.get('library_dirs', []): CVODE_LIBRARY_DIRS.append(str(d)) for d in cvode_pkgconf.get('include_dirs', []): CVODE_INCLUDE_DIRS.append(str(d)) for lib in cvode_pkgconf.get('include_dirs', []): CVODE_LIBRARIES.append(str(lib)) ida_pkgconf = pkgconfig.parse(PKGCONFIG_IDA) for d in ida_pkgconf.get('library_dirs', []): IDA_LIBRARY_DIRS.append(str(d)) for d in ida_pkgconf.get('include_dirs', []): IDA_INCLUDE_DIRS.append(str(d)) for lib in ida_pkgconf.get('include_dirs', []): IDA_LIBRARIES.append(str(lib)) except EnvironmentError: pass except ImportError: info("pkgconfig module not found, using preset paths") sundials_pxi, cfg = get_sundials_config_pxi(SUNDIALS_INCLUDE_DIRS, self.distribution) has_lapack = cfg['has_lapack'] if not SUNDIALS_LIBRARIES: # This is where to put N_vector codes (currently only serial is # supported) SUNDIALS_LIBRARIES.append('sundials_nvecserial') # SUNDIALS_LIBRARIES.append('sundials_nvecopenmp') # SUNDIALS_LIBRARIES.append('sundials_nvecparallel') # SUNDIALS_LIBRARIES.append('sundials_nvecparhyp') # SUNDIALS_LIBRARIES.append('sundials_nvecpetsc') # SUNDIALS_LIBRARIES.append('sundials_nvecpthreads') # This is where to put SUNLinearSolver codes (klu not supported # yet) if has_lapack: SUNDIALS_LIBRARIES.append('sundials_sunlinsollapackband') SUNDIALS_LIBRARIES.append('sundials_sunlinsollapackdense') SUNDIALS_LIBRARIES.append('sundials_sunlinsolband') SUNDIALS_LIBRARIES.append('sundials_sunlinsoldense') SUNDIALS_LIBRARIES.append('sundials_sunlinsolpcg') SUNDIALS_LIBRARIES.append('sundials_sunlinsolspbcgs') SUNDIALS_LIBRARIES.append('sundials_sunlinsolspfgmr') SUNDIALS_LIBRARIES.append('sundials_sunlinsolspgmr') SUNDIALS_LIBRARIES.append('sundials_sunlinsolsptfqmr') # SUNDIALS_LIBRARIES.append('sundials_sunlinsolklu') # This is where to put SUNMatrix codes SUNDIALS_LIBRARIES.append('sundials_sunmatrixband') SUNDIALS_LIBRARIES.append('sundials_sunmatrixdense') SUNDIALS_LIBRARIES.append('sundials_sunmatrixsparse') if not IDA_LIBRARIES: IDA_LIBRARIES.append('sundials_ida') if not CVODE_LIBRARIES: CVODE_LIBRARIES.append('sundials_cvode') if has_lapack: lapack_opt = get_info('lapack_opt', notfound_action=2) if lapack_opt: SUNDIALS_INCLUDE_DIRS.extend(lapack_opt.get('include_dirs',[])) SUNDIALS_LIBRARY_DIRS.extend(lapack_opt.get('library_dirs',[])) SUNDIALS_LIBRARIES.extend(lapack_opt.get('libraries',[])) info('Found LAPACK paths via lapack_opt ...') else: info('LAPACK was not found, but SUNDIALS compiled against ' 'lapack, check your numpy installation' ) CVODE_LIBRARIES.extend(SUNDIALS_LIBRARIES) IDA_LIBRARIES.extend(SUNDIALS_LIBRARIES) CVODE_INCLUDE_DIRS.extend(SUNDIALS_INCLUDE_DIRS) IDA_INCLUDE_DIRS.extend(SUNDIALS_INCLUDE_DIRS) CVODE_LIBRARY_DIRS.extend(SUNDIALS_LIBRARY_DIRS) IDA_LIBRARY_DIRS.extend(SUNDIALS_LIBRARY_DIRS) return [ Extension( base_module + '.' + "common_defs", sources = [join(base_path, 'common_defs.pyx')], include_dirs=SUNDIALS_INCLUDE_DIRS, library_dirs=SUNDIALS_LIBRARY_DIRS, libraries=SUNDIALS_LIBRARIES, ), Extension( base_module + '.' + "cvode", sources = [join(base_path, 'cvode.pyx')], include_dirs=CVODE_INCLUDE_DIRS, library_dirs=CVODE_LIBRARY_DIRS, libraries=CVODE_LIBRARIES, ), Extension( base_module + '.' + "ida", sources = [join(base_path, 'ida.pyx')], include_dirs=IDA_INCLUDE_DIRS, library_dirs=IDA_LIBRARY_DIRS, libraries=IDA_LIBRARIES, ), ]
# Poor version of pkgconfig package. def try_lib_named(pkgconfig_name, libname): try: libs = subprocess.check_output(['pkg-config', '--libs-only-l', pkgconfig_name]).strip().split() libs_r = [] for i in libs: i = i.decode('ascii') assert i.startswith('-l') libs_r.append(i[2:]) return libs_r except subprocess.CalledProcessError: return [libname] if have_pkgconfig: potrace_lib = pkgconfig.parse('potrace')['libraries'] agg_lib = pkgconfig.parse('agg')['libraries'] else: agg_lib = try_lib_named('libagg', 'agg') potrace_lib = try_lib_named('potrace', 'potrace') ext_modules = [ Extension("potrace._potrace", ["potrace/_potrace.pyx"], libraries=potrace_lib, include_dirs=[numpy.get_include()]), Extension("potrace.bezier", ["potrace/bezier.pyx"], libraries=agg_lib, language="c++", include_dirs=[numpy.get_include()]), Extension("potrace.agg.curves", ["potrace/agg/curves.pyx"], libraries=agg_lib, language="c++"), ]
# Use pkg-config to find location of libbson and libmongoc. try: import pkgconfig except ImportError: # Set to default locations for libmongoc and libbson. warnings.warn(("WARNING: the python package pkgconfig is not installed. " "If you have pkg-config installed on your system, please " "install the python's pkgconfig, e.g. \"pip install " "pkgconfig\". Will use libmongoc=%s and libbson=%s instead." % (mongoc_src, bson_src))) else: try: # Use pkgconfig to find location of libmongoc or libbson. if pkgconfig.exists("libmongoc-1.0"): pkgcfg = pkgconfig.parse("libmongoc-1.0") settings['include_dirs'] = list(pkgcfg['include_dirs']) settings['library_dirs'] = list(pkgcfg['library_dirs']) settings['libraries'] = list(pkgcfg['libraries']) settings['define_macros'] = list(pkgcfg['define_macros']) else: warnings.warn(("WARNING: unable to find libmongoc-1.0 with " "pkgconfig. Please check that PKG_CONFIG_PATH is " "set to a path that can find the .pc files for " "libbson and libmongoc. Will use libmongoc=%s and " "libbson=%s instead." % (mongoc_src, bson_src))) except EnvironmentError: warnings.warn(("WARNING: the system tool pkg-config is not installed. " "Will use libmongoc=%s and libbson=%s instead." % (mongoc_src, bson_src)))
from distutils.core import setup, Extension import warnings pkg_dict = dict( libraries=['hdf5'], library_dirs=[], include_dirs=[], ) try: import pkgconfig except ImportError: warnings.warn('python-pkgconfig not installed, using default search path to find HDF5') else: if pkgconfig.exists('hdf5'): pkg_dict = pkgconfig.parse('hdf5') else: warnings.warn('pkgconfig cannot find HDF5, using default path') setup(name="digital_rf_hdf5", version="1.1.3", description="Python tools to read and write digital rf data in Hdf5 format", author="Bill Rideout", author_email="*****@*****.**", url="http://www.haystack.mit.edu/~brideout/", package_dir = {'': 'source'}, py_modules=['digital_rf_hdf5', 'digital_metadata'], ext_modules=[Extension("_py_rf_write_hdf5", ["source/_py_rf_write_hdf5.c", "source/rf_write_hdf5.c"], libraries=list(pkg_dict['libraries']), library_dirs=list(pkg_dict['library_dirs']),
# -*- coding: utf-8 -*- import pkgconfig import numpy import hashlib import dijitso import dolfin.cpp as cpp from dolfin.cpp import MPI from functools import wraps import ffc from dolfin.cpp.parameter import parameters # Get DOLFIN pkg-config data if pkgconfig.exists("dolfin"): dolfin_pc = pkgconfig.parse("dolfin") else: raise RuntimeError("Could not find DOLFIN pkg-config file. Please make sure appropriate paths are set.") # Copied over from site-packages def mpi_jit_decorator(local_jit, *args, **kwargs): """A decorator for jit compilation Use this function as a decorator to any jit compiler function. In a parallel run, this function will first call the jit compilation function on the first process. When this is done, and the module is in the cache, it will call the jit compiler on the remaining processes, which will then use the cached module. *Example*
# # http://www.gnu.org/licenses/ #***************************************************************************** from __future__ import print_function import os, sys, platform, __builtin__ from sage.env import SAGE_LOCAL, SAGE_SRC, SAGE_LIB, UNAME from misc import SPYX_TMP from temporary_file import tmp_filename import pkgconfig # CBLAS can be one of multiple implementations cblas_pc = pkgconfig.parse('cblas') cblas_libs = list(cblas_pc['libraries']) cblas_library_dirs = list(cblas_pc['library_dirs']) cblas_include_dirs = list(cblas_pc['include_dirs']) # TODO: Remove Cygwin hack by installing a suitable cblas.pc if os.path.exists('/usr/lib/libblas.dll.a'): cblas_libs = 'gslcblas' standard_libs = [ 'mpfr', 'gmp', 'gmpxx', 'stdc++', 'pari', 'm', 'ec', 'gsl', ] + cblas_libs + [ 'ntl']
LIBS_SUNDIALS = ['sundials_nvecserial'] LIBS_IDA = ['sundials_ida'] LIBS_CVODE = ['sundials_cvode'] # paths for FORTRAN LIB_DIRS_FORTRAN = [] LIBS_FORTRAN = [] # use pkgconfig to find sundials PKGCONFIG_CVODE = 'sundials-cvode-serial' try: import pkgconfig try: if pkgconfig.exists(PKGCONFIG_CVODE): pkgconf = pkgconfig.parse(PKGCONFIG_CVODE) for d in pkgconf['library_dirs']: LIB_DIRS_SUNDIALS.append(str(d)) for d in pkgconf['include_dirs']: INCL_DIRS_SUNDIALS.append(str(d)) except EnvironmentError: pass except ImportError: print("pkgconfig module not found, using preset paths") if "SUNDIALS_INST" in os.environ: LIB_DIRS_SUNDIALS.append(os.path.join(os.environ["SUNDIALS_INST"], "lib")) INCL_DIRS_SUNDIALS.append(os.path.join(os.environ["SUNDIALS_INST"], "include")) print("SUNDIALS installation path set to `{}` via $SUNDIALS_INST.".format( os.environ["SUNDIALS_INST"])) else:
# All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the BSD license. See the accompanying LICENSE file # or read the terms at https://opensource.org/licenses/BSD-3-Clause. from cffi import FFI import pkgconfig if not pkgconfig.exists("fftw3"): raise RuntimeError("NFFT library not found via pkgconfig.") # Transform pkgconfig output to a dictionary of lists, which is the only format # accepted by distutils. pc_fftw3 = {key: list(val) for (key, val) in pkgconfig.parse("fftw3").items()} ffi = FFI() ffi.cdef( """ #define FFTW_FORWARD ... #define FFTW_BACKWARD ... #define FFTW_MEASURE ... #define FFTW_DESTROY_INPUT ... #define FFTW_UNALIGNED ... #define FFTW_CONSERVE_MEMORY ... #define FFTW_EXHAUSTIVE ... #define FFTW_PRESERVE_INPUT ... #define FFTW_PATIENT ...
# All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the BSD license. See the accompanying LICENSE file # or read the terms at https://opensource.org/licenses/BSD-3-Clause. from cffi import FFI import pkgconfig if not pkgconfig.exists("nfft3"): raise RuntimeError("NFFT library not found via pkgconfig.") # Transform pkgconfig output to a dictionary of lists, which is the only format # accepted by distutils. pc_nfft3 = {key: list(val) for (key, val) in pkgconfig.parse("nfft3").items()} ffi = FFI() ffi.cdef(""" typedef ... fftw_complex; #define FFTW_MEASURE ... #define FFTW_DESTROY_INPUT ... typedef struct { fftw_complex *f_hat; fftw_complex *f; double *x; ...;
compile_opts['define_macros'].extend([('WINDOWS', None), ('_WIN32', None)]) elif platform.system() == "Darwin": ignore_subdirs = {'linux', 'winusb', 'windows'} compile_opts = dict(define_macros=[], include_dirs=[], libraries=[], library_dirs=[]) compile_opts['extra_link_args'] = [ '-framework', 'Carbon', '-framework', 'CoreFoundation', '-framework', 'IOKit' ] else: ignore_subdirs = {'osx', 'winusb', 'windows'} try: import pkgconfig compile_opts = pkgconfig.parse('libusb') except ImportError: compile_opts = dict(define_macros=[], include_dirs=[], libraries=['usb'], library_dirs=[]) # Collect all source files for cseabreeze backend sources = ['src/seabreeze/cseabreeze/c_seabreeze_wrapper.pyx'] for root, subdirs, fns in os.walk('src/libseabreeze/src'): subdirs[:] = (d for d in subdirs if d not in ignore_subdirs) sources.extend((os.path.join(root, fn) for fn in fns)) # Add seabreeze include dirs compile_opts['include_dirs'].append(os.path.relpath('src/libseabreeze/include')) # define extension libseabreeze = Extension('seabreeze.cseabreeze._wrapper', language='c++', sources=[os.path.relpath(s) for s in sources],
import bagwacl import pyopencl as cl from distutils.core import setup,Extension import pkgconfig assert pkgconfig.exists('lal') assert pkgconfig.exists('lalsimulation') assert pkgconfig.exists('lalinference') # Compile flags c=pkgconfig.parse('lal lalsimulation lalinference') bagwacl.generate_bagwacl_data() setup( name='bagwacl', version='0.1', packages=['bagwacl'], scripts=['bin/lalinference_bagwacl'], ext_modules=[ Extension( 'libbagwacl', ['./src/bagwacl.c'], libraries=list(c['libraries']), library_dirs=list(c['library_dirs']), include_dirs=list(c['include_dirs']), runtime_library_dirs=list(c['library_dirs']), extra_compile_args=['-std=c99'], )