11import asyncio
22import traceback
3+ import warnings
34from functools import partial
5+ from importlib .metadata import PackageNotFoundError , version
6+
7+ import logistro
8+ from packaging .version import Version
9+
10+ _logger = logistro .getLogger (__name__ )
411
512
613async def to_thread (func , * args , ** kwargs ):
@@ -9,6 +16,41 @@ async def to_thread(func, *args, **kwargs):
916 await _loop .run_in_executor (None , fn )
1017
1118
19+ def warn_incompatible_plotly ():
20+ """
21+ Check if installed Plotly version (if any) is compatible with this Kaleido version.
22+
23+ If not, display a warning.
24+ """
25+ try :
26+ min_compatible_plotly_version = Version ("6.1.1" )
27+ installed_plotly_version = Version (version ("plotly" ))
28+ installed_kaleido_version = Version (version ("kaleido" ))
29+ if installed_plotly_version < min_compatible_plotly_version :
30+ warnings .warn (
31+ "\n \n "
32+ f"Warning: You have Plotly version { installed_plotly_version } , "
33+ "which is not compatible with this version of "
34+ f"Kaleido ({ installed_kaleido_version } ).\n \n "
35+ "This means that static image generation (e.g. `fig.write_image()`) "
36+ "will not work.\n \n "
37+ f"Please upgrade Plotly to version { min_compatible_plotly_version } "
38+ "or greater, or downgrade Kaleido to version 0.2.1."
39+ "\n " ,
40+ UserWarning ,
41+ stacklevel = 3 ,
42+ )
43+ except PackageNotFoundError :
44+ # If Plotly is not installed, there's nothing to worry about
45+ pass
46+ # ruff: noqa: BLE001
47+ except Exception as e :
48+ # If another error occurs, log it but do not raise
49+ # Since this compatibility check is just a convenience,
50+ # we don't want to block the whole library if there's an issue
51+ _logger .info ("Error while checking Plotly version." , exc_info = e )
52+
53+
1254class ErrorEntry :
1355 """A simple object to record errors and context."""
1456
0 commit comments