From 641098566d0579274c7dc1b27c444fb94edcc6f6 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver <thomas@kluyver.me.uk> Date: Mon, 15 Nov 2021 14:09:28 +0000 Subject: [PATCH] Allow for notebook with no markdown cells --- src/xfel_calibrate/calibrate.py | 6 +++++- src/xfel_calibrate/nb_args.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/xfel_calibrate/calibrate.py b/src/xfel_calibrate/calibrate.py index 3b67a0e62..26e45f0fe 100755 --- a/src/xfel_calibrate/calibrate.py +++ b/src/xfel_calibrate/calibrate.py @@ -57,6 +57,8 @@ def extract_title_author(nb): """ first_md = first_markdown_cell(nb) + if first_md is None: + return None, None source = first_md["source"] title = re.findall(r'#+\s*(.*)\s*#+', source) author = re.findall( @@ -375,7 +377,9 @@ def prepare_job( params = parameter_values(params, cluster_profile=cluster_profile) new_nb = replace_definitions(nb, params, execute=False, lang='python') if not show_title: - first_markdown_cell(new_nb).source = '' + title_cell = first_markdown_cell(new_nb) + if title_cell is not None: + title_cell.source = '' set_figure_format(new_nb, args["vector_figs"]) new_name = f"{nb_path.stem}__{cparm}__{suffix}.ipynb" diff --git a/src/xfel_calibrate/nb_args.py b/src/xfel_calibrate/nb_args.py index 3dc5280b9..511223ed6 100644 --- a/src/xfel_calibrate/nb_args.py +++ b/src/xfel_calibrate/nb_args.py @@ -282,7 +282,7 @@ def make_epilog(nb, caltype=None): """ msg = "" header_cell = first_markdown_cell(nb) - lines = header_cell.source.split("\n") + lines = header_cell.source.split("\n") if header_cell is not None else [''] if caltype: msg += "{:<15} {}".format(caltype, lines[0]) + "\n" else: -- GitLab