From ee69ee7b793ffbaeab806dd956a9514860d631a8 Mon Sep 17 00:00:00 2001 From: Denys SAVCHENKO Date: Mon, 2 Dec 2024 14:36:03 +0100 Subject: [PATCH 1/2] Strip hash and space in comments, not just first symbol --- nb2workflow/nbadapter.py | 4 ++-- tests/testfiles/multiline.ipynb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nb2workflow/nbadapter.py b/nb2workflow/nbadapter.py index b9ff2d0..6540a53 100644 --- a/nb2workflow/nbadapter.py +++ b/nb2workflow/nbadapter.py @@ -411,7 +411,7 @@ def _pop_comment_by_line(comment_tokens, l): for i, x in enumerate(comment_tokens): if x.start[0]==l: res = comment_tokens.pop(i) - return res.string[1:] + return res.string.strip(' #') return '' def parse_source_multiline(self, source: str) -> dict[str, list[dict]]: @@ -469,7 +469,7 @@ def parse_source_multiline(self, source: str) -> dict[str, list[dict]]: # now parse full-line comments for comment in comments: - cstring = comment.string[1:] + cstring = comment.strip('# ') result['standalone'].append(cstring) return result diff --git a/tests/testfiles/multiline.ipynb b/tests/testfiles/multiline.ipynb index cca0433..107436d 100644 --- a/tests/testfiles/multiline.ipynb +++ b/tests/testfiles/multiline.ipynb @@ -22,7 +22,7 @@ "\n", "opt: float|None = None\n", "otheropt = 5 # oda:optional\n", - "intfloat = 10 # oda:Float\n", + "intfloat = 10 # # oda:Float\n", "inten: int = 45 # oda:Energy \n", "# NOTE: won't work with dispatcher, because energy is always float there\n", "string_param = '''Foo Bar\n", @@ -62,7 +62,7 @@ }, "language_info": { "name": "python", - "version": "3.10.12" + "version": "3.10.15" } }, "nbformat": 4, From b1dbecee249e0f9490dfa363e0d691388e9a7fdc Mon Sep 17 00:00:00 2001 From: Denys SAVCHENKO Date: Mon, 2 Dec 2024 14:53:05 +0100 Subject: [PATCH 2/2] fix --- nb2workflow/nbadapter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nb2workflow/nbadapter.py b/nb2workflow/nbadapter.py index 6540a53..35f0825 100644 --- a/nb2workflow/nbadapter.py +++ b/nb2workflow/nbadapter.py @@ -469,7 +469,7 @@ def parse_source_multiline(self, source: str) -> dict[str, list[dict]]: # now parse full-line comments for comment in comments: - cstring = comment.strip('# ') + cstring = comment.string.strip('# ') result['standalone'].append(cstring) return result