Skip to content

Commit

Permalink
avoid installing dependencies for widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
lferraz committed Feb 14, 2023
1 parent e95aafe commit 695d1c0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
23 changes: 21 additions & 2 deletions limbus/widgets/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@
import logging
import functools

import cv2
try:
# NOTE: we import the cv2 & visdom modules here to avoid having it as a dependency
# for the whole project.
import cv2
import visdom
except ImportError:
pass

import torch
import visdom
import kornia
import numpy as np

Expand Down Expand Up @@ -163,6 +169,11 @@ class Visdom(Viz):

def __init__(self) -> None:
super().__init__()
try:
import visdom
except:
raise ImportError("To use Visdom as backend install the widgets extras: "
"pip install limbus[widgets]")
self._vis: Optional[visdom.Visdom] = None
self._try_init()

Expand Down Expand Up @@ -305,6 +316,14 @@ def show_text(self, component: Component, title: str, text: str, append: bool =
class OpenCV(Console):
"""Console visualization backend + openCV for images."""

def __init__(self) -> None:
super().__init__()
try:
import cv2
except:
raise ImportError("To use OpenCV as backend install the widgets extras: "
"pip install limbus[widgets]")

@is_enabled
@set_title
def show_image(self, component: Component, title: str, image: torch.Tensor):
Expand Down
8 changes: 5 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
install_requires=[
'torch',
'numpy',
'visdom',
'typeguard',
'kornia',
'opencv-python'
],
extras_require={
'dev': [
Expand All @@ -30,7 +28,11 @@
],
'components': [
'limbus-components'
]
],
'widgets': [
'visdom',
'opencv-python',
]
},
packages=find_packages(where='.'),
package_dir={'': '.'},
Expand Down
2 changes: 1 addition & 1 deletion setup_dev_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ $conda_bin env create
source $conda_bin_dir/activate $dev_env_dir/envs/limbus

# install dev requirements
pip install -e .[dev,components]
pip install -e .[dev,components,widgets]
# note that limbus-components is not installed in editable mode

0 comments on commit 695d1c0

Please sign in to comment.