Skip to content

Commit 5f68fdf

Browse files
committed
ci: forbid module-level import of scipy & matplotlib
1 parent a59a1e1 commit 5f68fdf

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ extend-ignore = [
277277
[tool.ruff.lint.isort]
278278
required-imports = ["from __future__ import annotations"]
279279

280+
[tool.ruff.lint.flake8-tidy-imports]
281+
banned-module-level-imports = ["scipy", "matplotlib"]
282+
280283
[tool.ruff.lint.per-file-ignores]
281284
"tests/**/*" = [
282285
"B015", # useless comparison
@@ -287,6 +290,10 @@ required-imports = ["from __future__ import annotations"]
287290
"S101", # asserts allowed in tests
288291
"NPY201", # numpy 2.* compatibility check
289292
"TID252", # allow relative imports in tests
293+
"TID253", # allow heavy imports in tests
294+
]
295+
"tidy3d/plugins/**/*" = [
296+
"TID253", # allow heavy imports in plugins (not used by MC)
290297
]
291298

292299
[tool.pytest.ini_options]

tidy3d/components/mode/mode_solver.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
import numpy as np
1212
import pydantic.v1 as pydantic
1313
import xarray as xr
14-
from matplotlib.collections import PatchCollection
15-
from matplotlib.patches import Rectangle
1614

1715
from tidy3d.components.base import Tidy3dBaseModel, cached_property, skip_if_fields_missing
1816
from tidy3d.components.boundary import PML, Absorber, Boundary, BoundarySpec, PECBoundary, StablePML
@@ -2394,6 +2392,10 @@ def _plot_pml(
23942392
cls, simulation: Simulation, plane: Box, mode_spec: ModeSpec, ax: Ax = None
23952393
) -> Ax:
23962394
"""Plot the mode plane absorbing boundaries."""
2395+
2396+
from matplotlib.collections import PatchCollection
2397+
from matplotlib.patches import Rectangle
2398+
23972399
# Get the mode plane normal axis, center, and limits.
23982400
_, h_lim, v_lim, _ = cls._center_and_lims(simulation=simulation, plane=plane)
23992401

tidy3d/components/viz/axes_utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
from functools import wraps
44
from typing import Optional
55

6-
import matplotlib.pyplot as plt
7-
import matplotlib.ticker as ticker
8-
96
from tidy3d.components.types import Ax, Axis, LengthUnit
107
from tidy3d.constants import UnitScaling
118
from tidy3d.exceptions import Tidy3dKeyError
129

1310

1411
def make_ax() -> Ax:
1512
"""makes an empty ``ax``."""
13+
import matplotlib.pyplot as plt
14+
1615
_, ax = plt.subplots(1, 1, tight_layout=True)
1716
return ax
1817

@@ -60,6 +59,9 @@ def set_default_labels_and_title(
6059
When the ``plot_length_units`` are specified, the plot axes are scaled, and
6160
the title and axis labels include the desired units.
6261
"""
62+
63+
import matplotlib.ticker as ticker
64+
6365
xlabel = axis_labels[0]
6466
ylabel = axis_labels[1]
6567
if plot_length_units is not None:

0 commit comments

Comments
 (0)