14
14
15
15
PLOTLY_GET_CHROME_ERROR_MSG = """
16
16
17
- Kaleido requires Google Chrome to be installed. Install it by running:
17
+ Kaleido requires Google Chrome to be installed.
18
+
19
+ Either download and install Chrome yourself following Google's instructions for your operating system,
20
+ or install it from your terminal by running:
21
+
18
22
$ plotly_get_chrome
23
+
19
24
"""
20
25
21
26
22
27
# TODO: Remove --pre flag once Kaleido v1 full release is available
23
28
KALEIDO_DEPRECATION_MSG = f"""
24
29
Support for Kaleido versions less than 1.0.0 is deprecated and will be removed after { ENGINE_SUPPORT_TIMELINE } .
25
- Please upgrade Kaleido to version 1.0.0 or greater (`pip install --upgrade --pre kaleido` or `pip install plotly[kaleido]`).
30
+ Please upgrade Kaleido to version 1.0.0 or greater (`pip install ' kaleido>=1.0.0' ` or `pip install ' plotly[kaleido]' `).
26
31
"""
27
32
ORCA_DEPRECATION_MSG = f"""
28
33
Support for the Orca engine is deprecated and will be removed after { ENGINE_SUPPORT_TIMELINE } .
29
- Please install Kaleido (`pip install --upgrade --pre kaleido` or `pip install plotly[kaleido]`) to use the Kaleido engine.
34
+ Please install Kaleido (`pip install ' kaleido>=1.0.0' ` or `pip install ' plotly[kaleido]' `) to use the Kaleido engine.
30
35
"""
31
36
ENGINE_PARAM_DEPRECATION_MSG = f"""
32
37
Support for the 'engine' argument is deprecated and will be removed after { ENGINE_SUPPORT_TIMELINE } .
@@ -110,6 +115,8 @@ def __getattr__(self, name):
110
115
return super ().__getattr__ (name )
111
116
112
117
# Ensure the new method of setting defaults is backwards compatible with Kaleido v0
118
+ # DefaultsBackwardsCompatible sets the attributes on `scope` object at the same time
119
+ # as they are set on the `defaults` object
113
120
class DefaultsBackwardsCompatible (defaults .__class__ ):
114
121
def __init__ (self , scope ):
115
122
self ._scope = scope
@@ -267,7 +274,7 @@ def to_image(
267
274
less than 1.0 will decrease the image resolution.
268
275
269
276
If not specified, will default to:
270
- - `plotly.io.defaults.default_scale` if engine is "kaliedo "
277
+ - `plotly.io.defaults.default_scale` if engine is "kaleido "
271
278
- `plotly.io.orca.config.default_scale` if engine is "orca" (deprecated)
272
279
273
280
validate: bool
@@ -329,9 +336,10 @@ def to_image(
329
336
if not kaleido_available ():
330
337
raise ValueError (
331
338
"""
332
- Image export using the "kaleido" engine requires the kaleido package,
339
+ Image export using the "kaleido" engine requires the Kaleido package,
333
340
which can be installed using pip:
334
- $ pip install -U kaleido
341
+
342
+ $ pip install --upgrade kaleido
335
343
"""
336
344
)
337
345
@@ -348,9 +356,11 @@ def to_image(
348
356
EPS export is not supported by Kaleido v1. Please use SVG or PDF instead.
349
357
You can also downgrade to Kaleido v0, but support for Kaleido v0 will be removed after { ENGINE_SUPPORT_TIMELINE } .
350
358
To downgrade to Kaleido v0, run:
351
- $ pip install kaleido<1.0.0
359
+ $ pip install ' kaleido<1.0.0'
352
360
"""
353
361
)
362
+ from kaleido .errors import ChromeNotFoundError
363
+
354
364
try :
355
365
# TODO: Refactor to make it possible to use a shared Kaleido instance here
356
366
img_bytes = kaleido .calc_fig_sync (
@@ -362,9 +372,13 @@ def to_image(
362
372
scale = scale or defaults .default_scale ,
363
373
),
364
374
topojson = defaults .topojson ,
365
- # mathjax=Path(defaults.mathjax).as_uri() if defaults.mathjax else None,
375
+ kopts = dict (
376
+ mathjax = defaults .mathjax ,
377
+ )
378
+ if defaults .mathjax
379
+ else None ,
366
380
)
367
- except kaleido . errors . ChromeNotFoundError :
381
+ except ChromeNotFoundError :
368
382
raise RuntimeError (PLOTLY_GET_CHROME_ERROR_MSG )
369
383
370
384
else :
@@ -583,18 +597,20 @@ def write_images(
583
597
if not kaleido_available ():
584
598
raise ValueError (
585
599
"""
586
- The `write_images()` function requires the kaleido package,
600
+ The `write_images()` function requires the Kaleido package,
587
601
which can be installed using pip:
588
- $ pip install -U kaleido
602
+
603
+ $ pip install --upgrade kaleido
589
604
"""
590
605
)
591
606
elif kaleido_major () < 1 :
592
607
raise ValueError (
593
608
f"""
594
609
You have Kaleido version { Version (importlib_metadata .version ("kaleido" ))} installed.
595
- The `write_images()` function requires the kaleido package version 1 or greater,
610
+ The `write_images()` function requires the Kaleido package version 1.0.0 or greater,
596
611
which can be installed using pip:
597
- $ pip install -U 'kaleido>=1.0.0'
612
+
613
+ $ pip install 'kaleido>=1.0.0'
598
614
"""
599
615
)
600
616
@@ -621,24 +637,32 @@ def write_images(
621
637
# has already been cast to a Path object.
622
638
# Also insert defaults for any missing arguments as needed
623
639
kaleido_specs = [
624
- {
625
- " fig" : d ["fig" ],
626
- " path" : d ["file" ],
627
- " opts" : dict (
640
+ dict (
641
+ fig = d ["fig" ],
642
+ path = d ["file" ],
643
+ opts = dict (
628
644
format = infer_format (d ["file" ], d ["format" ]) or defaults .default_format ,
629
645
width = d ["width" ] or defaults .default_width ,
630
646
height = d ["height" ] or defaults .default_height ,
631
647
scale = d ["scale" ] or defaults .default_scale ,
632
648
),
633
- "topojson" : defaults .topojson ,
634
- # "mathjax": Path(defaults.mathjax).as_uri() if defaults.mathjax else None,
635
- }
649
+ topojson = defaults .topojson ,
650
+ )
636
651
for d in arg_dicts
637
652
]
638
653
654
+ from kaleido .errors import ChromeNotFoundError
655
+
639
656
try :
640
- kaleido .write_fig_from_object_sync (kaleido_specs )
641
- except kaleido .errors .ChromeNotFoundError :
657
+ kaleido .write_fig_from_object_sync (
658
+ kaleido_specs ,
659
+ kopts = dict (
660
+ mathjax = defaults .mathjax ,
661
+ )
662
+ if defaults .mathjax
663
+ else None ,
664
+ )
665
+ except ChromeNotFoundError :
642
666
raise RuntimeError (PLOTLY_GET_CHROME_ERROR_MSG )
643
667
644
668
@@ -676,9 +700,10 @@ def full_figure_for_development(
676
700
if not kaleido_available ():
677
701
raise ValueError (
678
702
"""
679
- Full figure generation requires the kaleido package,
703
+ Full figure generation requires the Kaleido package,
680
704
which can be installed using pip:
681
- $ pip install -U kaleido
705
+
706
+ $ pip install --upgrade kaleido
682
707
"""
683
708
)
684
709
@@ -700,7 +725,7 @@ def full_figure_for_development(
700
725
# Kaleido v0
701
726
warnings .warn (
702
727
f"Support for Kaleido versions less than 1.0.0 is deprecated and will be removed after { ENGINE_SUPPORT_TIMELINE } . "
703
- + "Please upgrade Kaleido to version 1.0.0 or greater (`pip install --upgrade kaleido`)." ,
728
+ + "Please upgrade Kaleido to version 1.0.0 or greater (`pip install ' kaleido>=1.0.0' `)." ,
704
729
DeprecationWarning ,
705
730
)
706
731
fig = json .loads (scope .transform (fig , format = "json" ).decode ("utf-8" ))
@@ -720,9 +745,10 @@ def get_chrome() -> None:
720
745
defined in pyproject.toml
721
746
"""
722
747
if not kaleido_available () or kaleido_major () < 1 :
723
- raise ValueError (
724
- "This command requires Kaleido v1.0.0 or greater. Install it using `pip install kaleido`."
725
- )
748
+ raise ValueError ("""
749
+ This command requires Kaleido v1.0.0 or greater.
750
+ Install it using `pip install 'kaleido>=1.0.0'` or `pip install 'plotly[kaleido]'`."
751
+ """ )
726
752
import sys
727
753
728
754
cli_yes = len (sys .argv ) > 1 and sys .argv [1 ] == "-y"
0 commit comments