Skip to content

Commit 96bf9a0

Browse files
committed
re-add orca, add deprecation warnings for orca and kaleido-v0 (exact text TBD)
1 parent 89209ad commit 96bf9a0

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

plotly/io/_kaleido.py

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pathlib import Path
44
import importlib.metadata as importlib_metadata
55
from packaging.version import Version
6-
import tempfile
6+
import warnings
77

88
import plotly
99
from plotly.io._utils import validate_coerce_fig_to_dict
@@ -91,6 +91,55 @@ def to_image(
9191
The image data
9292
"""
9393

94+
# Handle engine
95+
# -------------
96+
if engine is not None:
97+
warnings.warn(
98+
"The 'engine' parameter is deprecated and will be removed in a future version.",
99+
DeprecationWarning,
100+
)
101+
engine = "auto"
102+
103+
if engine == "auto":
104+
if kaleido_available:
105+
# Default to kaleido if available
106+
engine = "kaleido"
107+
else:
108+
# See if orca is available
109+
from ._orca import validate_executable
110+
111+
try:
112+
validate_executable()
113+
engine = "orca"
114+
except:
115+
# If orca not configured properly, make sure we display the error
116+
# message advising the installation of kaleido
117+
engine = "kaleido"
118+
119+
if engine == "orca":
120+
warnings.warn(
121+
"Support for the 'orca' engine is deprecated and will be removed in a future version. "
122+
"Please use the 'kaleido' engine instead.",
123+
DeprecationWarning,
124+
)
125+
# Fall back to legacy orca image export path
126+
from ._orca import to_image as to_image_orca
127+
128+
return to_image_orca(
129+
fig,
130+
format=format,
131+
width=width,
132+
height=height,
133+
scale=scale,
134+
validate=validate,
135+
)
136+
elif engine != "kaleido":
137+
raise ValueError(
138+
"Invalid image export engine specified: {engine}".format(
139+
engine=repr(engine)
140+
)
141+
)
142+
94143
# Raise informative error message if Kaleido is not installed
95144
if not kaleido_available:
96145
raise ValueError(
@@ -119,6 +168,11 @@ def to_image(
119168
)
120169
else:
121170
# Kaleido v0
171+
warnings.warn(
172+
"Support for kaleido v0 is deprecated and will be removed in a future version. "
173+
"Please upgrade to kaleido v1 by running `pip install kaleido>=1.0.0`.",
174+
DeprecationWarning,
175+
)
122176
img_bytes = scope.transform(
123177
fig_dict, format=format, width=width, height=height, scale=scale
124178
)
@@ -320,6 +374,11 @@ def full_figure_for_development(fig, warn=True, as_dict=False):
320374
fig = json.loads(bytes.decode("utf-8"))
321375
else:
322376
# Kaleido v0
377+
warnings.warn(
378+
"Support for kaleido v0 is deprecated and will be removed in a future version. "
379+
"Please upgrade to kaleido v1 by running `pip install kaleido>=1.0.0`.",
380+
DeprecationWarning,
381+
)
323382
fig = json.loads(scope.transform(fig, format="json").decode("utf-8"))
324383

325384
if as_dict:

0 commit comments

Comments
 (0)