Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent import errors if glue-jupyter is not installed #53

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Check warning on line 26 in glue_ar/common/scatter_gltf.py

View check run for this annotation

Codecov / codecov/patch

glue_ar/common/scatter_gltf.py#L25-L26

Added lines #L25 - L26 were not covered by tests


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

Check warning on line 25 in glue_ar/common/scatter_usd.py

View check run for this annotation

Codecov / codecov/patch

glue_ar/common/scatter_usd.py#L23-L25

Added lines #L23 - L25 were not covered by tests


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