예제 #1
0
def generate_py_from_ipynb(ipynb_path, output_dir="."):
    if not ipynb_path.endswith(".ipynb"):
        logger.error("Did not expect file extension. Expected .ipynb, got %s",
                     os.path.splitext(ipynb_path)[1])
        return None
    mkdir_p(output_dir)
    filename_no_extension = os.path.basename(os.path.splitext(ipynb_path)[0])
    output_path = os.path.join(output_dir, filename_no_extension + ".py")
    ipynb = jupytext.read(ipynb_path)
    jupytext.write(ipynb, output_path)
    logger.info("Successfully converted %s -> %s", ipynb_path, output_path)
    return output_path
예제 #2
0
def _get_output_path_hex(notebooker_disable_git, py_template_dir) -> str:
    if py_template_dir and not notebooker_disable_git:
        latest_sha = None
        try:
            git_repo = git.repo.Repo(py_template_dir)
            if _git_has_changes(git_repo):
                logger.info("Pulling latest notebook templates from git.")
                _git_pull_latest(git_repo)
                logger.info("Git pull done.")
            latest_sha = git_repo.commit("HEAD").hexsha
        except Exception as e:
            logger.exception(e)
        return latest_sha or "OLD"
    else:
        return str(uuid.uuid4())
예제 #3
0
def _get_output_path_hex() -> str:
    if python_template_dir() and not NOTEBOOKER_DISABLE_GIT:
        logger.info("Pulling latest notebook templates from git.")
        try:
            latest_sha = _git_pull_templates()
            if get_cache("latest_sha") != latest_sha:
                logger.info("Change detected in notebook template master!")
                set_cache("latest_sha", latest_sha)
            logger.info("Git pull done.")
        except Exception as e:
            logger.exception(e)
        return get_cache("latest_sha") or "OLD"
    else:
        return str(uuid.uuid4())