diff --git a/tools/stable_backport.py b/tools/stable_backport.py index 017b1330e5eb39e1f786c8077765a44981042c1b..db31b0107bbcb45575a3ce99c0adcf3c04ad0c04 100755 --- a/tools/stable_backport.py +++ b/tools/stable_backport.py @@ -147,6 +147,11 @@ def fixup(self): self.reimport_module(module) +class ManualBackport(Error): + def fixup(self): + self.reimport_module(self.message) + + def replace_all(expr, dest): system(r"""for file in $(git ls-files modules | grep '\.py$'); do @@ -195,6 +200,21 @@ def main(self): dirnames[path.dirname(filename)].append(self.errors[error](filename, linenum, msg)) + with log('Searching manual backports'): + for manual in MANUAL_PORTS: + r = check_output("grep -nEr '^from %s import ' modules" % manual, shell=True).strip().decode('utf-8') + for line in r.split('\n'): + m = re.match(r'([\w\./]+):(\d+):.*', line) + filename = m.group(1) + linenum = m.group(2) + target = dirnames[path.dirname(filename)] + for err in target: + if err.filename == filename and err.linenum == linenum: + # an error was already spot on this line + break + else: + target.append(ManualBackport(filename, linenum, manual)) + for dirname, errors in sorted(dirnames.items()): with log('Fixing up %s errors in %s' % (colored(str(len(errors)), 'magenta'), colored(dirname, 'yellow'))):