diff options
author | Cole Robinson <crobinso@redhat.com> | 2014-03-22 19:22:34 -0400 |
---|---|---|
committer | Cole Robinson <crobinso@redhat.com> | 2014-03-25 13:37:02 -0400 |
commit | a180fd981b4b160a4a625127671bdc663c2cc6d2 (patch) | |
tree | 0d22ff94ce928d8acb3d28b312214ca4b74a0205 | |
parent | 115760f6f03ca5fd67b01176e325aceaecb08fe6 (diff) | |
download | libvirt-python-a180fd981b4b160a4a625127671bdc663c2cc6d2.tar.gz |
setup.py: Allow running --help or clean without pkg-config
If pkg-config isn't installed, or a too old libvirt, we can't even
do 'python setup.py --help' without throwing an exception.
Have the pkg-config checks and validation only throw an exception if
being called from the 'build' step.
https://bugzilla.redhat.com/show_bug.cgi?id=1074170
-rwxr-xr-x | setup.py | 31 |
1 files changed, 20 insertions, 11 deletions
@@ -24,19 +24,24 @@ MIN_LIBVIRT_LXC = "1.0.2" if not os.path.exists("build"): os.mkdir("build") -pkgcfg = distutils.spawn.find_executable("pkg-config") - -if pkgcfg is None: - raise Exception("pkg-config binary is required to compile libvirt-python") - -spawn([pkgcfg, - "--print-errors", - "--atleast-version=%s" % MIN_LIBVIRT, - "libvirt"]) +_pkgcfg = -1 +def get_pkgcfg(do_fail=True): + global _pkgcfg + if _pkgcfg == -1: + _pkgcfg = distutils.spawn.find_executable("pkg-config") + if _pkgcfg is None and do_fail: + raise Exception("pkg-config binary is required to compile libvirt-python") + return _pkgcfg + +def check_minimum_libvirt_version(): + spawn([get_pkgcfg(), + "--print-errors", + "--atleast-version=%s" % MIN_LIBVIRT, + "libvirt"]) def have_libvirt_lxc(): try: - spawn([pkgcfg, + spawn([get_pkgcfg(), "--atleast-version=%s" % MIN_LIBVIRT_LXC, "libvirt"]) return True @@ -45,7 +50,7 @@ def have_libvirt_lxc(): def get_pkgconfig_data(args, mod, required=True): """Run pkg-config to and return content associated with it""" - f = os.popen("%s %s %s" % (pkgcfg, " ".join(args), mod)) + f = os.popen("%s %s %s" % (get_pkgcfg(), " ".join(args), mod)) line = f.readline() if line is not None: @@ -78,6 +83,9 @@ def get_module_lists(): Determine which modules we are actually building, and all their required config """ + if get_pkgcfg(do_fail=False) is None: + return [], [] + c_modules = [] py_modules = [] ldflags = get_pkgconfig_data(["--libs-only-L"], "libvirt", False) @@ -130,6 +138,7 @@ def get_module_lists(): class my_build(build): def run(self): + check_minimum_libvirt_version() apis = get_api_xml_files() self.spawn([sys.executable, "generator.py", "libvirt", apis[0]]) |