diff --git a/src/xfel_calibrate/calibrate.py b/src/xfel_calibrate/calibrate.py index f93f7e7f55eb22557dff3fc9330f505e2471f10d..7cf729c8e9d88eefa588ace3459bb7b4e15c3117 100755 --- a/src/xfel_calibrate/calibrate.py +++ b/src/xfel_calibrate/calibrate.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import argparse +import ast import inspect import math import os @@ -386,14 +387,25 @@ def make_extended_parser() -> argparse.ArgumentParser: if nb_info["notebook"]: notebook = os.path.join(PKG_DIR, nb_info["notebook"]) else: - # If `"notebook"` entry is None, then set it to the user provided notebook - # TODO: This is a very hacky workaround, better implementation is not - # really possible with the current state of this module + # If `"notebook"` entry is None, then set it to the user provided + # notebook TODO: This is a very hacky workaround, better implementation + # is not really possible with the current state of this module + user_notebook_path = nb_info["user_notebook"] + # Pulls out the variables in the templated path string, so that they + # can be added to the argument parser + user_notebook_variables = [ + k.value.id + for k + in ast.walk(ast.parse(f"f'{user_notebook_path}'")) + if isinstance(k, ast.FormattedValue) + ] + user_notebook_parser = argparse.ArgumentParser() - user_notebook_parser.add_argument("--instrument") - user_notebook_parser.add_argument("--cycle") - user_notebook_parser.add_argument("--proposal") - user_notebook_args, _2 = user_notebook_parser.parse_known_args( + + for var in user_notebook_variables: + user_notebook_parser.add_argument(f"--{var}") + + user_notebook_args, _ = user_notebook_parser.parse_known_args( args=list(filter(lambda x: x != "-h", _)) # Drop help from args ) @@ -987,11 +999,7 @@ def run(): f"Concurrency parameter '{cvar}' " f"is taken from notebooks.py" ) - if not isinstance(defcval, (list, tuple)): - cvals = range(defcval) - else: - cvals = defcval - + cvals = range(defcval) if not isinstance(defcval, (list, tuple)) else defcval if cvals is None: defcval = get_par_attr(parms, cvar, 'value') if defcval is not None: @@ -999,11 +1007,7 @@ def run(): f"Concurrency parameter '{cvar}' " f"is taken from '{notebook}'" ) - if not isinstance(defcval, (list, tuple)): - cvals = [defcval] - else: - cvals = defcval - + cvals = [defcval] if not isinstance(defcval, (list, tuple)) else defcval if con_func: func = get_notebook_function(nb, con_func) if func is None: @@ -1066,7 +1070,7 @@ def run(): ) joblist.append(jobid) - if not all([j is None for j in joblist]): + if any(j is not None for j in joblist): print("Submitted the following SLURM jobs: {}".format(",".join(joblist)))