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

Reduce dependencies

parent 41170a8b
No related branches found
No related tags found
No related merge requests found
......@@ -2,24 +2,25 @@ import sys
import time
import os
from pathlib import Path
import traceback
from cadetrdm.io_utils import wait_for_user
from ipylab import JupyterFrontEnd
import junix
import nbformat as nbf
try:
from nbconvert.preprocessors import ExecutePreprocessor
from nbconvert.nbconvertapp import NbConvertApp
except ModuleNotFoundError as e:
# traceback.print_exc()
print("No working nbconvert installation found OR a conflict in your packages found.")
print("For more information, import nbconvert and check the error.")
class Notebook:
def __init__(self, notebook_path):
import nbformat as nbf
self.nbf = nbf
try:
from nbconvert.preprocessors import ExecutePreprocessor
from nbconvert.nbconvertapp import NbConvertApp
self.ExecutePreprocessor = ExecutePreprocessor
self.NbConvertApp = NbConvertApp
except ModuleNotFoundError as e:
# traceback.print_exc()
print("No working nbconvert installation found OR a conflict in your packages found.")
print("For more information, import nbconvert and check the error.")
self.notebook_path = Path(notebook_path)
@property
......@@ -31,7 +32,7 @@ class Notebook:
check_top_to_bottom=False,
check_in_order=True,
exclude_last_cell=False):
notebook = nbf.read(self.notebook_path, nbf.NO_CONVERT)
notebook = self.nbf.read(self.notebook_path, self.nbf.NO_CONVERT)
# extract all code cells (disregard markdown, raw and others), then extract the execution order
output_cells = [cell for cell in notebook.cells if cell["cell_type"] == "code"]
......@@ -96,6 +97,7 @@ class Notebook:
@staticmethod
def save_ipynb():
from ipylab import JupyterFrontEnd
app = JupyterFrontEnd()
print("Saving", end="")
# note: docmanager:save doesn't lock the python thread until saving is completed.
......@@ -106,6 +108,7 @@ class Notebook:
print("")
def reload_notebook(self):
from ipylab import JupyterFrontEnd
app = JupyterFrontEnd()
app.commands.execute('docmanager:reload')
......@@ -131,20 +134,20 @@ class Notebook:
print("Rerunning.")
with open(self.notebook_path) as f:
nb = nbf.read(f, as_version=4)
nb = self.nbf.read(f, as_version=4)
ep = ExecutePreprocessor(timeout=timeout, kernel_name='python3', extra_arguments=["nbconvert_call"])
ep = self.ExecutePreprocessor(timeout=timeout, kernel_name='python3', extra_arguments=["nbconvert_call"])
ep.preprocess(nb, )
with open(self.notebook_path, 'w', encoding='utf-8') as f:
nbf.write(nb, f)
self.nbf.write(nb, f)
self.reload_notebook()
def convert_ipynb(self, output_dir, formats: list = None):
if formats is None:
formats = ["html", ]
app = NbConvertApp()
app = self.NbConvertApp()
app.initialize()
output_root_directory = os.path.join(output_dir, self.notebook_name)
for export_format in formats:
......@@ -157,8 +160,9 @@ class Notebook:
app.start()
def export_all_figures(self, output_dir):
import junix
file_without_extension = self.notebook_path.stem
images = junix.export_images(filepath=str(self.notebook_path),
output_dir=os.path.join(output_dir, self.notebook_name),
prefix=file_without_extension)
......@@ -13,7 +13,6 @@ from urllib.request import urlretrieve
from ipylab import JupyterFrontEnd
from tabulate import tabulate
import pandas as pd
from cadetrdm.io_utils import recursive_chmod, write_lines_to_file, wait_for_user, init_lfs
from cadetrdm.jupyter_functionality import Notebook
......@@ -696,22 +695,13 @@ class ProjectRepo(BaseRepo):
tsv_filepath = self.working_dir / self._output_folder / "log.tsv"
df = pd.read_csv(tsv_filepath, sep="\t", header=0)
# Clean up the headers
df = df.rename(columns={"Output repo commit message": 'Output commit message',
"Output repo branch": "Output branch",
"Output repo commit hash": "Output hash", "Project repo commit hash": "Project hash"})
# Shorten the commit hashes
df.loc[:, "Output hash"] = df.loc[:, "Output hash"].apply(lambda x: x[:8])
# Shorten commit messages
df.loc[:, "Output commit message"] = df.loc[:, "Output commit message"].apply(lambda x: x[:55])
df.loc[:, "Output commit message"] = df.loc[:, "Output commit message"].apply(insert_newlines)
with open(tsv_filepath, "r") as filehandle:
lines = filehandle.readlines()
# Select only columns of interest
df = df.loc[:, ["Output commit message", "Output hash", "Output branch"]]
line_array = [line.replace("\n", "").split("\t") for line in lines]
# Print
print(tabulate(df, headers=df.columns, showindex=False))
print(tabulate(line_array[1:], headers=line_array[0]))
self.output_repo.checkout(self.output_repo._most_recent_branch)
......
......@@ -24,12 +24,6 @@ install_requires =
git-lfs
click
tabulate
pandas
nbformat
nbconvert
ipylab
junix
jupytext
include_package_data = True
......@@ -48,6 +42,13 @@ testing =
numpy
build
jupyter =
nbformat
nbconvert
ipylab
junix
jupytext
docs =
sphinx>=5.3.0
sphinxcontrib-bibtex>=2.5.0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment