How to use the pkgconfig.parse function in pkgconfig

To help you get started, we’ve selected a few pkgconfig examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github matze / pkgconfig / test_pkgconfig.py View on Github external
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')
github matze / pkgconfig / test_pkgconfig.py View on Github external
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')
github libvips / pyvips / pyvips / pyvips_build.py View on Github external
import pkgconfig
from cffi import FFI

# we must have the vips package to be able to do anything
if not pkgconfig.exists('vips'): 
    raise Exception('unable to find pkg-config package "vips"')
if pkgconfig.installed('vips', '< 8.2'):
    raise Exception('pkg-config "vips" is too old -- need libvips 8.2 or later')

ffibuilder = FFI()

ffibuilder.set_source("_libvips",
    r""" 
        #include 
    """, 
    **pkgconfig.parse('vips'))

# pkgconfig 1.5+ has modversion ... otherwise, use a small shim
try:
    from pkgconfig import modversion
except ImportError:
    def modversion(package):
        # will need updating once we hit 8.20 :(
        for i in range(20, 3, -1):
            if pkgconfig.installed(package, '>= 8.' + str(i)):
                # be careful micro version is always set to 0
                return '8.' + str(i) + '.0'
        return '8.2.0'

major, minor, micro = [int(s) for s in modversion('vips').split('.')]

features = {
github concordusapps / python-hummus / setup.py View on Github external
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')
github mehcode / python-xmlsec / xmlsec_setupinfo.py View on Github external
'User32',
                'Gdi32',
                'Crypt32',
            ],
            'include_dirs': [],
            'library_dirs': [],
            }

        xmlsec_extra.get_prebuilt_libs(
            OPTION_DOWNLOAD_DIR, config['include_dirs'], config['library_dirs']
        )
    else:
        import pkgconfig

        try:
            config = pkgconfig.parse('xmlsec1')
        except EnvironmentError:
            pass

        if config is None or not config.get('libraries'):
            fatal_xmlsec1_error()

        # make sure that all options are list
        for x in ('libraries', 'include_dirs', 'library_dirs'):
            config[x] = list(config.get(x) or [])

        # fix macros, ensure that macros is list
        macros = list(config.get('define_macros', []))
        for i, v in enumerate(macros):
            if v[0] == 'XMLSEC_CRYPTO' and not (v[1].startswith('"') and v[1].endswith('"')):
                macros[i] = ('XMLSEC_CRYPTO', '"{0}"'.format(v[1]))
                break
github ap-- / python-seabreeze / setup.py View on Github external
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],
                             **compile_opts)
github h5py / h5py / setup_configure.py View on Github external
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
github MITHaystack / digital_rf / python / setup.py View on Github external
except ImportError:
            infostr = (
                "INFO: python-pkgconfig not installed. Defaulting to" ' HDF5_ROOT="{0}"'
            )
            print(infostr.format(HDF5_ROOT))
        else:
            try:
                hdf5_exists = pkgconfig.exists("hdf5")
            except EnvironmentError:
                infostr = (
                    "INFO: pkg-config not installed. Defaulting to" ' HDF5_ROOT="{0}"'
                )
                print(infostr.format(HDF5_ROOT))
            else:
                if hdf5_exists:
                    hdf5_pkgconfig = pkgconfig.parse("hdf5")
                    for k in ("include_dirs", "library_dirs", "libraries"):
                        hdf5_config[k] = list(hdf5_pkgconfig[k])
                else:
                    infostr = (
                        "INFO: pkgconfig cannot find HDF5. Defaulting to"
                        ' HDF5_ROOT="{0}"'
                    )
                    print(infostr.format(HDF5_ROOT))
        # use environment variables to override discovered settings
        hdf5_env_config = dict(
            include_dirs="HDF5_INCLUDE_DIRS",
            library_dirs="HDF5_LIBRARY_DIRS",
            libraries="HDF5_LIBRARIES",
            define="HDF5_DEFINE",
        )
        for k, e in hdf5_env_config.items():