Move Modulemd import to pungi/__init__.py to remove duplicated code.
Signed-off-by: Jan Kaluza <jkaluza@redhat.com>
This commit is contained in:
parent
3f71cdd384
commit
1574f306c7
@ -4,6 +4,15 @@ import os
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
from pdc_client import PDCClient
|
||||||
|
import gi
|
||||||
|
gi.require_version('Modulemd', '1.0') # noqa
|
||||||
|
from gi.repository import Modulemd
|
||||||
|
except:
|
||||||
|
Modulemd = None
|
||||||
|
|
||||||
|
|
||||||
def get_full_version():
|
def get_full_version():
|
||||||
"""
|
"""
|
||||||
Find full version of Pungi: if running from git, this will return cleaned
|
Find full version of Pungi: if running from git, this will return cleaned
|
||||||
|
@ -33,20 +33,11 @@ from ..wrappers.scm import get_dir_from_scm
|
|||||||
from ..wrappers.createrepo import CreaterepoWrapper
|
from ..wrappers.createrepo import CreaterepoWrapper
|
||||||
from .base import PhaseBase
|
from .base import PhaseBase
|
||||||
from ..util import find_old_compose, temp_dir, get_arch_variant_data
|
from ..util import find_old_compose, temp_dir, get_arch_variant_data
|
||||||
|
from pungi import Modulemd
|
||||||
|
|
||||||
import productmd.rpms
|
import productmd.rpms
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
from pdc_client import PDCClient
|
|
||||||
import gi
|
|
||||||
gi.require_version('Modulemd', '1.0') # noqa
|
|
||||||
from gi.repository import Modulemd
|
|
||||||
WITH_MODULES = True
|
|
||||||
except:
|
|
||||||
WITH_MODULES = False
|
|
||||||
|
|
||||||
|
|
||||||
createrepo_lock = threading.Lock()
|
createrepo_lock = threading.Lock()
|
||||||
createrepo_dirs = set()
|
createrepo_dirs = set()
|
||||||
|
|
||||||
@ -193,7 +184,7 @@ def create_variant_repo(compose, arch, variant, pkg_type):
|
|||||||
shutil.copy2(product_id_path, os.path.join(repo_dir, "repodata", "productid"))
|
shutil.copy2(product_id_path, os.path.join(repo_dir, "repodata", "productid"))
|
||||||
|
|
||||||
# call modifyrepo to inject modulemd if needed
|
# call modifyrepo to inject modulemd if needed
|
||||||
if arch in variant.arch_mmds and WITH_MODULES:
|
if arch in variant.arch_mmds and Modulemd is not None:
|
||||||
modules = []
|
modules = []
|
||||||
for mmd in variant.arch_mmds[arch].values():
|
for mmd in variant.arch_mmds[arch].values():
|
||||||
# Create copy of architecture specific mmd to filter out packages
|
# Create copy of architecture specific mmd to filter out packages
|
||||||
|
@ -27,6 +27,7 @@ from .link import link_files
|
|||||||
from pungi.util import get_arch_variant_data, get_arch_data, get_variant_data
|
from pungi.util import get_arch_variant_data, get_arch_data, get_variant_data
|
||||||
from pungi.phases.base import PhaseBase
|
from pungi.phases.base import PhaseBase
|
||||||
from pungi.arch import split_name_arch, get_compatible_arches
|
from pungi.arch import split_name_arch, get_compatible_arches
|
||||||
|
from pungi import Modulemd
|
||||||
|
|
||||||
|
|
||||||
def get_gather_source(name):
|
def get_gather_source(name):
|
||||||
@ -68,9 +69,7 @@ class GatherPhase(PhaseBase):
|
|||||||
except ValueError as exc:
|
except ValueError as exc:
|
||||||
errors = exc.message.split('\n')
|
errors = exc.message.split('\n')
|
||||||
|
|
||||||
# This must be imported here to avoid circular deps problems.
|
if not Modulemd:
|
||||||
from pungi.phases.pkgset.sources import source_koji
|
|
||||||
if not source_koji.WITH_MODULES:
|
|
||||||
# Modules are not supported, check if we need them
|
# Modules are not supported, check if we need them
|
||||||
for variant in self.compose.variants.values():
|
for variant in self.compose.variants.values():
|
||||||
if variant.modules:
|
if variant.modules:
|
||||||
|
@ -22,16 +22,7 @@ Get a package list based on modulemd metadata loaded in pkgset phase.
|
|||||||
import pungi.arch
|
import pungi.arch
|
||||||
import pungi.phases.gather.source
|
import pungi.phases.gather.source
|
||||||
import kobo.rpmlib
|
import kobo.rpmlib
|
||||||
|
from pungi import Modulemd
|
||||||
|
|
||||||
try:
|
|
||||||
from pdc_client import PDCClient
|
|
||||||
import gi
|
|
||||||
gi.require_version('Modulemd', '1.0') # noqa
|
|
||||||
from gi.repository import Modulemd
|
|
||||||
WITH_MODULES = True
|
|
||||||
except:
|
|
||||||
WITH_MODULES = False
|
|
||||||
|
|
||||||
|
|
||||||
class GatherSourceModule(pungi.phases.gather.source.GatherSourceBase):
|
class GatherSourceModule(pungi.phases.gather.source.GatherSourceBase):
|
||||||
@ -52,11 +43,10 @@ class GatherSourceModule(pungi.phases.gather.source.GatherSourceBase):
|
|||||||
return packages, groups
|
return packages, groups
|
||||||
|
|
||||||
# Check if we even support modules in Pungi.
|
# Check if we even support modules in Pungi.
|
||||||
if not WITH_MODULES:
|
if not Modulemd:
|
||||||
log.write(
|
log.write(
|
||||||
"pdc_client module, pygobject module or libmodulemd "
|
"pygobject module or libmodulemd library is not installed, "
|
||||||
"library is not installed, support for modules is "
|
"support for modules is disabled\n")
|
||||||
"disabled\n")
|
|
||||||
return packages, groups
|
return packages, groups
|
||||||
|
|
||||||
# TODO: Enable multilib here and handle "multilib" field in the
|
# TODO: Enable multilib here and handle "multilib" field in the
|
||||||
|
@ -25,27 +25,23 @@ from pungi.wrappers.comps import CompsWrapper
|
|||||||
import pungi.phases.pkgset.pkgsets
|
import pungi.phases.pkgset.pkgsets
|
||||||
from pungi.arch import get_valid_arches
|
from pungi.arch import get_valid_arches
|
||||||
from pungi.util import is_arch_multilib, retry
|
from pungi.util import is_arch_multilib, retry
|
||||||
|
from pungi import Modulemd
|
||||||
|
|
||||||
from pungi.phases.pkgset.common import create_arch_repos, create_global_repo, populate_arch_pkgsets
|
from pungi.phases.pkgset.common import create_arch_repos, create_global_repo, populate_arch_pkgsets
|
||||||
from pungi.phases.gather import get_packages_to_gather
|
from pungi.phases.gather import get_packages_to_gather
|
||||||
|
|
||||||
|
|
||||||
import pungi.phases.pkgset.source
|
import pungi.phases.pkgset.source
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from pdc_client import PDCClient
|
from pdc_client import PDCClient
|
||||||
import gi
|
WITH_PDC = True
|
||||||
gi.require_version('Modulemd', '1.0') # noqa
|
|
||||||
from gi.repository import Modulemd
|
|
||||||
WITH_MODULES = True
|
|
||||||
except:
|
except:
|
||||||
WITH_MODULES = False
|
WITH_PDC = False
|
||||||
|
|
||||||
|
|
||||||
def get_pdc_client_session(compose):
|
def get_pdc_client_session(compose):
|
||||||
if not WITH_MODULES:
|
if not WITH_PDC:
|
||||||
compose.log_warning("pdc_client module, pygobject module or "
|
compose.log_warning("pdc_client module is not installed, "
|
||||||
"libmodulemd library is not installed, "
|
|
||||||
"support for modules is disabled")
|
"support for modules is disabled")
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
@ -241,6 +237,12 @@ def populate_global_pkgset(compose, koji_wrapper, path_prefix, event_id):
|
|||||||
# to compose_tags list.
|
# to compose_tags list.
|
||||||
if session:
|
if session:
|
||||||
for module in variant.get_modules():
|
for module in variant.get_modules():
|
||||||
|
if not Modulemd:
|
||||||
|
raise ValueError(
|
||||||
|
"pygobject module or libmodulemd library is not installed, "
|
||||||
|
"support for modules is disabled, but compose contains "
|
||||||
|
"modules.")
|
||||||
|
|
||||||
pdc_module = get_module(compose, session, module["name"])
|
pdc_module = get_module(compose, session, module["name"])
|
||||||
pdc_modules.append(pdc_module)
|
pdc_modules.append(pdc_module)
|
||||||
mmd = Modulemd.Module.new_from_string(pdc_module["modulemd"])
|
mmd = Modulemd.Module.new_from_string(pdc_module["modulemd"])
|
||||||
|
@ -14,16 +14,8 @@ import six
|
|||||||
from kobo.rpmlib import parse_nvr
|
from kobo.rpmlib import parse_nvr
|
||||||
|
|
||||||
from pungi.util import get_arch_variant_data
|
from pungi.util import get_arch_variant_data
|
||||||
from pungi import paths, checks
|
from pungi import paths, checks, Modulemd
|
||||||
|
|
||||||
try:
|
|
||||||
import gi # noqa
|
|
||||||
gi.require_version('Modulemd', '1.0') # noqa
|
|
||||||
from gi.repository import Modulemd # noqa
|
|
||||||
import pdc_client # noqa
|
|
||||||
HAS_MODULE_SUPPORT = True
|
|
||||||
except ImportError:
|
|
||||||
HAS_MODULE_SUPPORT = False
|
|
||||||
|
|
||||||
class PungiTestCase(unittest.TestCase):
|
class PungiTestCase(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -61,7 +53,8 @@ class MockVariant(mock.Mock):
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
def add_fake_module(self, nsvc, rpm_nvrs=None):
|
def add_fake_module(self, nsvc, rpm_nvrs=None):
|
||||||
if not HAS_MODULE_SUPPORT:
|
if not Modulemd:
|
||||||
|
# No support for modules
|
||||||
return
|
return
|
||||||
name, stream, version, context = nsvc.split(":")
|
name, stream, version, context = nsvc.split(":")
|
||||||
mmd = Modulemd.Module()
|
mmd = Modulemd.Module()
|
||||||
|
@ -18,15 +18,7 @@ from pungi.phases.createrepo import (CreaterepoPhase,
|
|||||||
create_variant_repo,
|
create_variant_repo,
|
||||||
get_productids_from_scm)
|
get_productids_from_scm)
|
||||||
from tests.helpers import DummyCompose, PungiTestCase, copy_fixture, touch
|
from tests.helpers import DummyCompose, PungiTestCase, copy_fixture, touch
|
||||||
|
from pungi import Modulemd
|
||||||
try:
|
|
||||||
import gi # noqa
|
|
||||||
gi.require_version('Modulemd', '1.0') # noqa
|
|
||||||
from gi.repository import Modulemd # noqa
|
|
||||||
import pdc_client # noqa
|
|
||||||
HAS_MODULE_SUPPORT = True
|
|
||||||
except ImportError:
|
|
||||||
HAS_MODULE_SUPPORT = False
|
|
||||||
|
|
||||||
|
|
||||||
class TestCreaterepoPhase(PungiTestCase):
|
class TestCreaterepoPhase(PungiTestCase):
|
||||||
@ -716,13 +708,11 @@ class TestCreateVariantRepo(PungiTestCase):
|
|||||||
with open(list_file) as f:
|
with open(list_file) as f:
|
||||||
self.assertEqual(f.read(), 'Packages/b/bash-4.3.30-2.fc21.src.rpm\n')
|
self.assertEqual(f.read(), 'Packages/b/bash-4.3.30-2.fc21.src.rpm\n')
|
||||||
|
|
||||||
|
@unittest.skipUnless(Modulemd is not None, 'Skipped test, no module support.')
|
||||||
@mock.patch('pungi.phases.createrepo.run')
|
@mock.patch('pungi.phases.createrepo.run')
|
||||||
@mock.patch('pungi.phases.createrepo.CreaterepoWrapper')
|
@mock.patch('pungi.phases.createrepo.CreaterepoWrapper')
|
||||||
def test_variant_repo_modules_artifacts_not_in_compose(
|
def test_variant_repo_modules_artifacts_not_in_compose(
|
||||||
self, CreaterepoWrapperCls, run):
|
self, CreaterepoWrapperCls, run):
|
||||||
if not HAS_MODULE_SUPPORT:
|
|
||||||
self.skipTest("Skipped test, no module support.")
|
|
||||||
|
|
||||||
compose = DummyCompose(self.topdir, {
|
compose = DummyCompose(self.topdir, {
|
||||||
'createrepo_checksum': 'sha256',
|
'createrepo_checksum': 'sha256',
|
||||||
})
|
})
|
||||||
@ -759,13 +749,11 @@ class TestCreateVariantRepo(PungiTestCase):
|
|||||||
repo.get_modifyrepo_cmd.mock_calls,
|
repo.get_modifyrepo_cmd.mock_calls,
|
||||||
[mock.call(repodata_dir, ANY, compress_type='gz', mdtype='modules')])
|
[mock.call(repodata_dir, ANY, compress_type='gz', mdtype='modules')])
|
||||||
|
|
||||||
|
@unittest.skipUnless(Modulemd is not None, 'Skipped test, no module support.')
|
||||||
@mock.patch('pungi.phases.createrepo.run')
|
@mock.patch('pungi.phases.createrepo.run')
|
||||||
@mock.patch('pungi.phases.createrepo.CreaterepoWrapper')
|
@mock.patch('pungi.phases.createrepo.CreaterepoWrapper')
|
||||||
def test_variant_repo_modules_artifacts(
|
def test_variant_repo_modules_artifacts(
|
||||||
self, CreaterepoWrapperCls, run):
|
self, CreaterepoWrapperCls, run):
|
||||||
if not HAS_MODULE_SUPPORT:
|
|
||||||
self.skipTest("Skipped test, no module support.")
|
|
||||||
|
|
||||||
compose = DummyCompose(self.topdir, {
|
compose = DummyCompose(self.topdir, {
|
||||||
'createrepo_checksum': 'sha256',
|
'createrepo_checksum': 'sha256',
|
||||||
})
|
})
|
||||||
|
@ -5,22 +5,14 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
try:
|
|
||||||
import gi # noqa
|
|
||||||
gi.require_version('Modulemd', '1.0') # noqa
|
|
||||||
from gi.repository import Modulemd # noqa
|
|
||||||
import pdc_client # noqa
|
|
||||||
HAS_MODULE_SUPPORT = True
|
|
||||||
except ImportError:
|
|
||||||
HAS_MODULE_SUPPORT = False
|
|
||||||
|
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
||||||
|
|
||||||
from pungi.phases.gather.sources.source_module import GatherSourceModule
|
from pungi.phases.gather.sources.source_module import GatherSourceModule
|
||||||
from tests import helpers
|
from tests import helpers
|
||||||
|
from pungi import Modulemd
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(HAS_MODULE_SUPPORT, 'Skipped test, no module support.')
|
@unittest.skipUnless(Modulemd is not None, 'Skipped test, no module support.')
|
||||||
class TestGatherSourceModule(helpers.PungiTestCase):
|
class TestGatherSourceModule(helpers.PungiTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestGatherSourceModule, self).setUp()
|
super(TestGatherSourceModule, self).setUp()
|
||||||
|
@ -10,17 +10,9 @@ import re
|
|||||||
|
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
||||||
|
|
||||||
try:
|
|
||||||
import gi # noqa
|
|
||||||
gi.require_version('Modulemd', '1.0') # noqa
|
|
||||||
from gi.repository import Modulemd # noqa
|
|
||||||
import pdc_client # noqa
|
|
||||||
HAS_MODULE_SUPPORT = True
|
|
||||||
except ImportError:
|
|
||||||
HAS_MODULE_SUPPORT = False
|
|
||||||
|
|
||||||
from pungi.phases.pkgset.sources import source_koji
|
from pungi.phases.pkgset.sources import source_koji
|
||||||
from tests import helpers
|
from tests import helpers
|
||||||
|
from pungi import Modulemd
|
||||||
|
|
||||||
EVENT_INFO = {'id': 15681980, 'ts': 1460956382.81936}
|
EVENT_INFO = {'id': 15681980, 'ts': 1460956382.81936}
|
||||||
TAG_INFO = {
|
TAG_INFO = {
|
||||||
@ -127,7 +119,7 @@ class TestPopulateGlobalPkgset(helpers.PungiTestCase):
|
|||||||
with open(self.pkgset_path) as f:
|
with open(self.pkgset_path) as f:
|
||||||
self.assertEqual(f.read(), 'DATA')
|
self.assertEqual(f.read(), 'DATA')
|
||||||
|
|
||||||
@unittest.skipUnless(HAS_MODULE_SUPPORT, 'Modulemd/pdc_client are not available') # noqa
|
@unittest.skipUnless(Modulemd is not None, 'Modulemd not available') # noqa
|
||||||
@mock.patch('six.moves.cPickle.dumps')
|
@mock.patch('six.moves.cPickle.dumps')
|
||||||
@mock.patch('pungi.phases.pkgset.pkgsets.KojiPackageSet')
|
@mock.patch('pungi.phases.pkgset.pkgsets.KojiPackageSet')
|
||||||
@mock.patch('pungi.phases.pkgset.sources.source_koji.get_module')
|
@mock.patch('pungi.phases.pkgset.sources.source_koji.get_module')
|
||||||
|
Loading…
Reference in New Issue
Block a user