Skip to content

Commit

Permalink
Introduce import error tests for optionals
Browse files Browse the repository at this point in the history
Introduce import error fences for optional plotting behavior in
pyedb.common.nets.CommonNets.plot.
  • Loading branch information
isaacwaldron committed Dec 2, 2024
1 parent 870ab60 commit bbe91a2
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/pyedb/common/nets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import os
import time

import shapely

from pyedb.generic.constants import CSS4_COLORS


Expand Down Expand Up @@ -120,22 +118,30 @@ def mirror_poly(poly):
sign = -1
return [[sign * i[0], i[1]] for i in poly]

import matplotlib.pyplot as plt
try:
import matplotlib.pyplot as plt
except ImportError:
self._pedb.logger.error("Matplotlib is needed. Please, install it first.")
return False

dpi = 100.0
figsize = (size[0] / dpi, size[1] / dpi)

fig = plt.figure(figsize=figsize)
ax = fig.add_subplot(1, 1, 1)
from shapely import affinity
from shapely.geometry import (
LinearRing,
MultiLineString,
MultiPolygon,
Point,
Polygon,
)
from shapely.plotting import plot_line, plot_polygon
try:
from shapely import affinity, union_all
from shapely.geometry import (
LinearRing,
MultiLineString,
MultiPolygon,
Point,
Polygon,
)
from shapely.plotting import plot_line, plot_polygon
except ImportError:
self._pedb.logger.error("Shapely is needed. Please, install it first.")
return False

start_time = time.time()
if not nets:
Expand Down Expand Up @@ -317,7 +323,7 @@ def create_poly(prim, polys, lines):
h1 = mirror_poly([(i, j) for i, j in zip(xvt, yvt)])
holes.append(h1)
if len(holes) > 1:
holes = shapely.union_all([Polygon(i) for i in holes])
holes = union_all([Polygon(i) for i in holes])
if isinstance(holes, MultiPolygon):
holes = [i.boundary for i in list(holes.geoms)]
else:
Expand Down

0 comments on commit bbe91a2

Please sign in to comment.