|
3 | 3 | from pathlib import Path
|
4 | 4 | import importlib.metadata as importlib_metadata
|
5 | 5 | from packaging.version import Version
|
6 |
| -import tempfile |
| 6 | +import warnings |
7 | 7 |
|
8 | 8 | import plotly
|
9 | 9 | from plotly.io._utils import validate_coerce_fig_to_dict
|
@@ -91,6 +91,55 @@ def to_image(
|
91 | 91 | The image data
|
92 | 92 | """
|
93 | 93 |
|
| 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 | + |
94 | 143 | # Raise informative error message if Kaleido is not installed
|
95 | 144 | if not kaleido_available:
|
96 | 145 | raise ValueError(
|
@@ -119,6 +168,11 @@ def to_image(
|
119 | 168 | )
|
120 | 169 | else:
|
121 | 170 | # 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 | + ) |
122 | 176 | img_bytes = scope.transform(
|
123 | 177 | fig_dict, format=format, width=width, height=height, scale=scale
|
124 | 178 | )
|
@@ -320,6 +374,11 @@ def full_figure_for_development(fig, warn=True, as_dict=False):
|
320 | 374 | fig = json.loads(bytes.decode("utf-8"))
|
321 | 375 | else:
|
322 | 376 | # 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 | + ) |
323 | 382 | fig = json.loads(scope.transform(fig, format="json").decode("utf-8"))
|
324 | 383 |
|
325 | 384 | if as_dict:
|
|
0 commit comments