From 7f1c31d554e2b080678ef8855cfb19b86c183b8e Mon Sep 17 00:00:00 2001 From: benlubas Date: Fri, 10 May 2024 12:45:30 -0400 Subject: [PATCH 1/5] fix: mark running cells as failed+done on restart --- rplugin/python3/molten/moltenbuffer.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/rplugin/python3/molten/moltenbuffer.py b/rplugin/python3/molten/moltenbuffer.py index 8b16ad8..c9adb56 100644 --- a/rplugin/python3/molten/moltenbuffer.py +++ b/rplugin/python3/molten/moltenbuffer.py @@ -93,10 +93,15 @@ def interrupt(self) -> None: def restart(self, delete_outputs: bool = False) -> None: if delete_outputs: - self.outputs = {} + self.clear_virt_outputs() self.clear_interface() self.clear_open_output_windows() - self.clear_virt_outputs() + self.outputs = {} + else: + for output in self.outputs.values(): + if output.output.status == OutputStatus.RUNNING: + output.output.status = OutputStatus.DONE + output.output.success = False self.runtime.restart() From ab9351baff839c2ea4b0c1b5d1ad8d4968c7f1c1 Mon Sep 17 00:00:00 2001 From: Ben Lubas <56943754+benlubas@users.noreply.github.com> Date: Fri, 10 May 2024 14:03:28 -0400 Subject: [PATCH 2/5] fix: correct execution time for multiple cells (#196) --- rplugin/python3/molten/outputbuffer.py | 2 +- rplugin/python3/molten/outputchunks.py | 6 +++--- rplugin/python3/molten/runtime.py | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/rplugin/python3/molten/outputbuffer.py b/rplugin/python3/molten/outputbuffer.py index c343821..661bd4b 100644 --- a/rplugin/python3/molten/outputbuffer.py +++ b/rplugin/python3/molten/outputbuffer.py @@ -70,7 +70,7 @@ def _get_header_text(self, output: Output) -> str: else: old = "" - if not output.old and self.options.output_show_exec_time: + if not output.old and self.options.output_show_exec_time and output.start_time: start = output.start_time end = output.end_time if output.end_time is not None else datetime.now() diff = end - start diff --git a/rplugin/python3/molten/outputchunks.py b/rplugin/python3/molten/outputchunks.py index ecdb0bb..b7ae055 100644 --- a/rplugin/python3/molten/outputchunks.py +++ b/rplugin/python3/molten/outputchunks.py @@ -179,8 +179,8 @@ class Output: status: OutputStatus success: bool old: bool - start_time: datetime - end_time: datetime + start_time: datetime | None + end_time: datetime | None _should_clear: bool @@ -191,7 +191,7 @@ def __init__(self, execution_count: Optional[int]): self.success = True self.old = False - self.start_time = datetime.now() + self.start_time = None self.end_time = None self._should_clear = False diff --git a/rplugin/python3/molten/runtime.py b/rplugin/python3/molten/runtime.py index 490b202..34ff466 100644 --- a/rplugin/python3/molten/runtime.py +++ b/rplugin/python3/molten/runtime.py @@ -1,3 +1,4 @@ +from datetime import datetime from typing import Optional, Tuple, List, Dict, Generator, IO, Any from enum import Enum from contextlib import contextmanager @@ -142,6 +143,7 @@ def copy_on_demand(content_ctor): return False if output.status == OutputStatus.HOLD: output.status = OutputStatus.RUNNING + output.start_time = datetime.now() elif output.status == OutputStatus.RUNNING: output.status = OutputStatus.DONE else: From 47b9a56d4bc0f877ff9469910b9653c46d462db4 Mon Sep 17 00:00:00 2001 From: Ben Lubas <56943754+benlubas@users.noreply.github.com> Date: Fri, 31 May 2024 22:25:33 -0400 Subject: [PATCH 3/5] chore: remove dead code (#202) --- rplugin/python3/molten/images.py | 55 ++++++++++---------------------- 1 file changed, 16 insertions(+), 39 deletions(-) diff --git a/rplugin/python3/molten/images.py b/rplugin/python3/molten/images.py index ecce8e4..02b3e57 100644 --- a/rplugin/python3/molten/images.py +++ b/rplugin/python3/molten/images.py @@ -35,12 +35,6 @@ def present(self) -> None: to reduce flickering. """ - @abstractmethod - def clear(self) -> None: - """ - Clear all images from the canvas. - """ - @abstractmethod def img_size(self, identifier: str) -> Dict[str, int]: """ @@ -102,9 +96,6 @@ def deinit(self) -> None: def present(self) -> None: pass - def clear(self) -> None: - pass - def img_size(self, _indentifier: str) -> Dict[str, int]: return {"height": 0, "width": 0} @@ -131,7 +122,6 @@ class ImageNvimCanvas(Canvas): def __init__(self, nvim: Nvim): self.nvim = nvim - self.images = {} self.visible = set() self.to_make_visible = set() self.to_make_invisible = set() @@ -145,7 +135,6 @@ def init(self) -> None: def deinit(self) -> None: self.image_api.clear_all() - self.images.clear() def present(self) -> None: # images to both show and hide should be ignored @@ -164,10 +153,6 @@ def present(self) -> None: self.to_make_invisible.clear() self.to_make_visible.clear() - def clear(self) -> None: - for img in self.visible: - self.image_api.clear(img) - def img_size(self, identifier: str) -> Dict[str, int]: return self.image_api.image_size(identifier) @@ -180,21 +165,19 @@ def add_image( bufnr: int, winnr: int | None = None, ) -> str: - if path not in self.images: - img = self.image_api.from_file( - path, - { - "id": identifier, - "buffer": bufnr, - "with_virtual_padding": True, - "x": x, - "y": y, - "window": winnr, - }, - ) - self.to_make_visible.add(img) - return img - return path + img = self.image_api.from_file( + path, + { + "id": identifier, + "buffer": bufnr, + "with_virtual_padding": True, + "x": x, + "y": y, + "window": winnr, + }, + ) + self.to_make_visible.add(img) + return img def remove_image(self, identifier: str) -> None: self.to_make_invisible.add(identifier) @@ -214,7 +197,6 @@ def __init__(self, nvim: Nvim, split_dir: str | None, split_size: int | None): self.nvim = nvim self.split_dir = split_dir self.split_size = split_size - self.images: dict = {} self.visible = set() self.to_make_visible = set() self.to_make_invisible = set() @@ -247,9 +229,6 @@ def present(self) -> None: self.to_make_invisible.clear() self.to_make_visible.clear() - def clear(self) -> None: - pass - def img_size(self, _indentifier: str) -> Dict[str, int]: return {"height": 0, "width": 0} @@ -263,11 +242,9 @@ def add_image( _winnr: int, ) -> str | dict[str, str]: """Adds an image to the queue to be rendered by Wezterm via the place method""" - if path not in self.images: - img = {"path": path, "id": identifier} - self.to_make_visible.add(img["path"]) - return img - return path + img = {"path": path, "id": identifier} + self.to_make_visible.add(img["path"]) + return img def remove_image(self, identifier: str) -> None: pass From 1a5360c59dc68230aac867fe262e4efc53f1b2d9 Mon Sep 17 00:00:00 2001 From: Gabriel Saillard Date: Tue, 2 Jul 2024 23:15:05 +0200 Subject: [PATCH 4/5] docs(nb-setup): example NewNotebook command (#214) --- docs/Notebook-Setup.md | 65 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/docs/Notebook-Setup.md b/docs/Notebook-Setup.md index 24ae363..822b9ad 100644 --- a/docs/Notebook-Setup.md +++ b/docs/Notebook-Setup.md @@ -411,6 +411,71 @@ vim.api.nvim_create_autocmd("BufEnter", { }) ``` +#### Creating new notebooks + +Since Jupytext needs a valid notebook file to convert, creating a blank new notebook is not as easy as making an empty buffer and loading it up. + +To simplify this workflow, you can define a vim user command to create an empty, but valid, notebook file and open it: + +```lua +-- Provide a command to create a blank new Python notebook +-- note: the metadata is needed for Jupytext to understand how to parse the notebook. +-- if you use another language than Python, you should change it in the template. +local default_notebook = [[ + { + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython" + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 + } +]] + +local function new_notebook(filename) + local path = filename .. ".ipynb" + local file = io.open(path, "w") + if file then + file:write(default_notebook) + file:close() + vim.cmd("edit " .. path) + else + print("Error: Could not open new notebook file for writing.") + end +end + +vim.api.nvim_create_user_command('NewNotebook', function(opts) + new_notebook(opts.args) +end, { + nargs = 1, + complete = 'file' +}) +``` + +You can then use `:NewNotebook folder/notebook_name` to start a new notebook from scratch! + ## Compromises Compared to Jupyter-lab: From eb6d0fe33e14989b0f1fbe25d9732889ee57bd1a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 12 Jul 2024 16:52:26 -0400 Subject: [PATCH 5/5] chore(main): release 1.8.4 (#195) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e038a92..c47051f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [1.8.4](https://github.com/benlubas/molten-nvim/compare/v1.8.3...v1.8.4) (2024-07-02) + + +### Bug Fixes + +* correct execution time for multiple cells ([#196](https://github.com/benlubas/molten-nvim/issues/196)) ([ab9351b](https://github.com/benlubas/molten-nvim/commit/ab9351baff839c2ea4b0c1b5d1ad8d4968c7f1c1)) +* mark running cells as failed+done on restart ([7f1c31d](https://github.com/benlubas/molten-nvim/commit/7f1c31d554e2b080678ef8855cfb19b86c183b8e)) + ## [1.8.3](https://github.com/benlubas/molten-nvim/compare/v1.8.2...v1.8.3) (2024-04-22)