ray/doc/test_myst_doc.py
Antoni Baum c74886a55e
[CI] Run doc notebooks in CI (#24816)
Currently, we are not running doc notebooks in CI due to a bazel misconfiguration - we are using `glob` in a top level package in order to get the paths for the notebooks, but those are contained inside subpackages, which glob purposefully ignores. Therefore, the lists of notebooks to run are empty. This PR fixes that by:
* Running the `py_test_run_all_notebooks` macro inside the relevant subpackages
* Editing the `test_myst_doc.py` script to allow for recursive search for the target file, allowing to deal with mismatches between `name` and `data` arguments in `py_test_run_all_notebooks`
* Setting the `allow_empty=False` flag inside `glob` calls in our macros to ensure that this oversight is caught early
* Enabling detection of changes in doc folder for `*.ipynb` and `BUILD` files

This PR also adds a GPU runner for doc tests, allowing one of our examples to pass - and setting the infra for more to come. Finally, a misconfigured path for one set of doc tests is also fixed.
2022-05-17 09:50:42 +01:00

45 lines
1.1 KiB
Python

"""Convert a jupytext-compliant format in to a python script
and execute it with parsed arguments."""
import subprocess
import argparse
import tempfile
import sys
from pathlib import Path
import jupytext
parser = argparse.ArgumentParser(description="Run a jupytext parsable file.")
parser.add_argument(
"--path",
help="path to the jupytext-compatible file",
)
parser.add_argument(
"--find-recursively",
action="store_true",
help="if true, will attempt to find path recursively in cwd",
)
if __name__ == "__main__":
args, remainder = parser.parse_known_args()
path = Path(args.path)
cwd = Path.cwd()
if args.find_recursively and not path.exists():
path = next((p for p in cwd.rglob("*") if str(p).endswith(args.path)), None)
assert path and path.exists()
with open(path, "r") as f:
notebook = jupytext.read(f)
name = ""
with tempfile.NamedTemporaryFile("w", delete=False) as f:
jupytext.write(notebook, f, fmt="py:percent")
name = f.name
remainder.insert(0, name)
remainder.insert(0, sys.executable)
# Run the notebook
subprocess.run(remainder)