setup: Remove dep on importing virtinst

Import BuildConfig directly from the source file using import hackery.
buildconfig.py is independent of virtinst code so it already does
the right thing. Add some checking to make sure this doesn't regress
in the future.

Drop the now unneeded RPM deps.
This commit is contained in:
Cole Robinson 2019-06-17 11:14:39 -04:00
parent d097e66324
commit c92693a276
2 changed files with 18 additions and 28 deletions

View File

@ -12,7 +12,6 @@ if sys.version_info.major < 3:
import glob import glob
import fnmatch import fnmatch
import os import os
import re
import unittest import unittest
import distutils import distutils
@ -29,22 +28,25 @@ import distutils.sysconfig
sysprefix = distutils.sysconfig.get_config_var("prefix") sysprefix = distutils.sysconfig.get_config_var("prefix")
def _parse_version(): def _import_buildconfig():
# We do these tricks to not mess up code coverage testing. Switching # A bit of crazyness to import the buildconfig file without importing
# to pytest will let use drop these # the rest of virtinst, so the build process doesn't require all the
path = os.path.join(os.path.dirname(__file__), # runtime deps to be installed
"virtinst", "buildconfig.py") import warnings
content = open(path).read()
match = re.search(r"^__version__ = \".*\"$", content, re.MULTILINE) # 'imp' is deprecated. We use it elsewhere though too. Deal with using
return str(match.group(0)).split()[-1].strip("\"") # the modern replacement when we replace all usage
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
import imp
buildconfig = imp.load_source('buildconfig', 'virtinst/buildconfig.py')
if "libvirt" in sys.modules:
raise RuntimeError("Found libvirt in sys.modules. setup.py should "
"not import virtinst.")
return buildconfig.BuildConfig
def _get_buildconfig(): BuildConfig = _import_buildconfig()
from virtinst import BuildConfig
return BuildConfig
VERSION = _parse_version()
# pylint: disable=attribute-defined-outside-init # pylint: disable=attribute-defined-outside-init
@ -180,8 +182,6 @@ class my_build(distutils.command.build.build):
def _make_bin_wrappers(self): def _make_bin_wrappers(self):
cmds = ["virt-manager", "virt-install", "virt-clone", cmds = ["virt-manager", "virt-install", "virt-clone",
"virt-convert", "virt-xml"] "virt-convert", "virt-xml"]
BuildConfig = _get_buildconfig()
if not os.path.exists("build"): if not os.path.exists("build"):
os.mkdir("build") os.mkdir("build")
@ -198,7 +198,6 @@ class my_build(distutils.command.build.build):
def _make_man_pages(self): def _make_man_pages(self):
BuildConfig = _get_buildconfig()
for path in glob.glob("man/*.pod"): for path in glob.glob("man/*.pod"):
base = os.path.basename(path) base = os.path.basename(path)
appname = os.path.splitext(base)[0] appname = os.path.splitext(base)[0]
@ -281,7 +280,6 @@ class my_install(distutils.command.install.install):
Error if we weren't 'configure'd with the correct install prefix Error if we weren't 'configure'd with the correct install prefix
""" """
def finalize_options(self): def finalize_options(self):
BuildConfig = _get_buildconfig()
if self.prefix is None: if self.prefix is None:
if BuildConfig.prefix != sysprefix: if BuildConfig.prefix != sysprefix:
print("Using configured prefix=%s instead of sysprefix=%s" % ( print("Using configured prefix=%s instead of sysprefix=%s" % (
@ -320,7 +318,6 @@ class my_sdist(distutils.command.sdist.sdist):
description = "Update virt-manager.spec; build sdist-tarball." description = "Update virt-manager.spec; build sdist-tarball."
def run(self): def run(self):
BuildConfig = _get_buildconfig()
f1 = open('virt-manager.spec.in', 'r') f1 = open('virt-manager.spec.in', 'r')
f2 = open('virt-manager.spec', 'w') f2 = open('virt-manager.spec', 'w')
for line in f1: for line in f1:
@ -348,7 +345,6 @@ class my_rpm(distutils.core.Command):
""" """
Run sdist, then 'rpmbuild' the tar.gz Run sdist, then 'rpmbuild' the tar.gz
""" """
BuildConfig = _get_buildconfig()
self.run_command('sdist') self.run_command('sdist')
os.system('rpmbuild -ta --clean dist/virt-manager-%s.tar.gz' % os.system('rpmbuild -ta --clean dist/virt-manager-%s.tar.gz' %
BuildConfig.version) BuildConfig.version)
@ -376,7 +372,6 @@ class configure(distutils.core.Command):
def run(self): def run(self):
BuildConfig = _get_buildconfig()
template = "" template = ""
template += "[config]\n" template += "[config]\n"
template += "prefix = %s\n" % self.prefix template += "prefix = %s\n" % self.prefix
@ -665,7 +660,7 @@ class VMMDistribution(distutils.dist.Distribution):
distutils.core.setup( distutils.core.setup(
name="virt-manager", name="virt-manager",
version=VERSION, version=BuildConfig.version,
author="Cole Robinson", author="Cole Robinson",
author_email="virt-tools-list@redhat.com", author_email="virt-tools-list@redhat.com",
url="http://virt-manager.org", url="http://virt-manager.org",

View File

@ -59,11 +59,6 @@ Suggests: python3-libguestfs
BuildRequires: intltool BuildRequires: intltool
BuildRequires: /usr/bin/pod2man BuildRequires: /usr/bin/pod2man
BuildRequires: python3-devel BuildRequires: python3-devel
BuildRequires: python3-gobject-base
BuildRequires: python3-libvirt
BuildRequires: python3-libxml2
BuildRequires: python3-requests
BuildRequires: libosinfo >= 0.2.10
%description %description