11
11
from plotly .io ._defaults import defaults
12
12
13
13
ENGINE_SUPPORT_TIMELINE = "September 2025"
14
+ ENABLE_KALEIDO_V0_DEPRECATION_WARNINGS = False
14
15
15
16
PLOTLY_GET_CHROME_ERROR_MSG = """
16
17
23
24
24
25
"""
25
26
26
-
27
- # TODO: Remove --pre flag once Kaleido v1 full release is available
28
27
KALEIDO_DEPRECATION_MSG = f"""
29
28
Support for Kaleido versions less than 1.0.0 is deprecated and will be removed after { ENGINE_SUPPORT_TIMELINE } .
30
29
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:
95
94
from kaleido .scopes .plotly import PlotlyScope
96
95
97
96
# Show a deprecation warning if the old method of setting defaults is used
98
- class PlotlyScopeWithDeprecationWarnings (PlotlyScope ):
97
+ class PlotlyScopeWrapper (PlotlyScope ):
99
98
def __setattr__ (self , name , value ):
100
99
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
+ )
106
106
super ().__setattr__ (name , value )
107
107
108
108
def __getattr__ (self , name ):
109
109
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
+ )
115
116
return super ().__getattr__ (name )
116
117
117
118
# Ensure the new method of setting defaults is backwards compatible with Kaleido v0
@@ -131,7 +132,7 @@ def __setattr__(self, name, value):
131
132
setattr (self ._scope , name , value )
132
133
super ().__setattr__ (name , value )
133
134
134
- scope = PlotlyScopeWithDeprecationWarnings ()
135
+ scope = PlotlyScopeWrapper ()
135
136
defaults = DefaultsBackwardsCompatible (scope )
136
137
# Compute absolute path to the 'plotly/package_data/' directory
137
138
root_dir = os .path .dirname (os .path .abspath (plotly .__file__ ))
@@ -150,30 +151,32 @@ def __setattr__(self, name, value):
150
151
import kaleido
151
152
152
153
# Show a deprecation warning if the old method of setting defaults is used
153
- class DefaultsDeprecationWarning :
154
+ class DefaultsWrapper :
154
155
def __getattr__ (self , name ):
155
156
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
+ )
161
163
return getattr (defaults , name )
162
164
else :
163
165
raise AttributeError (bad_attribute_error_msg_func (name ))
164
166
165
167
def __setattr__ (self , name , value ):
166
168
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
+ )
172
175
setattr (defaults , name , value )
173
176
else :
174
177
raise AttributeError (bad_attribute_error_msg_func (name ))
175
178
176
- scope = DefaultsDeprecationWarning ()
179
+ scope = DefaultsWrapper ()
177
180
178
181
except ImportError as e :
179
182
PlotlyScope = None
@@ -296,7 +299,8 @@ def to_image(
296
299
297
300
# Handle engine
298
301
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 )
300
304
else :
301
305
engine = "auto"
302
306
@@ -317,7 +321,8 @@ def to_image(
317
321
engine = "kaleido"
318
322
319
323
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 )
321
326
# Fall back to legacy orca image export path
322
327
from ._orca import to_image as to_image_orca
323
328
@@ -385,7 +390,8 @@ def to_image(
385
390
386
391
else :
387
392
# 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 )
389
395
img_bytes = scope .transform (
390
396
fig_dict , format = format , width = width , height = height , scale = scale
391
397
)
@@ -476,16 +482,17 @@ def write_image(
476
482
None
477
483
"""
478
484
# 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 )
489
496
490
497
# Try to cast `file` as a pathlib object `path`.
491
498
path = as_path_object (file )
@@ -748,11 +755,12 @@ def full_figure_for_development(
748
755
fig = json .loads (bytes .decode ("utf-8" ))
749
756
else :
750
757
# 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
+ )
756
764
fig = json .loads (scope .transform (fig , format = "json" ).decode ("utf-8" ))
757
765
758
766
if as_dict :
0 commit comments