From f813e3a34748b67e18a951214cc0bcce044b0628 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Tue, 3 Apr 2018 09:54:45 -0400 Subject: [PATCH] avoid testing exact matches twice Without this patch we test the attributes that have to match exactly two separate times, once to report which do not match and again to see if they all match before testing the exclusions. With this patch we only test the attributes one time and if we fail to match one we do not test them again. Change-Id: Ida4fe5d14acfbd5f72a722037270df7c88a760d2 Signed-off-by: Doug Hellmann --- openstack_requirements/check.py | 39 +++++++++++++++++---------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/openstack_requirements/check.py b/openstack_requirements/check.py index c17b7ba85d..c5d6c29e73 100644 --- a/openstack_requirements/check.py +++ b/openstack_requirements/check.py @@ -87,31 +87,32 @@ def _is_requirement_in_global_reqs(req, global_reqs): req_exclusions = _get_exclusions(req) for req2 in global_reqs: + matching = True for aname in ['package', 'location', 'markers', 'comment']: rval = getattr(req, aname) r2val = getattr(req2, aname) if rval != r2val: print('{} {!r}: {!r} does not match {!r}'.format( - req.package, aname, rval, r2val)) + req, aname, rval, r2val)) + matching = False + break + if not matching: + continue - if (req.package == req2.package and - req.location == req2.location and - req.markers == req2.markers and - req.comment == req2.comment): - # This matches the right package and other properties, so - # ensure that any exclusions are a subset of the global - # set. - global_exclusions = _get_exclusions(req2) - if req_exclusions.issubset(global_exclusions): - return True - else: - print( - "Requirement for package {} " - "has an exclusion not found in the " - "global list: {} vs. {}".format( - req.package, req_exclusions, global_exclusions) - ) - return False + # This matches the right package and other properties, so + # ensure that any exclusions are a subset of the global + # set. + global_exclusions = _get_exclusions(req2) + if req_exclusions.issubset(global_exclusions): + return True + else: + print( + "Requirement for package {} " + "has an exclusion not found in the " + "global list: {} vs. {}".format( + req.package, req_exclusions, global_exclusions) + ) + return False return False