Skip to content

Commit

Permalink
Refactor NoneType check into package utilities.
Browse files Browse the repository at this point in the history
  • Loading branch information
Carifio24 committed Sep 18, 2024
1 parent 3835c01 commit 2cd220b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 34 deletions.
16 changes: 5 additions & 11 deletions glue_ar/common/scatter.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
from functools import partial
from numpy import clip, isfinite, isnan, ndarray, ones, sqrt

# Backwards compatibility for Python < 3.10
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
17 changes: 6 additions & 11 deletions glue_ar/common/scatter_gltf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,8 @@
from numpy import array, isfinite, ndarray
from numpy.linalg import norm

# Backwards compatibility for Python < 3.10
try:
from types import NoneType
except ImportError:
NoneType = type(None)
from typing import List, Literal, Optional, Tuple

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


from glue_ar.common.export_options import ar_layer_export
from glue_ar.common.scatter_export_options import ARIpyvolumeScatterExportOptions, ARVispyScatterExportOptions
Expand All @@ -28,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
20 changes: 8 additions & 12 deletions glue_ar/common/scatter_usd.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
# Backwards compatibility for Python < 3.10
try:
from types import NoneType
except ImportError:
NoneType = type(None)
from typing import List, Optional, Tuple

try:
from glue_jupyter.common.state3d import ViewerState3D
from glue_jupyter.ipyvolume.scatter import Scatter3DLayerState
except ImportError:
ViewerState3D = NoneType
Scatter3DLayerState = NoneType
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 @@ -25,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

0 comments on commit 2cd220b

Please sign in to comment.