[Python-modules-commits] [python-pkgconfig] 01/05: Import python-pkgconfig_1.2.2.orig.tar.gz

Josué Ortega josue at moszumanska.debian.org
Sun Dec 11 19:29:10 UTC 2016


This is an automated email from the git hooks/post-receive script.

josue pushed a commit to branch master
in repository python-pkgconfig.

commit 11ddd6799e01b1520fb726e70ee765ee3d345c3f
Author: Josue Ortega <josue at debian.org>
Date:   Sun Dec 11 13:23:13 2016 -0600

    Import python-pkgconfig_1.2.2.orig.tar.gz
---
 .gitignore             |  1 +
 .travis.yml            |  3 ++-
 MANIFEST.in            |  2 ++
 README.rst             | 48 ++++++++++++++++++++++++++++++++++++++++++++-
 data/fake-gtk+-3.0.pc  |  2 +-
 data/fake-python.pc    |  2 +-
 pkgconfig/pkgconfig.py | 53 ++++++++++++++++++++++++++++++++++++--------------
 setup.py               |  2 +-
 test.py                | 11 +++++++++--
 tox.ini                |  2 +-
 10 files changed, 103 insertions(+), 23 deletions(-)

diff --git a/.gitignore b/.gitignore
index 8d70289..315af43 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,7 @@
 build/
 dist/
 .tox/
+.eggs/
 *.egg/*
 *.egg-info
 *.pyc
diff --git a/.travis.yml b/.travis.yml
index 8dc9bcd..c0ec9d6 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -5,8 +5,9 @@ python:
     - "2.7"
     - "3.2"
     - "3.3"
+    - "3.4"
 
 install:
-    - pip install nose --use-mirrors
+    - pip install nose
 
 script: nosetests
diff --git a/MANIFEST.in b/MANIFEST.in
index 9d5d250..9cbe7d3 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,2 +1,4 @@
 include LICENSE
 include README.rst
+include test.py
+include data/*
diff --git a/README.rst b/README.rst
index 11de6a0..0d7cced 100644
--- a/README.rst
+++ b/README.rst
@@ -9,6 +9,10 @@ command line tool and supports Python 2.6+.
 
 It can be used to
 
+-  find all pkg-config packages ::
+
+       >>> packages = pkgconfig.list_all()
+
 -  check if a package exists ::
 
        >>> pkgconfig.exists('glib-2.0')
@@ -31,6 +35,48 @@ It can be used to
 
        >>> d = pkgconfig.parse('glib-2.0 gtk+-2.0')
        >>> d['libraries']
-       set([u'glib-2.0', u'gtk+-2.0'])
+       [u'gtk+-2.0', u'glib-2.0']
+
+   The ``pkgconfig.parse`` function return a dictonary of list.
+   The lists returned are an accurate representations of the equivalent
+   ``pkg-config`` call, both in content and order.
+
+If ``pkg-config`` is not on the path, raises ``EnvironmentError``.
 
 The ``pkgconfig`` module is licensed under the MIT license.
+
+
+Changelog
+---------
+
+Version 1.2.1 and 1.2.2
+~~~~~~~~~~~~~~~~~~~~~~~
+
+Bug fix releases released on December 1st and 2nd 2016.
+
+- Include the ``data`` folder in the distribution in order to run tests
+- Improve the tests
+
+
+Version 1.2.0
+~~~~~~~~~~~~~
+
+Released on November 30th 2016.
+
+- Potential break: switch from result set to list
+- Expose --list-all query
+- Added support for PKG_CONFIG environment variable
+
+
+Version 1.1.0
+~~~~~~~~~~~~~
+
+Released on November 6th 2013.
+
+- Multiple packages can now be parsed with a single call to ``.parse``.
+
+
+Version 1.0.0
+~~~~~~~~~~~~~
+
+First release on September 8th 2013.
diff --git a/data/fake-gtk+-3.0.pc b/data/fake-gtk+-3.0.pc
index bf547b6..fbb1b83 100644
--- a/data/fake-gtk+-3.0.pc
+++ b/data/fake-gtk+-3.0.pc
@@ -1,6 +1,6 @@
 prefix=/usr
 exec_prefix=/usr
-libdir=/usr/lib64
+libdir=/usr/lib_gtk_foo
 includedir=/usr/include
 targets=x11 broadway
 
diff --git a/data/fake-python.pc b/data/fake-python.pc
index ad32999..2077ca0 100644
--- a/data/fake-python.pc
+++ b/data/fake-python.pc
@@ -1,6 +1,6 @@
 prefix=/usr
 exec_prefix=${prefix}
-libdir=${exec_prefix}/lib
+libdir=${exec_prefix}/lib_python_foo
 includedir=${prefix}/include
 
 Name: Python
diff --git a/pkgconfig/pkgconfig.py b/pkgconfig/pkgconfig.py
index 8b773bd..888e272 100644
--- a/pkgconfig/pkgconfig.py
+++ b/pkgconfig/pkgconfig.py
@@ -22,9 +22,11 @@
 """pkgconfig is a Python module to interface with the pkg-config command line
 tool."""
 
+import os
 import subprocess
 import re
 import collections
+from functools import wraps
 
 
 def _compare_versions(v1, v2):
@@ -51,6 +53,7 @@ def _split_version_specifier(spec):
 
 
 def _convert_error(func):
+    @wraps(func)
     def _wrapper(*args, **kwargs):
         try:
             return func(*args, **kwargs)
@@ -62,7 +65,8 @@ def _convert_error(func):
 
 @_convert_error
 def _query(package, option):
-    cmd = 'pkg-config {0} {1}'.format(option, package).split()
+    pkg_config_exe = os.environ.get('PKG_CONFIG', None) or 'pkg-config'
+    cmd = '{0} {1} {2}'.format(pkg_config_exe, option, package).split()
     proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
     out, err = proc.communicate()
@@ -72,19 +76,32 @@ def _query(package, option):
 
 @_convert_error
 def exists(package):
-    """Return True if package information is available."""
-    cmd = 'pkg-config --exists {0}'.format(package).split()
+    """
+    Return True if package information is available.
+
+    If ``pkg-config`` not on path, raises ``EnvironmentError``.
+    """
+    pkg_config_exe = os.environ.get('PKG_CONFIG', None) or 'pkg-config'
+    cmd = '{0} --exists {1}'.format(pkg_config_exe, package).split()
     return subprocess.call(cmd) == 0
 
 
 @_convert_error
 def requires(package):
-    """Return a list of package names that is required by the package"""
+    """
+    Return a list of package names that is required by the package.
+
+    If ``pkg-config`` not on path, raises ``EnvironmentError``.
+    """
     return _query(package, '--print-requires').split('\n')
 
 
 def cflags(package):
-    """Return the CFLAGS string returned by pkg-config."""
+    """
+    Return the CFLAGS string returned by pkg-config.
+
+    If ``pkg-config`` not on path, raises ``EnvironmentError``.
+    """
     return _query(package, '--cflags')
 
 
@@ -108,6 +125,8 @@ def installed(package, version):
     False
     >>> installed('foo', '>= 0.0.4')
     True
+
+    If ``pkg-config`` not on path, raises ``EnvironmentError``.
     """
     if not exists(package):
         return False
@@ -152,9 +171,11 @@ def parse(packages):
     Builds a dictionary containing the 'libraries', the 'library_dirs',
     the 'include_dirs', and the 'define_macros' that are presented by
     pkg-config. *package* is a string with space-delimited package names.
+
+    If ``pkg-config`` not on path, raises ``EnvironmentError``.
     """
     def parse_package(package):
-        result = collections.defaultdict(set)
+        result = collections.defaultdict(list)
 
         # Execute the query to pkg-config and clean the result.
         out = _query(package, '--cflags --libs')
@@ -164,27 +185,29 @@ def parse(packages):
         for token in out.split():
             key = _PARSE_MAP.get(token[:2])
             if key:
-                result[key].add(token[2:].strip())
+                result[key].append(token[2:].strip())
 
         # Iterate and clean define macros.
-        macros = set()
+        macros = list()
         for declaration in result['define_macros']:
             macro = tuple(declaration.split('='))
             if len(macro) == 1:
                 macro += '',
 
-            macros.add(macro)
+            macros.append(macro)
 
         result['define_macros'] = macros
 
         # Return parsed configuration.
         return result
 
-    # Go through all package names and update the result dict accordingly.
-    result = collections.defaultdict(set)
+    # Return the result of parse_package directly.
+    # We don't need to loop over the packages
+
+    return parse_package(packages)
 
-    for package in packages.split():
-        for k, v in parse_package(package).items():
-            result[k].update(v)
 
-    return result
+def list_all():
+    """Return a list of all packages found by pkg-config."""
+    packages = [line.split()[0] for line in _query('', '--list-all').split('\n')]
+    return packages
diff --git a/setup.py b/setup.py
index 6a204c7..aeb3172 100644
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,6 @@
 from setuptools import setup
 
-VERSION = '1.1.0'
+VERSION = '1.2.2'
 
 setup(
     name='pkgconfig',
diff --git a/test.py b/test.py
index ddb25b0..f03b663 100644
--- a/test.py
+++ b/test.py
@@ -36,7 +36,7 @@ def test_libs():
     flags = pkgconfig.libs(PACKAGE_NAME)
 
     for flag in flags.split(' '):
-        nt.assert_true(flag in ('-L/usr/lib64', '-lgtk-3'))
+        nt.assert_true(flag in ('-L/usr/lib_gtk_foo', '-lgtk-3'))
 
 
 def test_parse():
@@ -44,7 +44,14 @@ def test_parse():
 
     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('/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_listall():
+    packages = pkgconfig.list_all()
+    nt.assert_true('fake-gtk+-3.0' in packages)
+    nt.assert_true('fake-python' in packages)
diff --git a/tox.ini b/tox.ini
index eaa2882..96addc5 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,5 +1,5 @@
 [tox]
-envlist = py26, py27
+envlist = py26, py27, py32, py33, py34
 
 [testenv]
 deps = nose

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-pkgconfig.git



More information about the Python-modules-commits mailing list