From 809c9cd9e01f6d37c515533d79741727c59bd608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20H=C3=BCbner?= Date: Wed, 12 May 2021 19:17:11 +0200 Subject: [PATCH 1/3] added suffix testing by regex --- myst_nb/execution.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/myst_nb/execution.py b/myst_nb/execution.py index 93232234..ad66fdfc 100644 --- a/myst_nb/execution.py +++ b/myst_nb/execution.py @@ -10,6 +10,7 @@ """ import os +import re import tempfile from datetime import datetime from pathlib import Path @@ -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 From 416c84da5a25fc730820f21be0385f90e3703902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20H=C3=BCbner?= Date: Wed, 12 May 2021 19:26:33 +0200 Subject: [PATCH 2/3] pass tuple as args in nb_has_all_output --- myst_nb/execution.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/myst_nb/execution.py b/myst_nb/execution.py index ad66fdfc..53db4c6c 100644 --- a/myst_nb/execution.py +++ b/myst_nb/execution.py @@ -14,7 +14,7 @@ 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 @@ -327,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",) +) -> bool: """Determine if the path contains a notebook with at least one output.""" has_outputs = False ext = os.path.splitext(source_path)[1] From f17d12c0889b64f4ecaca79aeb694770b32660b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20H=C3=BCbner?= Date: Wed, 12 May 2021 21:18:19 +0200 Subject: [PATCH 3/3] repl. Tuple by Iterable --- myst_nb/execution.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/myst_nb/execution.py b/myst_nb/execution.py index 53db4c6c..ffbcb5d6 100644 --- a/myst_nb/execution.py +++ b/myst_nb/execution.py @@ -14,7 +14,7 @@ import tempfile from datetime import datetime from pathlib import Path -from typing import List, Optional, Set, Tuple +from typing import Iterable, List, Optional, Set import nbformat as nbf from jupyter_cache import get_cache @@ -328,7 +328,7 @@ def _converter(path): def nb_has_all_output( - source_path: str, nb_extensions: Tuple[str] = (".ipynb",) + source_path: str, nb_extensions: Iterable[str] = (".ipynb",) ) -> bool: """Determine if the path contains a notebook with at least one output.""" has_outputs = False