Skip to content

Commit 4199e8a

Browse files
Merge branch 'master' of github.com:davidangarita1/Kaleido into david/github-action-update-cdn
2 parents 6e428ef + 725729f commit 4199e8a

35 files changed

+3958
-3638
lines changed

.github/workflows/publish_testpypi.yml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,22 @@ on:
99
jobs:
1010
super-test:
1111
strategy:
12-
max-parallel: 2
12+
fail-fast: false
1313
matrix:
1414
os: [ubuntu-latest, windows-latest, macos-latest]
15-
python_v: ['3.8', '3.9', '3.10', '']
15+
python_v: ['3.8', '3.9', '3.10', '3.12', '3.13', '3.14']
1616
# chrome_v: ['-1']
1717
defaults:
1818
run:
1919
working-directory: ./src/py/
2020
name: Build and Test
2121
runs-on: ${{ matrix.os }}
22+
env:
23+
UV_PYTHON: ${{ matrix.python_v }}
2224
steps:
2325
- uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 1
2428
- uses: astral-sh/setup-uv@v5
2529
- name: Install Dependencies
2630
if: ${{ matrix.os == 'ubuntu-latest' }}
@@ -29,10 +33,10 @@ jobs:
2933
# must actually checkout for version determination
3034
- run: git checkout ${{ github.ref_name }}
3135
- run: uv python install ${{ matrix.python_v }}
32-
- run: uv python pin ${{ matrix.python_v }}
33-
if: ${{ matrix.python_v != '' }}
3436
# don't modify sync file! messes up version!
35-
- run: uv sync --all-extras --frozen # does order matter?
37+
- run: uv sync --all-extras --locked --no-sources
38+
- run: git status
39+
- run: git diff --quiet HEAD || { echo "Working tree dirty"; exit 1; }
3640
- run: uv build
3741
- name: Reinstall from wheel
3842
run: >
@@ -80,11 +84,10 @@ jobs:
8084
working-directory: ./src/py/
8185
name: Upload release to TestPyPI
8286
needs: super-test
83-
if: |
84-
always() &&
85-
!cancelled() &&
86-
!failure() &&
87-
startsWith(github.ref, 'refs/tags/')
87+
if: ${{ !cancelled() &&
88+
!failure() &&
89+
github.event_name == 'push' &&
90+
github.run_attempt == 1 }}
8891
runs-on: ubuntu-latest
8992
environment:
9093
name: testpypi

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
run: >
2626
uv sync
2727
--no-sources
28+
--locked
2829
--all-extras
2930
3031
- name: Install google-chrome-for-testing

src/py/.pre-commit-config.yaml

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ default_install_hook_types: [pre-commit, commit-msg]
1414
default_stages: [pre-commit]
1515
repos:
1616
- repo: https://github.com/pre-commit/pre-commit-hooks
17-
rev: v3.2.0
17+
rev: v6.0.0
1818
hooks:
1919
- id: trailing-whitespace
2020
- id: end-of-file-fixer
@@ -25,12 +25,12 @@ repos:
2525
- id: check-toml
2626
- id: debug-statements
2727
- repo: https://github.com/asottile/add-trailing-comma
28-
rev: v3.1.0
28+
rev: v3.2.0
2929
hooks:
3030
- id: add-trailing-comma
3131
- repo: https://github.com/astral-sh/ruff-pre-commit
3232
# Ruff version.
33-
rev: v0.12.10
33+
rev: v0.13.3
3434
hooks:
3535
# Run the linter.
3636
- id: ruff
@@ -40,7 +40,7 @@ repos:
4040
types_or: [python, pyi]
4141
# options: ignore one line things [E701]
4242
- repo: https://github.com/adrienverge/yamllint
43-
rev: v1.35.1
43+
rev: v1.37.1
4444
hooks:
4545
- id: yamllint
4646
name: yamllint
@@ -55,7 +55,7 @@ repos:
5555
}\
5656
}"]
5757
- repo: https://github.com/rhysd/actionlint
58-
rev: v1.7.4
58+
rev: v1.7.7
5959
hooks:
6060
- id: actionlint
6161
name: Lint GitHub Actions workflow files
@@ -76,18 +76,9 @@ repos:
7676
args: [--staged, -c, "general.ignore=B6,T3", --msg-filename]
7777
stages: [commit-msg]
7878
- repo: https://github.com/crate-ci/typos
79-
rev: v1.28.2
79+
rev: v1
8080
hooks:
8181
- id: typos
82-
- repo: https://github.com/markdownlint/markdownlint
83-
rev: v0.13.0
84-
hooks:
85-
- id: markdownlint
86-
name: Markdownlint
87-
description: Run markdownlint on your Markdown files
88-
entry: mdl --rules ~MD026 --style .markdown.rb
89-
language: ruby
90-
files: \.(md|mdown|markdown)$
9182
- repo: https://github.com/Yelp/detect-secrets
9283
rev: v1.5.0
9384
hooks:
@@ -96,3 +87,16 @@ repos:
9687
language: python
9788
entry: detect-secrets-hook
9889
args: ['']
90+
- repo: https://github.com/rvben/rumdl-pre-commit
91+
rev: v0.0.153 # Use the latest release tag
92+
hooks:
93+
- id: rumdl
94+
# To only check (default):
95+
# args: []
96+
# To automatically fix issues:
97+
# args: [--fix]
98+
- repo: https://github.com/RobertCraigie/pyright-python
99+
rev: v1.1.406 # pin a tag; latest as of 2025-10-01
100+
hooks:
101+
- id: pyright
102+
args: ["--project=src/py"]

src/py/CHANGELOG.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
v1.3.0rc0
2+
- Significant refactor, better organization
3+
- `write_fig` and `_from_object` now take an additional argument:
4+
`cancel_on_error: bool, default False`. See docs.
5+
- Unused `path` argument for `calc_fig` was deprecated.
6+
- Fixed race condition where two render tasks would choose the same filename
7+
8+
19
v1.2.0
210
- Try to use plotly JSON encoder instead of default
311

src/py/kaleido/__init__.py

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
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

6567
def 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

7781
async 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

141141
async 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):
174173
def 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

182181
def 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

Comments
 (0)