Skip to content
Snippets Groups Projects
Commit ff9ab4c7 authored by Ronald Jäpel's avatar Ronald Jäpel
Browse files

Migrate Jupyter functionality into JupyterInterfaceRepo class

parent 03ff2c33
No related branches found
No related tags found
No related merge requests found
...@@ -87,7 +87,8 @@ class Notebook: ...@@ -87,7 +87,8 @@ class Notebook:
) )
return all(pass_check) return all(pass_check)
def save_ipynb(self): @staticmethod
def save_ipynb():
app = JupyterFrontEnd() app = JupyterFrontEnd()
print("Saving", end="") print("Saving", end="")
# note: docmanager:save doesn't lock the python thread until saving is completed. # note: docmanager:save doesn't lock the python thread until saving is completed.
......
...@@ -1032,25 +1032,33 @@ class ProjectRepo(BaseRepo): ...@@ -1032,25 +1032,33 @@ class ProjectRepo(BaseRepo):
else: else:
self.exit_context(message=results_commit_message) self.exit_context(message=results_commit_message)
class OutputRepo(BaseRepo):
pass
class JupyterInterfaceRepo(ProjectRepo):
def commit(self, message: str, add_all=True):
Notebook.save_ipynb()
super().commit(message, add_all)
def commit_nb_output(self, notebook_path: str, results_commit_message: str, def commit_nb_output(self, notebook_path: str, results_commit_message: str,
force_rerun=False, timeout=600, conversion_formats: list = None): force_rerun=False, timeout=600, conversion_formats: list = None):
if not Path(notebook_path).is_absolute(): if not Path(notebook_path).is_absolute():
notebook_path = self.working_dir / notebook_path notebook_path = self.working_dir / notebook_path
# if "nbconvert_call" in sys.argv:
# # This won't work as intended.
# self.enter_context(force=True)
# else:
# self.enter_context(force=False)
notebook = Notebook(notebook_path) notebook = Notebook(notebook_path)
if "nbconvert_call" not in sys.argv:
# This is reached in the first call of this function
self.enter_context(force=False)
notebook.check_and_rerun_notebook(force_rerun=force_rerun, notebook.check_and_rerun_notebook(force_rerun=force_rerun,
timeout=timeout) timeout=timeout)
else:
# This is executed during the nbconvert call
notebook.convert_ipynb(self.output_path, formats=conversion_formats) notebook.convert_ipynb(self.output_path, formats=conversion_formats)
notebook.export_all_figures(self.output_path) notebook.export_all_figures(self.output_path)
self.exit_context(results_commit_message) self.exit_context(results_commit_message)
class OutputRepo(BaseRepo):
pass
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment