Skip to content

Commit

Permalink
allow no output_formats
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-i committed Oct 24, 2022
1 parent aa8a89b commit 56cbf84
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
11 changes: 6 additions & 5 deletions jupyter_scheduler/executors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
39 changes: 21 additions & 18 deletions jupyter_scheduler/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 56cbf84

Please sign in to comment.