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

Improve file filtering in CI #734

Merged
merged 4 commits into from
Jan 31, 2024
Merged
Changes from 2 commits
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
36 changes: 31 additions & 5 deletions scripts/nb-tester/test-notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from dataclasses import dataclass
from datetime import datetime
from pathlib import Path
from typing import Iterator

import nbclient
import nbconvert
Expand All @@ -35,6 +36,34 @@
]


def filter_paths(paths: list[Path], submit_jobs: bool) -> Iterator[Path]:
"""
Filter out any paths we don't want to run, printing messages.
"""
for path in paths:
if path.suffix != ".ipynb":
print(f"ℹ️ Skipping {path}; file is not `.ipynb` format.")
continue

if any(path.match(glob) for glob in NOTEBOOKS_EXCLUDE):
this_file = Path(__file__).relative_to(Path(".").resolve())
frankharkins marked this conversation as resolved.
Show resolved Hide resolved
print(
f"ℹ️ Skipping {path}; to run it, edit `NOTEBOOKS_EXCLUDE` in {this_file}."
)
continue

if (
any(path.match(glob) for glob in NOTEBOOKS_THAT_SUBMIT_JOBS)
and not submit_jobs
frankharkins marked this conversation as resolved.
Show resolved Hide resolved
):
print(
f"ℹ️ Skipping {path} as it submits jobs; use the --submit-jobs flag to run it."
)
continue

yield path


@dataclass(frozen=True)
class ExecuteOptions:
write: bool
Expand Down Expand Up @@ -214,15 +243,12 @@ def create_argument_parser() -> argparse.ArgumentParser:
args = create_argument_parser().parse_args()

paths = map(Path, args.filenames or find_notebooks(submit_jobs=args.submit_jobs))
if not args.submit_jobs:
paths = [path for path in paths if not any(path.match(glob) for glob in NOTEBOOKS_THAT_SUBMIT_JOBS)]
paths = filter_paths(paths, submit_jobs=args.submit_jobs)
frankharkins marked this conversation as resolved.
Show resolved Hide resolved

# Execute notebooks
start_time = datetime.now()
print("Executing notebooks:")
results = [
execute_notebook(path, args) for path in paths if path.suffix == ".ipynb"
]
results = [execute_notebook(path, args) for path in paths]
print("Checking for trailing jobs...")
results.append(cancel_trailing_jobs(start_time))
if not all(results):
Expand Down
Loading