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

Allows more complex suffixes in notebooks #328

Merged
merged 4 commits into from
May 14, 2021
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
14 changes: 10 additions & 4 deletions myst_nb/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@

"""
import os
import re
import tempfile
from datetime import datetime
from pathlib import Path
from typing import List, Optional, Set
from typing import List, Optional, Set, Tuple

import nbformat as nbf
from jupyter_cache import get_cache
Expand Down Expand Up @@ -225,8 +226,11 @@ def is_valid_exec_file(env: BuildEnvironment, docname: str) -> bool:
doc_path = env.doc2path(docname)
if doc_path in env.nb_excluded_exec_paths:
return False
extension = os.path.splitext(doc_path)[1]
if extension not in env.nb_allowed_exec_suffixes:
matches = tuple(
re.search(re.escape(suffix) + "$", doc_path)
for suffix in env.nb_allowed_exec_suffixes
)
if not any(matches):
return False
return True

Expand Down Expand Up @@ -323,7 +327,9 @@ def _converter(path):
return result


def nb_has_all_output(source_path: str, nb_extensions: List[str] = (".ipynb",)) -> bool:
def nb_has_all_output(
source_path: str, nb_extensions: Tuple[str] = (".ipynb",)
Copy link
Member

Choose a reason for hiding this comment

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

Tuple[str] means a tuple with only one element that is a string. For a variable number use I think Tuple[str,...] or maybe just Iterable[str] would be better

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed. Changed it to Iterable[str] in f17d12c

) -> bool:
"""Determine if the path contains a notebook with at least one output."""
has_outputs = False
ext = os.path.splitext(source_path)[1]
Expand Down