From 0fa17bce9c8bb0f940fe946d55607c4258e39852 Mon Sep 17 00:00:00 2001 From: Jeremy Stanley Date: Mon, 8 Aug 2016 15:42:29 +0000 Subject: [PATCH] Only error for duplicate requirements when strict If a project adds a requirements check job while its requirements files are nonconforming, they should be able to fix it by submitting a change which fixes their requirements. If validity checks get performed while reading requirements lists in the gate{name}-requirements job, they need to only trigger failure while parsing the submitted requirements and not on the existing state of requirements before applying a proposed change. Pass the "strict" flag through and wrap the duplicate entries check in a conditional for it, so that we don't block fixes for projects that start out with a duplicate requirement. Change-Id: I16cbea930fd104717e73bd4e012ec77fc4f98494 --- jenkins/scripts/project-requirements-change.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/jenkins/scripts/project-requirements-change.py b/jenkins/scripts/project-requirements-change.py index 378f967949..8b38883689 100755 --- a/jenkins/scripts/project-requirements-change.py +++ b/jenkins/scripts/project-requirements-change.py @@ -53,7 +53,7 @@ class RequirementsList(object): return {k: v for d in self.reqs_by_file.values() for k, v in d.items()} - def extract_reqs(self, content): + def extract_reqs(self, content, strict): reqs = collections.defaultdict(set) parsed = requirement.parse(content) for name, entries in parsed.items(): @@ -63,7 +63,8 @@ class RequirementsList(object): list_reqs = [r for (r, line) in entries] # Strip the comments out before checking if there are duplicates list_reqs_stripped = [r._replace(comment='') for r in list_reqs] - if len(list_reqs_stripped) != len(set(list_reqs_stripped)): + if strict and len(list_reqs_stripped) != len(set( + list_reqs_stripped)): print("Requirements file has duplicate entries " "for package %s : %r." % (name, list_reqs)) self.failed = True @@ -85,11 +86,11 @@ class RequirementsList(object): if strict and not content.endswith('\n'): print("Requirements file %s does not " "end with a newline." % fname) - self.reqs_by_file[fname] = self.extract_reqs(content) + self.reqs_by_file[fname] = self.extract_reqs(content, strict) for name, content in project.extras(self.project).items(): print("Processing .[%(extra)s]" % {'extra': name}) - self.reqs_by_file[name] = self.extract_reqs(content) + self.reqs_by_file[name] = self.extract_reqs(content, strict) def grab_args():