diff --git a/jupyter_scheduler/executors.py b/jupyter_scheduler/executors.py index ea31b440f..38de4af54 100644 --- a/jupyter_scheduler/executors.py +++ b/jupyter_scheduler/executors.py @@ -133,11 +133,12 @@ def execute(self): except CellExecutionError as e: pass finally: - for output_format in job.output_formats: - cls = nbconvert.get_exporter(output_format) - output, resources = cls().from_notebook_node(nb) - with fsspec.open(self.staging_paths[output_format], "w", encoding="utf-8") as f: - f.write(output) + if job.output_formats: + for output_format in job.output_formats: + cls = nbconvert.get_exporter(output_format) + output, resources = cls().from_notebook_node(nb) + with fsspec.open(self.staging_paths[output_format], "w", encoding="utf-8") as f: + f.write(output) def supported_features(cls) -> Dict[JobFeature, bool]: return { diff --git a/jupyter_scheduler/scheduler.py b/jupyter_scheduler/scheduler.py index 993fc7b3f..a211321a4 100644 --- a/jupyter_scheduler/scheduler.py +++ b/jupyter_scheduler/scheduler.py @@ -235,10 +235,11 @@ def get_output_filenames(self, model: DescribeJob) -> Dict[str, str]: """ filenames = {} - for output_format in model.output_formats: - filenames[output_format] = create_output_filename( - model.input_uri, model.create_time, output_format - ) + if model.output_formats: + for output_format in model.output_formats: + filenames[output_format] = create_output_filename( + model.input_uri, model.create_time, output_format + ) return filenames @@ -251,16 +252,17 @@ def add_outputs(self, model: DescribeJob): mapping = self.environments_manager.output_formats_mapping() outputs = [] output_filenames = self.get_output_filenames(model) - for output_format in model.output_formats: - filename = output_filenames[output_format] - output_path = os.path.join(model.output_prefix, filename) - outputs.append( - Output( - display_name=mapping[output_format], - output_format=output_format, - output_path=output_path if self.file_exists(output_path) else None, + if model.output_formats: + for output_format in model.output_formats: + filename = output_filenames[output_format] + output_path = os.path.join(model.output_prefix, filename) + outputs.append( + Output( + display_name=mapping[output_format], + output_format=output_format, + output_path=output_path if self.file_exists(output_path) else None, + ) ) - ) model.outputs = outputs model.downloaded = all(output.output_path for output in outputs) @@ -319,8 +321,8 @@ def create_job(self, model: CreateJob) -> str: if job: raise IdempotencyTokenError(model.idempotency_token) - if not model.output_formats: - model.output_formats = ["ipynb"] + # if not model.output_formats: + # model.output_formats = ["ipynb"] job = Job(**model.dict(exclude_none=True)) session.add(job) @@ -549,9 +551,10 @@ def get_staging_paths(self, job_id: str) -> Dict[str, str]: if not model: return staging_paths - for output_format in model.output_formats: - filename = create_output_filename(model.input_uri, model.create_time, output_format) - staging_paths[output_format] = os.path.join(self.staging_path, job_id, filename) + if model.output_formats: + for output_format in model.output_formats: + filename = create_output_filename(model.input_uri, model.create_time, output_format) + staging_paths[output_format] = os.path.join(self.staging_path, job_id, filename) return staging_paths