Skip to content

Commit

Permalink
Use hasattr instead of version check
Browse files Browse the repository at this point in the history
  • Loading branch information
vidartf committed Aug 25, 2022
1 parent 18da0b2 commit ed4e994
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 22 deletions.
1 change: 0 additions & 1 deletion docs/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ dependencies:
- scikit-image
- sphinx
- nbsphinx
- packaging
30 changes: 10 additions & 20 deletions pythreejs/_base/Three.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
from ipywidgets import Widget, widget_serialization
from traitlets import Unicode

try:
from importlib.metadata import version
from packaging.version import parse, Version
def version_gte_than(pkg, minimum_supported):
return parse(version(pkg)) >= Version(minimum_supported)
except ImportError:
def version_gte_than(pkg, minimum_supported):
import pkg_resources
return pkg_resources.get_distribution(pkg).parsed_version >= pkg_resources.parse_version(minimum_supported)

from .._package import npm_pkg_name
from .._version import EXTENSION_SPEC_VERSION

Expand Down Expand Up @@ -49,7 +39,15 @@ def _on_ret_val(self, method_name, ret_val):
"""Message callback used internally for logging exec returns"""
self.log.info('%s() -> %s' % (method_name, ret_val))

if version_gte_than("ipywidgets", "8.0.0"):
if hasattr(Widget, "_ipython_display_"): # ipywidgets < 8.0.0
def _ipython_display_(self, **kwargs):
if self._previewable:
from IPython.display import display
from .renderable import Preview
return display(Preview(self), **kwargs)
else:
return super(ThreeWidget, self)._ipython_display_(**kwargs)
else:
def _repr_mimebundle_(self, **kwargs):
if self._previewable:
from .renderable import Preview
Expand All @@ -66,12 +64,4 @@ def _repr_mimebundle_(self, **kwargs):
}
}
else:
return super(ThreeWidget, self)._repr_mimebundle_(**kwargs)
else:
def _ipython_display_(self, **kwargs):
if self._previewable:
from IPython.display import display
from .renderable import Preview
return display(Preview(self), **kwargs)
else:
return super(ThreeWidget, self)._ipython_display_(**kwargs)
return super(ThreeWidget, self)._repr_mimebundle_(**kwargs)
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
'ipywidgets>=7.2.1',
'ipydatawidgets>=1.1.1',
'numpy',
'packaging',
'traitlets',
],
'extras_require': {
Expand Down

0 comments on commit ed4e994

Please sign in to comment.