Skip to content

Commit

Permalink
Merge pull request #53 from Carifio24/gj-imports
Browse files Browse the repository at this point in the history
Prevent import errors if glue-jupyter is not installed
  • Loading branch information
Carifio24 authored Sep 18, 2024
2 parents 7ead880 + 2cd220b commit 63292b1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
14 changes: 5 additions & 9 deletions glue_ar/common/scatter.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
from functools import partial
from numpy import clip, isfinite, isnan, ndarray, ones, sqrt
try:
from types import NoneType
except ImportError:
NoneType = type(None)
from typing import Callable, Dict, List, Optional, Tuple, Union


from glue.utils import ensure_numerical
from glue_vispy_viewers.scatter.layer_state import ScatterLayerState

from glue_ar.common.shapes import rectangular_prism_points, rectangular_prism_triangulation, \
sphere_points, sphere_triangles
from glue_ar.utils import Bounds, NoneType, Viewer3DState, mask_for_bounds

try:
from glue_jupyter.ipyvolume.scatter import Scatter3DLayerState
except ImportError:
Scatter3DLayerState = NoneType

from glue_ar.common.shapes import rectangular_prism_points, rectangular_prism_triangulation, \
sphere_points, sphere_triangles
from glue_ar.utils import Bounds, Viewer3DState, mask_for_bounds

ScatterLayerState3D = Union[ScatterLayerState, Scatter3DLayerState]

Point = Tuple[float, float, float]
Expand Down
8 changes: 6 additions & 2 deletions glue_ar/common/scatter_gltf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from gltflib import AccessorType, BufferTarget, ComponentType, PrimitiveMode
from glue_jupyter.common.state3d import ViewerState3D
from glue_vispy_viewers.scatter.layer_state import ScatterLayerState
from glue_vispy_viewers.volume.viewer_state import Vispy3DViewerState
from numpy import array, isfinite, ndarray
Expand All @@ -19,7 +18,12 @@
from glue_ar.common.scatter import Scatter3DLayerState, ScatterLayerState3D, \
PointsGetter, box_points_getter, IPYVOLUME_POINTS_GETTERS, \
IPYVOLUME_TRIANGLE_GETTERS, VECTOR_OFFSETS, radius_for_scatter_layer, \
scatter_layer_mask, sizes_for_scatter_layer, sphere_points_getter
scatter_layer_mask, sizes_for_scatter_layer, sphere_points_getter, NoneType

try:
from glue_jupyter.common.state3d import ViewerState3D
except ImportError:
ViewerState3D = NoneType


def add_vectors_gltf(builder: GLTFBuilder,
Expand Down
11 changes: 8 additions & 3 deletions glue_ar/common/scatter_usd.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from typing import List, Optional, Tuple

from glue_jupyter.common.state3d import ViewerState3D
from glue_jupyter.ipyvolume.scatter import Scatter3DLayerState
from glue_vispy_viewers.scatter.layer_state import ScatterLayerState
from glue_vispy_viewers.scatter.viewer_state import Vispy3DViewerState
from numpy import array, ndarray
Expand All @@ -16,9 +14,16 @@
from glue_ar.common.shapes import cone_triangles, cone_points, cylinder_points, cylinder_triangles, \
normalize, rectangular_prism_triangulation, sphere_triangles
from glue_ar.utils import Viewer3DState, export_label_for_layer, iterable_has_nan, hex_to_components, \
layer_color, xyz_for_layer, Bounds
layer_color, xyz_for_layer, Bounds, NoneType
from glue_ar.usd_utils import material_for_color

try:
from glue_jupyter.common.state3d import ViewerState3D
from glue_jupyter.ipyvolume.scatter import Scatter3DLayerState
except ImportError:
ViewerState3D = NoneType
Scatter3DLayerState = NoneType


def add_vectors_usd(builder: USDBuilder,
viewer_state: Viewer3DState,
Expand Down
5 changes: 5 additions & 0 deletions glue_ar/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
except ImportError:
ViewerState3D = Vispy3DViewerState

# Backwards compatibility for Python < 3.10
try:
from types import NoneType # noqa
except ImportError:
NoneType = type(None)

PACKAGE_DIR = dirname(abspath(__file__))
AR_ICON = abspath(join(dirname(__file__), "ar.png"))
Expand Down

0 comments on commit 63292b1

Please sign in to comment.