-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate repo-specific functionality from nb-tester (#2425)
Splits out part of #2405 This PR pulls some of our CI functionality out of the nb-tester package and into separate scripts.
- Loading branch information
1 parent
5aaf222
commit 1005805
Showing
7 changed files
with
128 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# This code is a Qiskit project. | ||
# | ||
# (C) Copyright IBM 2024. | ||
# | ||
# This code is licensed under the Apache License, Version 2.0. You may | ||
# obtain a copy of this license in the LICENSE 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. | ||
|
||
""" | ||
Check all notebooks are listed in `scripts/config/notebook-testing.toml` so | ||
they don't slip through our CI tests. | ||
""" | ||
|
||
from pathlib import Path | ||
import tomllib | ||
import sys | ||
|
||
config_path = Path("scripts/config/notebook-testing.toml") | ||
config = tomllib.loads(config_path.read_text()) | ||
|
||
categorized_notebooks = set() | ||
for group in config.values(): | ||
for path in group: | ||
categorized_notebooks.add(Path(path)) | ||
|
||
uncategorized = [ | ||
path | ||
for path in Path(".").glob("[!.]*/**/*.ipynb") | ||
if not path.match("**/.ipynb_checkpoints/**") and path not in categorized_notebooks | ||
] | ||
|
||
if uncategorized: | ||
print( | ||
f"\nThe following notebooks are not classified in {config_path}:\n " | ||
+ "\n ".join(map(str, uncategorized)) | ||
+ "\nAdd them to the appropriate group so we know how to test them.\n" | ||
) | ||
sys.exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# This code is a Qiskit project. | ||
# | ||
# (C) Copyright IBM 2024. | ||
# | ||
# This code is licensed under the Apache License, Version 2.0. You may | ||
# obtain a copy of this license in the LICENSE 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. | ||
|
||
""" | ||
Run the notebook tester on changed notebooks and display a helpful message if | ||
can't test due to being on a fork. | ||
""" | ||
|
||
FORK_ERROR_MESSAGE = """\ | ||
We can't run this test on pull requests from forks. | ||
If you have write access to Qiskit/documentation, push to a new branch there | ||
and make your pull request from that branch instead. | ||
If you don't have write access, you must test out the notebook locally using | ||
the instructions in https://github.com/Qiskit/documentation#execute-notebooks. | ||
When this PR is approved, a maintainer will merge it to a new branch in | ||
Qiskit/documentation, then make a PR from that branch into main so it can pass | ||
CI. | ||
""" | ||
|
||
import os | ||
import subprocess | ||
from pathlib import Path | ||
|
||
all_changed_files = Path(".github/outputs/all_changed_files.txt").read_text().split("\n") | ||
|
||
changed_notebooks = [ | ||
path for path in all_changed_files | ||
if path.startswith("docs/") | ||
] | ||
config_changed = any(path.startswith("scripts/") for path in all_changed_files) | ||
|
||
args = ["tox", "--", "--write"] | ||
if changed_notebooks and not config_changed: | ||
args.extend(changed_notebooks.split("\n")) | ||
|
||
is_fork = os.environ["PR_REPOSITORY"] != os.environ["GITHUB_REPOSITORY"] | ||
|
||
try: | ||
subprocess.run(args, check=True) | ||
except Exception as err: | ||
is_fork = os.environ["PR_REPOSITORY"] != os.environ["GITHUB_REPOSITORY"] | ||
if is_fork: | ||
raise SystemExit(FORK_ERROR_MESSAGE) from err | ||
raise err |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.