Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move release note in wrong location and add script to block this #8320

Merged
merged 3 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .azure/lint-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
60 changes: 60 additions & 0 deletions tools/find_stray_release_notes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/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 os
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):
if reno.search(file_path) and not exact_reno.search(file_path):
return file_path
return None


def _main():
default_path = os.path.join(
Copy link
Contributor

@nkanazawa1989 nkanazawa1989 Jul 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How this variable is used?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, good catch. this is sloppy copy and paste from the script I based this on

os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "qiskit"
)
parser = argparse.ArgumentParser(description="Find any stray release notes.")
args = parser.parse_args()
files = discover_files()
with multiprocessing.Pool() as pool:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works in every platform?

Copy link
Member Author

@mtreinish mtreinish Jul 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it will, because I have the if __name__ = "__main__" on the script. Without this windows and macOS > 3.7 would potentially have issues because they default to the spawn method.

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()
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand Down