Example #1
0
def main():
    logging.basicConfig(level=logging.INFO)

    if "GAMMAPY_DATA" not in os.environ:
        log.info("GAMMAPY_DATA environment variable not set.")
        log.info("Running notebook tests requires this environment variable.")
        log.info("Exiting now.")
        sys.exit()

    passed = True

    # setup
    path_temp = Path("temp")
    path_temp.mkdir()

    try:
        for nb_path in get_notebooks_paths():
            path_dest = path_temp / nb_path.name
            shutil.copyfile(nb_path, path_dest)
            if not notebook_run(path_dest):
                passed = False
    finally:
        # tear down
        shutil.rmtree(path_temp, ignore_errors=True)

    if not passed:
        sys.exit("Some tests failed. Existing now.")
Example #2
0
def cli_jupyter_tar(out):
    """Create a tar file with the notebooks in docs."""

    tar_name = Path(out)
    with tarfile.open(tar_name, "w:") as tar:
        for name in get_notebooks_paths():
            tar.add(name, arcname=Path(name).name)
        for img in get_images_paths():
            tar.add(name, arcname=Path("images") / Path(img).name)
    log.info(f"{tar_name} file has been created.")
Example #3
0
def cli_jupyter_tar(out):
    """Create a tar file with the notebooks in docs."""

    tar_name = Path(out)
    with tarfile.open(tar_name, "w:") as tar:
        for name in get_notebooks_paths():
            path_tail = str(name).split(str(PATH_DOCS.resolve()))[1]
            tar.add(name, arcname=Path(path_tail))
        for img in get_images_paths():
            tar.add(img, arcname=Path("tutorials/images") / Path(img).name)
    log.info(f"{tar_name} file has been created.")
def build_notebooks(args):
    if "GAMMAPY_DATA" not in os.environ:
        log.info("GAMMAPY_DATA environment variable not set.")
        log.info("Running notebook tests requires this environment variable.")
        log.info("Exiting now.")
        sys.exit(1)

    PATH_NBS.mkdir(parents=True, exist_ok=True)
    notebooks = list(get_notebooks_paths())

    if args.src and Path(args.src).resolve() in notebooks:
        write_notebook(Path(args.src).resolve())
        return

    log.info('Found %d notebooks', len(notebooks))
    with Pool(args.n_jobs) as pool:
        pool.map(write_notebook, notebooks)
Example #5
0
def main():

    parser = argparse.ArgumentParser()
    parser.add_argument("--src", help="Tutorial notebook to process")
    args = parser.parse_args()

    logging.basicConfig(level=logging.INFO)
    log.info("Building API links in .ipynb and Sphinx formatted notebooks.")
    log.info("Bring back stripped and clean notebooks.")

    for nb_path in get_notebooks_paths():
        if args.src and Path(args.src).resolve() != nb_path:
            continue
        downloadable_path = PATH_NBS / nb_path.absolute().name
        shutil.copyfile(downloadable_path, nb_path)
        make_api_links(downloadable_path, file_type="ipynb")
        html_path = str(nb_path).replace(f"/{SOURCE_DIR}", f"/{PATH_DOC}")
        html_path = html_path.replace("ipynb", "html")
        make_api_links(Path(html_path), file_type="html")
def build_notebooks(args):
    if "GAMMAPY_DATA" not in os.environ:
        log.info("GAMMAPY_DATA environment variable not set.")
        log.info("Running notebook tests requires this environment variable.")
        log.info("Exiting now.")
        sys.exit()

    PATH_NBS.mkdir(parents=True, exist_ok=True)

    for nb_path in get_notebooks_paths():
        if args.src and Path(args.src).resolve() != nb_path:
            continue
        skip = False
        copy_clean_notebook(nb_path)
        rawnb = nbformat.read(nb_path, as_version=nbformat.NO_CONVERT)
        if "gammapy" in rawnb.metadata and "skip_run" in rawnb.metadata[
                "gammapy"]:
            skip = rawnb.metadata["gammapy"]["skip_run"]
        if not skip:
            notebook_run(nb_path)
            add_box(nb_path)
Example #7
0
def main():
    args = parser.parse_args()

    logging.basicConfig(level=logging.INFO)

    if "GAMMAPY_DATA" not in os.environ:
        log.info("GAMMAPY_DATA environment variable not set.")
        log.info("Running notebook tests requires this environment variable.")
        log.info("Exiting now.")
        sys.exit(1)

    notebooks = list(get_notebooks_paths())
    log.info('Found %d notebooks', len(notebooks))

    with tempfile.TemporaryDirectory(suffix='_gammapy_nb_test') as tmp_dir:
        tmp_dir = Path(tmp_dir)

        with Pool(args.n_jobs) as pool:
            run_nb = partial(run_notebook, tmp_dir=tmp_dir)
            passed = pool.map(run_nb, notebooks)

    if not all(passed):
        sys.exit("Some tests failed. Existing now.")
Example #8
0
def test_get_notebooks_paths():
    assert any("maps.ipynb" in str(p) for p in get_notebooks_paths())