Today, I had to scratch an itch that concerned calling pkg-config from
within Python. Imagine that you write an extension module that depends on some
external development libraries. First you want to make sure that you build
against a version that provides the features you expect and second you have to
provide pre-processor directives, compiler flags and library options to build
your module. The
pkg-config command line tool can be used to query this meta
information from its database, at least that’s how it’s done in the manual
Makefile and Autotools world. To gather that information in an arbitrary Python
script, I wrote a small helper module called pkgconfig.
To fill this empty post with more blurb, I will restate the README here:
pkgconfig can be used to check if a package exists
>>> import pkgconfig >>> pkgconfig.exists('glib-2.0') True
check if a package meets certain version requirements
>>> pkgconfig.installed('glib-2.0', '< 2.26') False >>> pkgconfig.installed('glib-2.0', '>=2.26') True
and also query the
LDFLAGS for building a dependent module
>>> pkgconfig.cflags('glib-2.0') '-I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include' >>> pkgconfig.libs('glib-2.0') '-lglib-2.0'
The module is licensed under the MIT license, so if you want to use it in your private projects, just dump it there. Suggestions and bug reports should be addressed in the GitHub repo.
PS: I know, it’s the worst project tag line in the history of project tag lines.