Skip to content

Commit

Permalink
fix: don't require pillow unless it's used (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
benlubas committed Mar 12, 2024
1 parent 7d8bd23 commit ca725ae
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ window (or both)
- `plotly` and `kaleido` (for displaying Plotly figures)
- `pyperclip` if you want to use `molten_copy_output`
- `nbformat` for importing and exporting output to jupyter notebooks files
- `pillow` for opening images with `:MoltenImagePopup`

You can run `:checkhealth` to see what you have installed.

Expand Down
1 change: 1 addition & 0 deletions lua/molten/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ M.check = function()
py_mod_check("kaleido", "kaleido", false)
py_mod_check("pyperclip", "pyperclip", false)
py_mod_check("nbformat", "nbformat", false)
py_mod_check("PIL", "pillow", false)
end

return M
7 changes: 6 additions & 1 deletion rplugin/python3/molten/moltenbuffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import IO, Callable, List, Optional, Dict, Tuple
from queue import Queue
import hashlib
from PIL import Image

from pynvim import Nvim
from pynvim.api import Buffer
Expand Down Expand Up @@ -146,10 +145,16 @@ def open_image_popup(self, silent=False) -> bool:
for chunk in output.chunks:
if isinstance(chunk, ImageOutputChunk):
try:
from PIL import Image
img = Image.open(chunk.img_path)
img.show(f"[{output.execution_count}] Molten Image")
if not silent:
notify_info(self.nvim, "Opened image popup")
except ModuleNotFoundError:
if not silent:
notify_error(
self.nvim, "Failed to open image becuase module `PIL` was not found"
)
except:
if not silent:
notify_error(
Expand Down

0 comments on commit ca725ae

Please sign in to comment.