Skip to content

Commit b91887b

Browse files
committed
disable kaleido and orca deprecation warnings
1 parent 058eed2 commit b91887b

File tree

3 files changed

+82
-69
lines changed

3 files changed

+82
-69
lines changed

plotly/basedatatypes.py

+29-25
Original file line numberDiff line numberDiff line change
@@ -3794,23 +3794,25 @@ def to_image(self, *args, **kwargs):
37943794
from plotly.io.kaleido import (
37953795
kaleido_available,
37963796
kaleido_major,
3797+
ENABLE_KALEIDO_V0_DEPRECATION_WARNINGS,
37973798
KALEIDO_DEPRECATION_MSG,
37983799
ORCA_DEPRECATION_MSG,
37993800
ENGINE_PARAM_DEPRECATION_MSG,
38003801
)
38013802

3802-
if (
3803-
kwargs.get("engine", None) in {None, "auto", "kaleido"}
3804-
and kaleido_available()
3805-
and kaleido_major() < 1
3806-
):
3807-
warnings.warn(KALEIDO_DEPRECATION_MSG, DeprecationWarning, stacklevel=2)
3808-
if kwargs.get("engine", None) == "orca":
3809-
warnings.warn(ORCA_DEPRECATION_MSG, DeprecationWarning, stacklevel=2)
3810-
if kwargs.get("engine", None):
3811-
warnings.warn(
3812-
ENGINE_PARAM_DEPRECATION_MSG, DeprecationWarning, stacklevel=2
3813-
)
3803+
if ENABLE_KALEIDO_V0_DEPRECATION_WARNINGS:
3804+
if (
3805+
kwargs.get("engine", None) in {None, "auto", "kaleido"}
3806+
and kaleido_available()
3807+
and kaleido_major() < 1
3808+
):
3809+
warnings.warn(KALEIDO_DEPRECATION_MSG, DeprecationWarning, stacklevel=2)
3810+
if kwargs.get("engine", None) == "orca":
3811+
warnings.warn(ORCA_DEPRECATION_MSG, DeprecationWarning, stacklevel=2)
3812+
if kwargs.get("engine", None):
3813+
warnings.warn(
3814+
ENGINE_PARAM_DEPRECATION_MSG, DeprecationWarning, stacklevel=2
3815+
)
38143816

38153817
return pio.to_image(self, *args, **kwargs)
38163818

@@ -3887,24 +3889,26 @@ def write_image(self, *args, **kwargs):
38873889
from plotly.io.kaleido import (
38883890
kaleido_available,
38893891
kaleido_major,
3892+
ENABLE_KALEIDO_V0_DEPRECATION_WARNINGS,
38903893
KALEIDO_DEPRECATION_MSG,
38913894
ORCA_DEPRECATION_MSG,
38923895
ENGINE_PARAM_DEPRECATION_MSG,
38933896
)
38943897

3895-
if (
3896-
kwargs.get("engine", None) in {None, "auto", "kaleido"}
3897-
and kaleido_available()
3898-
and kaleido_major() < 1
3899-
):
3900-
warnings.warn(KALEIDO_DEPRECATION_MSG, DeprecationWarning, stacklevel=2)
3901-
if kwargs.get("engine", None) == "orca":
3902-
warnings.warn(ORCA_DEPRECATION_MSG, DeprecationWarning, stacklevel=2)
3903-
if kwargs.get("engine", None):
3904-
warnings.warn(
3905-
ENGINE_PARAM_DEPRECATION_MSG, DeprecationWarning, stacklevel=2
3906-
)
3907-
return pio.write_image(self, *args, **kwargs)
3898+
if ENABLE_KALEIDO_V0_DEPRECATION_WARNINGS:
3899+
if (
3900+
kwargs.get("engine", None) in {None, "auto", "kaleido"}
3901+
and kaleido_available()
3902+
and kaleido_major() < 1
3903+
):
3904+
warnings.warn(KALEIDO_DEPRECATION_MSG, DeprecationWarning, stacklevel=2)
3905+
if kwargs.get("engine", None) == "orca":
3906+
warnings.warn(ORCA_DEPRECATION_MSG, DeprecationWarning, stacklevel=2)
3907+
if kwargs.get("engine", None):
3908+
warnings.warn(
3909+
ENGINE_PARAM_DEPRECATION_MSG, DeprecationWarning, stacklevel=2
3910+
)
3911+
return pio.write_image(self, *args, **kwargs)
39083912

39093913
# Static helpers
39103914
# --------------

plotly/io/_kaleido.py

+52-44
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from plotly.io._defaults import defaults
1212

1313
ENGINE_SUPPORT_TIMELINE = "September 2025"
14+
ENABLE_KALEIDO_V0_DEPRECATION_WARNINGS = False
1415

1516
PLOTLY_GET_CHROME_ERROR_MSG = """
1617
@@ -23,8 +24,6 @@
2324
2425
"""
2526

26-
27-
# TODO: Remove --pre flag once Kaleido v1 full release is available
2827
KALEIDO_DEPRECATION_MSG = f"""
2928
Support for Kaleido versions less than 1.0.0 is deprecated and will be removed after {ENGINE_SUPPORT_TIMELINE}.
3029
Please upgrade Kaleido to version 1.0.0 or greater (`pip install 'kaleido>=1.0.0'` or `pip install 'plotly[kaleido]'`).
@@ -95,23 +94,25 @@ def kaleido_major() -> int:
9594
from kaleido.scopes.plotly import PlotlyScope
9695

9796
# Show a deprecation warning if the old method of setting defaults is used
98-
class PlotlyScopeWithDeprecationWarnings(PlotlyScope):
97+
class PlotlyScopeWrapper(PlotlyScope):
9998
def __setattr__(self, name, value):
10099
if name in defaults.__dict__:
101-
warnings.warn(
102-
kaleido_scope_default_warning_func(name),
103-
DeprecationWarning,
104-
stacklevel=2,
105-
)
100+
if ENABLE_KALEIDO_V0_DEPRECATION_WARNINGS:
101+
warnings.warn(
102+
kaleido_scope_default_warning_func(name),
103+
DeprecationWarning,
104+
stacklevel=2,
105+
)
106106
super().__setattr__(name, value)
107107

108108
def __getattr__(self, name):
109109
if hasattr(defaults, name):
110-
warnings.warn(
111-
kaleido_scope_default_warning_func(name),
112-
DeprecationWarning,
113-
stacklevel=2,
114-
)
110+
if ENABLE_KALEIDO_V0_DEPRECATION_WARNINGS:
111+
warnings.warn(
112+
kaleido_scope_default_warning_func(name),
113+
DeprecationWarning,
114+
stacklevel=2,
115+
)
115116
return super().__getattr__(name)
116117

117118
# Ensure the new method of setting defaults is backwards compatible with Kaleido v0
@@ -131,7 +132,7 @@ def __setattr__(self, name, value):
131132
setattr(self._scope, name, value)
132133
super().__setattr__(name, value)
133134

134-
scope = PlotlyScopeWithDeprecationWarnings()
135+
scope = PlotlyScopeWrapper()
135136
defaults = DefaultsBackwardsCompatible(scope)
136137
# Compute absolute path to the 'plotly/package_data/' directory
137138
root_dir = os.path.dirname(os.path.abspath(plotly.__file__))
@@ -150,30 +151,32 @@ def __setattr__(self, name, value):
150151
import kaleido
151152

152153
# Show a deprecation warning if the old method of setting defaults is used
153-
class DefaultsDeprecationWarning:
154+
class DefaultsWrapper:
154155
def __getattr__(self, name):
155156
if hasattr(defaults, name):
156-
warnings.warn(
157-
kaleido_scope_default_warning_func(name),
158-
DeprecationWarning,
159-
stacklevel=2,
160-
)
157+
if ENABLE_KALEIDO_V0_DEPRECATION_WARNINGS:
158+
warnings.warn(
159+
kaleido_scope_default_warning_func(name),
160+
DeprecationWarning,
161+
stacklevel=2,
162+
)
161163
return getattr(defaults, name)
162164
else:
163165
raise AttributeError(bad_attribute_error_msg_func(name))
164166

165167
def __setattr__(self, name, value):
166168
if hasattr(defaults, name):
167-
warnings.warn(
168-
kaleido_scope_default_warning_func(name),
169-
DeprecationWarning,
170-
stacklevel=2,
171-
)
169+
if ENABLE_KALEIDO_V0_DEPRECATION_WARNINGS:
170+
warnings.warn(
171+
kaleido_scope_default_warning_func(name),
172+
DeprecationWarning,
173+
stacklevel=2,
174+
)
172175
setattr(defaults, name, value)
173176
else:
174177
raise AttributeError(bad_attribute_error_msg_func(name))
175178

176-
scope = DefaultsDeprecationWarning()
179+
scope = DefaultsWrapper()
177180

178181
except ImportError as e:
179182
PlotlyScope = None
@@ -296,7 +299,8 @@ def to_image(
296299

297300
# Handle engine
298301
if engine is not None:
299-
warnings.warn(ENGINE_PARAM_DEPRECATION_MSG, DeprecationWarning, stacklevel=2)
302+
if ENABLE_KALEIDO_V0_DEPRECATION_WARNINGS:
303+
warnings.warn(ENGINE_PARAM_DEPRECATION_MSG, DeprecationWarning, stacklevel=2)
300304
else:
301305
engine = "auto"
302306

@@ -317,7 +321,8 @@ def to_image(
317321
engine = "kaleido"
318322

319323
if engine == "orca":
320-
warnings.warn(ORCA_DEPRECATION_MSG, DeprecationWarning, stacklevel=2)
324+
if ENABLE_KALEIDO_V0_DEPRECATION_WARNINGS:
325+
warnings.warn(ORCA_DEPRECATION_MSG, DeprecationWarning, stacklevel=2)
321326
# Fall back to legacy orca image export path
322327
from ._orca import to_image as to_image_orca
323328

@@ -385,7 +390,8 @@ def to_image(
385390

386391
else:
387392
# Kaleido v0
388-
warnings.warn(KALEIDO_DEPRECATION_MSG, DeprecationWarning, stacklevel=2)
393+
if ENABLE_KALEIDO_V0_DEPRECATION_WARNINGS:
394+
warnings.warn(KALEIDO_DEPRECATION_MSG, DeprecationWarning, stacklevel=2)
389395
img_bytes = scope.transform(
390396
fig_dict, format=format, width=width, height=height, scale=scale
391397
)
@@ -476,16 +482,17 @@ def write_image(
476482
None
477483
"""
478484
# Show Kaleido deprecation warning if needed
479-
if (
480-
engine in {None, "auto", "kaleido"}
481-
and kaleido_available()
482-
and kaleido_major() < 1
483-
):
484-
warnings.warn(KALEIDO_DEPRECATION_MSG, DeprecationWarning, stacklevel=2)
485-
if engine == "orca":
486-
warnings.warn(ORCA_DEPRECATION_MSG, DeprecationWarning, stacklevel=2)
487-
if engine not in {None, "auto"}:
488-
warnings.warn(ENGINE_PARAM_DEPRECATION_MSG, DeprecationWarning, stacklevel=2)
485+
if ENABLE_KALEIDO_V0_DEPRECATION_WARNINGS:
486+
if (
487+
engine in {None, "auto", "kaleido"}
488+
and kaleido_available()
489+
and kaleido_major() < 1
490+
):
491+
warnings.warn(KALEIDO_DEPRECATION_MSG, DeprecationWarning, stacklevel=2)
492+
if engine == "orca":
493+
warnings.warn(ORCA_DEPRECATION_MSG, DeprecationWarning, stacklevel=2)
494+
if engine not in {None, "auto"}:
495+
warnings.warn(ENGINE_PARAM_DEPRECATION_MSG, DeprecationWarning, stacklevel=2)
489496

490497
# Try to cast `file` as a pathlib object `path`.
491498
path = as_path_object(file)
@@ -748,11 +755,12 @@ def full_figure_for_development(
748755
fig = json.loads(bytes.decode("utf-8"))
749756
else:
750757
# Kaleido v0
751-
warnings.warn(
752-
f"Support for Kaleido versions less than 1.0.0 is deprecated and will be removed after {ENGINE_SUPPORT_TIMELINE}. "
753-
+ "Please upgrade Kaleido to version 1.0.0 or greater (`pip install 'kaleido>=1.0.0'`).",
754-
DeprecationWarning,
755-
)
758+
if ENABLE_KALEIDO_V0_DEPRECATION_WARNINGS:
759+
warnings.warn(
760+
f"Support for Kaleido versions less than 1.0.0 is deprecated and will be removed after {ENGINE_SUPPORT_TIMELINE}. "
761+
+ "Please upgrade Kaleido to version 1.0.0 or greater (`pip install 'kaleido>=1.0.0'`).",
762+
DeprecationWarning,
763+
)
756764
fig = json.loads(scope.transform(fig, format="json").decode("utf-8"))
757765

758766
if as_dict:

plotly/io/kaleido.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
scope,
55
kaleido_available,
66
kaleido_major,
7+
ENABLE_KALEIDO_V0_DEPRECATION_WARNINGS,
78
KALEIDO_DEPRECATION_MSG,
89
ORCA_DEPRECATION_MSG,
910
ENGINE_PARAM_DEPRECATION_MSG,

0 commit comments

Comments
 (0)