From bb4d52a290b43a1f0aa0930a718a15e52bc55d40 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Tue, 12 Jul 2022 08:16:03 -0400 Subject: [PATCH] Move release note in wrong location and add script to block this (#8320) * Move release note in wrong location and add script to block this In #8201 I added a release note as part of the PR which documented the change in behavior. However, I accidentally committed this file in the wrong location (by running reno new outside of the repo root). This meant the file was never actually included in the release notes for the 0.21.0 release. This commit corrects this oversight and moves it back to the proper location. However, since this isn't my first time making this mistake and I can expect that others will make it too in the future. This commit also adds a new script to detect this and raise an error when release notes are present outside of the proper location. By running this as part of lint jobs we'll block this mistake from happening again. * Fix lint Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- .azure/lint-linux.yml | 1 + Makefile | 1 + ...-hard-time-limit-vf2-be83830ecc71f72c.yaml | 0 tools/find_stray_release_notes.py | 58 +++++++++++++++++++ tox.ini | 2 + 5 files changed, 62 insertions(+) rename {qiskit/transpiler/preset_passmanagers/releasenotes/notes => releasenotes/notes/0.21}/remove-hard-time-limit-vf2-be83830ecc71f72c.yaml (100%) create mode 100755 tools/find_stray_release_notes.py diff --git a/.azure/lint-linux.yml b/.azure/lint-linux.yml index a3b2d29da22c..830acdc1821e 100644 --- a/.azure/lint-linux.yml +++ b/.azure/lint-linux.yml @@ -51,5 +51,6 @@ jobs: cargo clippy -- -D warnings tools/verify_headers.py qiskit test python tools/find_optional_imports.py + tools/find_stray_release_notes.py reno lint displayName: 'Lint' diff --git a/Makefile b/Makefile index 14f58407b05e..e592a759231b 100644 --- a/Makefile +++ b/Makefile @@ -51,6 +51,7 @@ lint: tools/verify_headers.py qiskit test tools examples pylint -rn --disable='invalid-name, missing-module-docstring, redefined-outer-name' examples/python/*.py tools/find_optional_imports.py + tools/find_stray_release_notes.py # Only pylint on files that have changed from origin/main. Also parallelize (disables cyclic-import check) lint-incr: diff --git a/qiskit/transpiler/preset_passmanagers/releasenotes/notes/remove-hard-time-limit-vf2-be83830ecc71f72c.yaml b/releasenotes/notes/0.21/remove-hard-time-limit-vf2-be83830ecc71f72c.yaml similarity index 100% rename from qiskit/transpiler/preset_passmanagers/releasenotes/notes/remove-hard-time-limit-vf2-be83830ecc71f72c.yaml rename to releasenotes/notes/0.21/remove-hard-time-limit-vf2-be83830ecc71f72c.yaml diff --git a/tools/find_stray_release_notes.py b/tools/find_stray_release_notes.py new file mode 100755 index 000000000000..7e04f5ecc320 --- /dev/null +++ b/tools/find_stray_release_notes.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022 +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +"""Utility script to verify qiskit copyright file headers""" + +import argparse +import multiprocessing +import subprocess +import sys +import re + +# release notes regex +reno = re.compile(r"releasenotes\/notes") +# exact release note regex +exact_reno = re.compile(r"^releasenotes\/notes") + + +def discover_files(): + """Find all .py, .pyx, .pxd files in a list of trees""" + cmd = ["git", "ls-tree", "-r", "--name-only", "HEAD"] + res = subprocess.run(cmd, capture_output=True, check=True, encoding="UTF8") + files = res.stdout.split("\n") + return files + + +def validate_path(file_path): + """Validate a path in the git tree.""" + if reno.search(file_path) and not exact_reno.search(file_path): + return file_path + return None + + +def _main(): + parser = argparse.ArgumentParser(description="Find any stray release notes.") + _args = parser.parse_args() + files = discover_files() + with multiprocessing.Pool() as pool: + res = pool.map(validate_path, files) + failed_files = [x for x in res if x is not None] + if len(failed_files) > 0: + for failed_file in failed_files: + sys.stderr.write("%s is not in the correct location.\n" % failed_file) + sys.exit(1) + sys.exit(0) + + +if __name__ == "__main__": + _main() diff --git a/tox.ini b/tox.ini index ee04a83bc77e..f457cab047e0 100644 --- a/tox.ini +++ b/tox.ini @@ -32,6 +32,7 @@ commands = # pylint -rn --disable='invalid-name,missing-module-docstring,redefined-outer-name' examples/python/*.py {toxinidir}/tools/verify_headers.py qiskit test tools examples {toxinidir}/tools/find_optional_imports.py + {toxinidir}/tools/find_stray_release_notes.py reno lint [testenv:lint-incr] @@ -45,6 +46,7 @@ commands = {toxinidir}/tools/pylint_incr.py -rn -j4 -sn --disable='invalid-name,missing-module-docstring,redefined-outer-name' --paths :(glob,top)examples/python/*.py {toxinidir}/tools/verify_headers.py qiskit test tools examples {toxinidir}/tools/find_optional_imports.py + {toxinidir}/tools/find_stray_release_notes.py reno lint [testenv:black]