Skip to content

Commit 154cd0d

Browse files
authored
Add pass through kopts dict for kaleido args (#316)
* Add pass through kopts dict for kaleido args * Update CHANGELOG * Remove separate n arg entirely * Add NoneType check to dict destruct * Add kopts to calc_fig
1 parent 7821a8e commit 154cd0d

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

src/py/CHANGELOG.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
v1.0.0rc12
2+
- Add `kopts` args to top-level shortcuts to pass args to `Kaleido(**kopts)`
13
v1.0.0rc11
24
- Write mocker tool to parameterize opts in tests
35
- Crop page to pdf size

src/py/kaleido/__init__.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,25 @@ async def calc_fig(
3333
opts=None,
3434
*,
3535
topojson=None,
36+
kopts=None,
3637
):
3738
"""
3839
Return binary for plotly figure.
3940
4041
A convenience wrapper for `Kaleido.calc_fig()` which starts a `Kaleido` and
4142
executes the `calc_fig()`.
43+
It takes an additional argument, `kopts`, a dictionary of arguments to pass
44+
to the kaleido process. See the `kaleido.Kaleido` docs. However,
45+
`calc_fig()` will never use more than one processor, so any `n` value will
46+
be overridden.
47+
4248
4349
See documentation for `Kaleido.calc_fig()`.
4450
4551
"""
46-
async with Kaleido(n=1) as k:
52+
kopts = kopts or {}
53+
kopts["n"] = 1
54+
async with Kaleido(**kopts) as k:
4755
return await k.calc_fig(
4856
fig,
4957
path=path,
@@ -60,20 +68,21 @@ async def write_fig( # noqa: PLR0913 (too many args, complexity)
6068
topojson=None,
6169
error_log=None,
6270
profiler=None,
63-
n=1,
71+
kopts=None,
6472
):
6573
"""
6674
Write a plotly figure(s) to a file.
6775
6876
A convenience wrapper for `Kaleido.write_fig()` which starts a `Kaleido` and
6977
executes the `write_fig()`.
70-
It takes one additional argument, `n`, which can be used to set the number
71-
of processes.
78+
It takes an additional argument, `kopts`, a dictionary of arguments to pass
79+
to the kaleido process. See the `kaleido.Kaleido` docs.
80+
7281
73-
See documentation for `Kaleido.write_fig()`.
82+
See documentation for `Kaleido.write_fig()` for the other arguments.
7483
7584
"""
76-
async with Kaleido(n=n) as k:
85+
async with Kaleido(**(kopts or {})) as k:
7786
await k.write_fig(
7887
fig,
7988
path=path,
@@ -89,20 +98,21 @@ async def write_fig_from_object(
8998
*,
9099
error_log=None,
91100
profiler=None,
92-
n=1,
101+
kopts=None,
93102
):
94103
"""
95104
Write a plotly figure(s) to a file.
96105
97106
A convenience wrapper for `Kaleido.write_fig_from_object()` which starts a
98107
`Kaleido` and executes the `write_fig_from_object()`
99-
It takes one additional argument, `n`, which can be used to set the number
100-
of processes.
108+
It takes an additional argument, `kopts`, a dictionary of arguments to pass
109+
to the kaleido process. See the `kaleido.Kaleido` docs.
101110
102-
See documentation for `Kaleido.write_fig_from_object()`.
111+
See documentation for `Kaleido.write_fig_from_object()` for the other
112+
arguments.
103113
104114
"""
105-
async with Kaleido(n=n) as k:
115+
async with Kaleido(**(kopts or {})) as k:
106116
await k.write_fig_from_object(
107117
generator,
108118
error_log=error_log,

0 commit comments

Comments
 (0)