Skip to content

Commit

Permalink
👌 IMPROVE: Allow notebook suffixes with .s (#328)
Browse files Browse the repository at this point in the history
Use regex to identify suffixes, rather than splitting at "right-most" dot.
  • Loading branch information
juhuebner authored May 14, 2021
1 parent ce5f69c commit e39132e
Showing 1 changed file with 10 additions and 4 deletions.
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 Iterable, List, Optional, Set

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: Iterable[str] = (".ipynb",)
) -> 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

0 comments on commit e39132e

Please sign in to comment.