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

[Refactor] Decouple config and execution in nb-tester #2410

Merged
merged 5 commits into from
Dec 3, 2024

Conversation

frankharkins
Copy link
Member

Pre-work for #2405.

This PR refactors nb-tester to decouple the config logic, which decides which notebooks to run and how to patch them, from the notebook execution logic, which runs the notebooks.

The config logic is already the most complicated part of the program. This PR decouples config and execution by moving them to separate files and having them communicate only by a single NotebookJob interface. Each NotebookJob contains a notebook path and instructions on how to run that notebook. This means the config logic can be scoped to creating a list of NotebookJob objects. This also makes the config logic easier to test.

There should be no behaviour changes in this PR.


print(
f"⚠️ Cancelling {len(jobs)} job(s) created after {start_time}.\n"
"Add any notebooks that submit jobs to `notebooks-that-submit-jobs` in "
f"`{config_path}`."
f"`scripts/config/notebook-testing.toml`."
Copy link
Member Author

Choose a reason for hiding this comment

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

Hardcoded for now but will make more general in a follow-up

@frankharkins frankharkins marked this pull request as ready for review December 2, 2024 12:59
Copy link
Collaborator

@arnaucasau arnaucasau left a comment

Choose a reason for hiding this comment

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

Awesome work Frank! I like the communication between scripts using NotebookJob a lot!

Comment on lines -552 to -565
if paths and args.is_fork:
print(
"⛔️ We can't run notebook tests on pull requests from forks becaus of how GitHub Secrets work."
"\n\n"
"If you have write access to Qiskit/documentation, push to a new "
"branch there and make your pull request from that branch instead."
"\n\n"
"If you don't have write access, you should locally test out the notebooks you're modifying "
"by 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.\n",
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wasn't able to find this conditional after the refactor. Do we still use it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good catch. It'd be helpful to keep this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good spot! I plan to move that functionality to our GitHub action because it's very specific to our repo, but it shouldn't have been removed in this PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It used to live there, but we decided to move it to the script in #2062. I'm fine with moving this back to the GH action, so long as it preserves the same prior functionality of not failing when the notebooks couldn't have been tested anyways.

Copy link
Member Author

Choose a reason for hiding this comment

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

I remember that, here's what I had in mind. It is the kind of thing I'd forget so thanks for reminding me.

try:
subprocess.run(args, check=True)
except Exception as err:
if os.environ["PR_REPOSITORY"] != os.environ["GITHUB_REPOSITORY"]:
raise SystemExit(
"We can't run this test on pull requests from forks."
"\n\n"
"If you have write access to Qiskit/documentation, push to a new "
"branch there and make your pull request from that branch instead."
"\n\n"
"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."
) from err
raise err

Copy link
Collaborator

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

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

Thanks!

I've moved this to config to keep the args hidden from the rest of the
program.
@frankharkins frankharkins added this pull request to the merge queue Dec 3, 2024
Merged via the queue into main with commit 103ca11 Dec 3, 2024
3 checks passed
@frankharkins frankharkins deleted the FH/refactor-nb-tester branch December 3, 2024 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants