From 22bda315504903a87c15b4abf14f45c6d4d3b09b Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Apr 22 2019 05:52:29 +0000 Subject: Some fixes to funtion requires_included * Fix argument description for requires_included * Remove comment for the possible negative stream in module metadata. Each module build got from MBS is the result of module expansion stream (aka MSE) from original module build submitted to MBS. Ursa-Major just works with such kind of module builds rather than the original module build with original modulemd created in module dist-git repository. Hence, it is ok to remove the comment from function requires_included. * Simplify the code a bit. Signed-off-by: Chenxiong Qi --- diff --git a/ursa_major/utils.py b/ursa_major/utils.py index 9406c0d..d7c8a98 100644 --- a/ursa_major/utils.py +++ b/ursa_major/utils.py @@ -91,9 +91,10 @@ def load_mmd(yaml, is_file=False): def requires_included(mmd_requires, config_requires): """Test if requires defined in config is included in module metadata - :param dict mmd_requires: a mapping representing either buildrequires or - requires, which is generally converted from module metadata. For - example, ``{"platform": "f29"}``. + :param mmd_requires: a mapping representing either buildrequires or + requires, which is returned from function ``peek_requires`` and + ``peek_buildrequires``. + :type mmd_requires: dict[str, Modulemd.SimpleSet] :param dict config_requires: a mapping representing either buildrequires or requires defined in config file. This is what to check if it is included in ``mmd_requires``. @@ -102,21 +103,19 @@ def requires_included(mmd_requires, config_requires): :rtype: bool """ for req_name, req_streams in config_requires.items(): - if req_name not in mmd_requires.keys(): + if req_name not in mmd_requires: return False - if not(isinstance(req_streams, list)): + if not isinstance(req_streams, list): req_streams = [req_streams] - streams = mmd_requires[req_name].dup() - neg_reqs = [s[1:] for s in req_streams if s.startswith('-')] - pos_reqs = [s for s in req_streams if not s.startswith('-')] + neg_reqs = set(s[1:] for s in req_streams if s.startswith('-')) + pos_reqs = set(s for s in req_streams if not s.startswith('-')) - # TODO: can mmd contains negative requires like - # {'platform': ['-f26']} ? - if set(streams) & set(neg_reqs): + streams = set(mmd_requires[req_name].dup()) + if streams & neg_reqs: return False - if pos_reqs and not (set(streams) & set(pos_reqs)): + if pos_reqs and not (streams & pos_reqs): return False return True