Skip to content

Commit

Permalink
Merge main into sweep/add-deserialization-fn
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] authored Dec 6, 2023
2 parents 6cbed51 + 2cc905e commit 3788888
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
17 changes: 13 additions & 4 deletions muutils/nbutils/configure_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
# handling figures
PlottingMode = typing.Literal["ignore", "inline", "widget", "save"]
PLOT_MODE: PlottingMode = "inline"
CONVERSION_PLOTMODE_OVERRIDE: PlottingMode | None = None
FIG_COUNTER: int = 0
FIG_OUTPUT_FMT: str | None = None
FIG_NUMBERED_FNAME: str = "figure-{num}"
Expand Down Expand Up @@ -69,10 +70,16 @@ def setup_plots(
close_after_plotshow: bool = False,
) -> None:
"""Set up plot saving/rendering options"""
global PLOT_MODE, FIG_COUNTER, FIG_OUTPUT_FMT, FIG_NUMBERED_FNAME, FIG_CONFIG, FIG_BASEPATH, CLOSE_AFTER_PLOTSHOW
global PLOT_MODE, CONVERSION_PLOTMODE_OVERRIDE, FIG_COUNTER, FIG_OUTPUT_FMT, FIG_NUMBERED_FNAME, FIG_CONFIG, FIG_BASEPATH, CLOSE_AFTER_PLOTSHOW

# set plot mode, handling override
if CONVERSION_PLOTMODE_OVERRIDE is not None:
# override if set
PLOT_MODE = CONVERSION_PLOTMODE_OVERRIDE
else:
# otherwise use the given plot mode
PLOT_MODE = plot_mode

# set plot mode
PLOT_MODE = plot_mode
FIG_COUNTER = 0
CLOSE_AFTER_PLOTSHOW = close_after_plotshow

Expand All @@ -81,7 +88,9 @@ def setup_plots(
ipython = get_ipython()
ipython.magic("matplotlib inline")
else:
raise RuntimeError("Cannot use inline plotting outside of Jupyter")
raise RuntimeError(
f"Cannot use inline plotting outside of Jupyter\n{PLOT_MODE = }\t{CONVERSION_PLOTMODE_OVERRIDE = }"
)
return
elif PLOT_MODE == "widget":
if IN_JUPYTER:
Expand Down
9 changes: 9 additions & 0 deletions muutils/nbutils/convert_ipynb_to_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ def new_render(
render = new_render
# ------------------------------------------------------------
"""
],
"muutils": [
"""import muutils.nbutils.configure_notebook as nb_conf
nb_conf.CONVERSION_PLOTMODE_OVERRIDE = "ignore"
"""
],
}
Expand All @@ -53,6 +58,10 @@ def disable_plots_in_script(script_lines: list[str]) -> list[str]:
"""Disable plots in a script by adding cursed things after the import statements"""
result_str_TEMP: str = "\n\n".join(script_lines)
script_lines_new: list[str] = script_lines

if "muutils" in result_str_TEMP:
script_lines_new = DISABLE_PLOTS["muutils"] + script_lines_new

if "matplotlib" in result_str_TEMP:
assert (
"import matplotlib.pyplot as plt" in result_str_TEMP
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "muutils"
version = "0.5.4"
version = "0.5.5"
description = "A collection of miscellaneous python utilities"
license = "GPL-3.0-only"
authors = ["mivanit <[email protected]>"]
Expand Down

0 comments on commit 3788888

Please sign in to comment.