1111from plotly .io ._defaults import defaults
1212
1313ENGINE_SUPPORT_TIMELINE = "September 2025"
14+ ENABLE_KALEIDO_V0_DEPRECATION_WARNINGS = False
1415
1516PLOTLY_GET_CHROME_ERROR_MSG = """
1617
2324
2425"""
2526
26-
27- # TODO: Remove --pre flag once Kaleido v1 full release is available
2827KALEIDO_DEPRECATION_MSG = f"""
2928Support for Kaleido versions less than 1.0.0 is deprecated and will be removed after { ENGINE_SUPPORT_TIMELINE } .
3029Please 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
178181except 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 :
0 commit comments