1919 from pathlib import Path
2020 from typing import Any , TypeVar , Union
2121
22- from ._fig_tools import Figurish , LayoutOpts
22+ from ._utils . fig_tools import Figurish , LayoutOpts
2323
2424 T = TypeVar ("T" )
2525 AnyIterable = Union [AsyncIterable [T ], Iterable [T ]]
2626
27+ from .kaleido import FigureDict
28+
2729__all__ = [
2830 "Kaleido" ,
2931 "PageGenerator" ,
@@ -50,7 +52,7 @@ def start_sync_server(*args: Any, silence_warnings: bool = False, **kwargs: Any)
5052 function will warn you if the server is already running.
5153
5254 This wrapper function takes the exact same arguments as kaleido.Kaleido(),
53- except one extra, `silence_warnings`.
55+ except one extra: `silence_warnings`.
5456
5557 Args:
5658 *args: all arguments `Kaleido()` would take.
@@ -64,19 +66,20 @@ def start_sync_server(*args: Any, silence_warnings: bool = False, **kwargs: Any)
6466
6567def stop_sync_server (* , silence_warnings : bool = False ):
6668 """
67- Stop the kaleido server. It can be restarted. Warns if not started.
69+ Stop the kaleido server. It can be restarted.
70+
71+ This function will warn you if the server is already stopped.
6872
6973 Args:
7074 silence_warnings: (bool, default False): If True, don't emit warning if
71- stopping a server that's not running .
75+ stopping an already stopped server .
7276
7377 """
7478 _global_server .close (silence_warnings = silence_warnings )
7579
7680
7781async def calc_fig (
7882 fig : Figurish ,
79- path : str | None | Path = None ,
8083 opts : LayoutOpts | None = None ,
8184 * ,
8285 topojson : str | None = None ,
@@ -86,22 +89,20 @@ async def calc_fig(
8689 Return binary for plotly figure.
8790
8891 A convenience wrapper for `Kaleido.calc_fig()` which starts a `Kaleido` and
89- executes the `calc_fig()`.
92+ executes `calc_fig()`.
9093 It takes an additional argument, `kopts`, a dictionary of arguments to pass
9194 to the kaleido process. See the `kaleido.Kaleido` docs. However,
9295 `calc_fig()` will never use more than one processor, so any `n` value will
9396 be overridden.
9497
95-
96- See documentation for `Kaleido.calc_fig()`.
98+ See also the documentation for `Kaleido.calc_fig()`.
9799
98100 """
99101 kopts = kopts or {}
100102 kopts ["n" ] = 1 # should we force this?
101103 async with Kaleido (** kopts ) as k :
102104 return await k .calc_fig (
103105 fig ,
104- path = path ,
105106 opts = opts ,
106107 topojson = topojson ,
107108 )
@@ -122,14 +123,13 @@ async def write_fig(
122123 A convenience wrapper for `Kaleido.write_fig()` which starts a `Kaleido` and
123124 executes the `write_fig()`.
124125 It takes an additional argument, `kopts`, a dictionary of arguments to pass
125- to the kaleido process. See the `kaleido.Kaleido` docs.
126-
126+ to the `Kaleido` constructor. See the `kaleido.Kaleido` docs.
127127
128- See documentation for `Kaleido.write_fig()` for the other arguments .
128+ See also the documentation for `Kaleido.write_fig()`.
129129
130130 """
131131 async with Kaleido (** (kopts or {})) as k :
132- await k .write_fig (
132+ return await k .write_fig (
133133 fig ,
134134 path = path ,
135135 opts = opts ,
@@ -139,26 +139,25 @@ async def write_fig(
139139
140140
141141async def write_fig_from_object (
142- generator : AnyIterable , # this could be more specific with []
142+ fig_dicts : FigureDict | AnyIterable [ FigureDict ],
143143 * ,
144144 kopts : dict [str , Any ] | None = None ,
145145 ** kwargs ,
146146):
147147 """
148- Write a plotly figure(s) to a file.
148+ Write a plotly figure(s) to a file specified by a dictionary or iterable of .
149149
150150 A convenience wrapper for `Kaleido.write_fig_from_object()` which starts a
151151 `Kaleido` and executes the `write_fig_from_object()`
152152 It takes an additional argument, `kopts`, a dictionary of arguments to pass
153- to the kaleido process . See the `kaleido.Kaleido` docs.
153+ to the `Kaleido` constructor . See the `kaleido.Kaleido` docs.
154154
155- See documentation for `Kaleido.write_fig_from_object()` for the other
156- arguments.
155+ See also the documentation for `Kaleido.write_fig_from_object()`.
157156
158157 """
159158 async with Kaleido (** (kopts or {})) as k :
160- await k .write_fig_from_object (
161- generator ,
159+ return await k .write_fig_from_object (
160+ fig_dicts ,
162161 ** kwargs ,
163162 )
164163
@@ -174,14 +173,18 @@ def calc_fig_sync(*args: Any, **kwargs: Any):
174173def write_fig_sync (* args : Any , ** kwargs : Any ):
175174 """Call `write_fig` but blocking."""
176175 if _global_server .is_running ():
177- _global_server .call_function ("write_fig" , * args , ** kwargs )
176+ return _global_server .call_function ("write_fig" , * args , ** kwargs )
178177 else :
179- _sync_server .oneshot_async_run (write_fig , args = args , kwargs = kwargs )
178+ return _sync_server .oneshot_async_run (write_fig , args = args , kwargs = kwargs )
180179
181180
182181def write_fig_from_object_sync (* args : Any , ** kwargs : Any ):
183182 """Call `write_fig_from_object` but blocking."""
184183 if _global_server .is_running ():
185- _global_server .call_function ("write_fig_from_object" , * args , ** kwargs )
184+ return _global_server .call_function ("write_fig_from_object" , * args , ** kwargs )
186185 else :
187- _sync_server .oneshot_async_run (write_fig_from_object , args = args , kwargs = kwargs )
186+ return _sync_server .oneshot_async_run (
187+ write_fig_from_object ,
188+ args = args ,
189+ kwargs = kwargs ,
190+ )
0 commit comments