Skip to content

Commit

Permalink
PERF: delay rarely used imports from visualization.api submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
neutrinoceros committed Jun 19, 2023
1 parent df86543 commit c974677
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
3 changes: 2 additions & 1 deletion yt/tests/test_external_frontends.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import importlib.metadata
import sys

import pytest
Expand Down Expand Up @@ -39,7 +40,7 @@ def mock_entry_points(group=None):
else:
return {"yt.frontends": [MockEntryPoint]}

monkeypatch.setattr(yt.loaders, "entry_points", mock_entry_points)
monkeypatch.setattr(importlib.metadata, "entry_points", mock_entry_points)
assert "ExtDataset" not in output_type_registry

yield
Expand Down
6 changes: 2 additions & 4 deletions yt/visualization/fixed_resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
from yt.frontends.ytdata.utilities import save_as_dataset
from yt.funcs import get_output_filename, iter_fields, mylog
from yt.loaders import load_uniform_grid
from yt.utilities.lib.api import ( # type: ignore
CICDeposit_2,
add_points_to_greyscale_image,
)
from yt.utilities.lib.pixelization_routines import (
pixelize_cylinder,
rotate_particle_coord,
Expand Down Expand Up @@ -702,6 +698,8 @@ def __getitem__(self, item):
if item in self.data:
return self.data[item]

from yt.utilities.lib.api import CICDeposit_2, add_points_to_greyscale_image

deposition = self.data_source.deposition
density = self.data_source.density

Expand Down
13 changes: 9 additions & 4 deletions yt/visualization/plot_modifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
from yt._maintenance.deprecation import issue_deprecation_warning
from yt._typing import AnyFieldKey, FieldKey
from yt.data_objects.data_containers import YTDataContainer
from yt.data_objects.level_sets.clump_handling import Clump
from yt.data_objects.selection_objects.cut_region import YTCutRegion
from yt.frontends.ytdata.data_structures import YTClumpContainer
from yt.funcs import is_sequence, mylog, validate_width_tuple
from yt.geometry.api import Geometry
from yt.geometry.unstructured_mesh_handler import UnstructuredIndex
from yt.units import dimensions
from yt.units.yt_array import YTArray, YTQuantity, uhstack # type: ignore
from yt.utilities.exceptions import (
Expand All @@ -29,8 +27,6 @@
YTUnsupportedPlotCallback,
)
from yt.utilities.lib.geometry_utils import triangle_plane_intersect
from yt.utilities.lib.line_integral_convolution import line_integral_convolution_2d
from yt.utilities.lib.mesh_triangulation import triangulate_indices
from yt.utilities.lib.pixelization_routines import (
pixelize_cartesian,
pixelize_off_axis_cartesian,
Expand Down Expand Up @@ -1628,6 +1624,8 @@ def __init__(self, clumps, *, plot_args=None, **kwargs):
self.plot_args = plot_args

def __call__(self, plot):
from yt.data_objects.level_sets.clump_handling import Clump

bounds = self._physical_bounds(plot)
extent = self._plot_bounds(plot)

Expand Down Expand Up @@ -2391,6 +2389,9 @@ def promote_2d_to_3d(self, coords, indices, plot):
return new_coords, new_connects

def __call__(self, plot):
from yt.geometry.unstructured_mesh_handler import UnstructuredIndex
from yt.utilities.lib.mesh_triangulation import triangulate_indices

index = plot.ds.index
if not issubclass(type(index), UnstructuredIndex):
raise RuntimeError(
Expand Down Expand Up @@ -3199,6 +3200,10 @@ def __init__(
def __call__(self, plot):
from matplotlib import cm

from yt.utilities.lib.line_integral_convolution import (
line_integral_convolution_2d,
)

bounds = self._physical_bounds(plot)
extent = self._plot_bounds(plot)

Expand Down

0 comments on commit c974677

Please sign in to comment.