Skip to content

Commit f7cbc8a

Browse files
authored
Merge branch 'plotly:master' into reno
2 parents 61cbd99 + 48c931e commit f7cbc8a

4 files changed

Lines changed: 51 additions & 1 deletion

File tree

src/py/CHANGELOG.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
Unreleased
2+
- Add warning if using incompatible Plotly version
3+
14
v1.0.0rc15
25
- BUG: Add regex sanitization for auto-filename generation
36
- Further santiize title to filename conversion

src/py/kaleido/_utils.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import asyncio
22
import traceback
3+
import warnings
34
from 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

613
async 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+
1254
class ErrorEntry:
1355
"""A simple object to record errors and context."""
1456

src/py/kaleido/kaleido.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@
1616
from ._fig_tools import _is_figurish, build_fig_spec
1717
from ._kaleido_tab import _KaleidoTab
1818
from ._page_generator import PageGenerator
19-
from ._utils import ErrorEntry
19+
from ._utils import ErrorEntry, warn_incompatible_plotly
2020

2121
_logger = logistro.getLogger(__name__)
2222

23+
# Show a warning if the installed Plotly version
24+
# is incompatible with this version of Kaleido
25+
warn_incompatible_plotly()
26+
2327

2428
def _make_printer(name):
2529
"""Create event printer for generic events. Helper function."""

src/py/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ dependencies = [
2929
"choreographer>=1.0.5",
3030
"logistro>=1.0.8",
3131
"orjson>=3.10.15",
32+
"packaging",
3233
]
3334

3435
[project.urls]

0 commit comments

Comments
 (0)