Skip to content

Commit 3fa010c

Browse files
committed
refactor output files creation logic into a separate function for clarity
1 parent c56f924 commit 3fa010c

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

jupyter_scheduler/executors.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,9 @@
1111
import nbformat
1212
from nbconvert.preprocessors import CellExecutionError, ExecutePreprocessor
1313

14-
from jupyter_scheduler.download_manager import (
15-
DescribeDownload,
16-
Download,
17-
initiate_download_standalone,
18-
)
14+
from jupyter_scheduler.download_manager import initiate_download_standalone
1915
from jupyter_scheduler.models import DescribeJob, JobFeature, Status
20-
from jupyter_scheduler.orm import Job, create_session, generate_uuid
16+
from jupyter_scheduler.orm import Job, create_session
2117
from jupyter_scheduler.parameterize import add_parameters
2218
from jupyter_scheduler.utils import get_utc_timestamp
2319

@@ -155,11 +151,7 @@ def execute(self):
155151
raise e
156152
finally:
157153
self.add_side_effects_files(staging_dir)
158-
for output_format in job.output_formats:
159-
cls = nbconvert.get_exporter(output_format)
160-
output, _ = cls().from_notebook_node(nb)
161-
with fsspec.open(self.staging_paths[output_format], "w", encoding="utf-8") as f:
162-
f.write(output)
154+
self.create_output_files(job, nb)
163155
with self.db_session() as session:
164156
initiate_download_standalone(
165157
job_id=job.job_id,
@@ -168,7 +160,7 @@ def execute(self):
168160
redownload=True,
169161
)
170162

171-
def add_side_effects_files(self, staging_dir):
163+
def add_side_effects_files(self, staging_dir: str):
172164
"""Scan for side effect files potentially created after input file execution and update the job's packaged_files with these files"""
173165
input_notebook = os.path.relpath(self.staging_paths["input"])
174166
new_files_set = set()
@@ -190,6 +182,13 @@ def add_side_effects_files(self, staging_dir):
190182
)
191183
session.commit()
192184

185+
def create_output_files(self, job: DescribeJob, notebook_node):
186+
for output_format in job.output_formats:
187+
cls = nbconvert.get_exporter(output_format)
188+
output, _ = cls().from_notebook_node(notebook_node)
189+
with fsspec.open(self.staging_paths[output_format], "w", encoding="utf-8") as f:
190+
f.write(output)
191+
193192
def supported_features(cls) -> Dict[JobFeature, bool]:
194193
return {
195194
JobFeature.job_name: True,

0 commit comments

Comments
 (0)