Skip to content

Commit d9d5193

Browse files
authored
Adapt for python 38 (#245)
* Adapt for python 38 * Remove index from testing * Fix mockers --input arg * Turn generator to list in mocker * Complete forgotten await * Force utf-8 encoding for jsons * Add tests for publishing
1 parent d4664e3 commit d9d5193

File tree

9 files changed

+267
-39
lines changed

9 files changed

+267
-39
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# .github/workflows/publish_testpypi.yml
2+
---
3+
name: test-n-build
4+
on:
5+
push:
6+
tags:
7+
- v*
8+
jobs:
9+
super-test:
10+
strategy:
11+
max-parallel: 2
12+
matrix:
13+
os: [ubuntu-latest, windows-latest, macos-latest]
14+
python_v: ['3.8', '3.9', '3.10', '']
15+
chrome_v: ['-1']
16+
name: Build and Test
17+
runs-on: ${{ matrix.os }}
18+
steps:
19+
- uses: actions/checkout@v4
20+
- uses: astral-sh/setup-uv@v4
21+
- name: Install Dependencies
22+
if: ${{ matrix.os == 'ubuntu-latest' }}
23+
run: sudo apt-get update && sudo apt-get install xvfb
24+
timeout-minutes: 1
25+
# must actually checkout for version determination
26+
- run: git checkout ${{ github.ref_name }}
27+
- run: uv python install ${{ matrix.python_v }}
28+
- run: uv python pin ${{ matrix.python_v }}
29+
if: ${{ matrix.python_v != '' }}
30+
# don't modify sync file! messes up version!
31+
- run: uv sync --no-sources --all-extras --frozen # does order matter?
32+
- run: uv build
33+
- name: Reinstall from wheel
34+
run: >
35+
uv pip install dist/choreographer-$(uv
36+
run --no-sync --with setuptools-git-versioning
37+
setuptools-git-versioning)-py3-none-any.whl
38+
- run: uv run --no-sync choreo_get_chrome -v --i ${{ matrix.chrome_v }}
39+
- name: Diagnose
40+
run: uv run --no-sync choreo_diagnose --no-run
41+
42+
- name: Test mocker
43+
run: >
44+
uv run
45+
--no-sources kaleido_mocker
46+
--random 100
47+
--logistro-level INFO
48+
49+
- name: Test
50+
if: ${{ ! runner.debug && matrix.os != 'ubuntu-latest' }}
51+
run: uv run --no-sync poe test
52+
timeout-minutes: 8
53+
54+
- name: Test (Linux)
55+
if: ${{ ! runner.debug && matrix.os == 'ubuntu-latest' }}
56+
run: xvfb-run uv run --no-sync poe test
57+
timeout-minutes: 8
58+
59+
- name: Test (Debug)
60+
if: runner.debug
61+
run: uv run --no-sync poe debug-test
62+
timeout-minutes: 20
63+
64+
- name: Test (Debug, Linux)
65+
if: ${{ runner.debug && matrix.os == 'ubuntu-latest' }}
66+
run: xvfb-run uv run --no-sync poe debug-test
67+
timeout-minutes: 8
68+
69+
testpypi-publish:
70+
name: Upload release to TestPyPI
71+
needs: super-test
72+
if: always() && !cancelled() && !failure()
73+
runs-on: ubuntu-latest
74+
environment:
75+
name: testpypi
76+
url: https://test.pypi.org/p/choreographer
77+
# Signs this workflow so pypi trusts it
78+
permissions:
79+
id-token: write
80+
steps:
81+
- name: Checkout
82+
uses: actions/checkout@v4
83+
- uses: astral-sh/setup-uv@v4
84+
- uses: actions/setup-python@v5
85+
with:
86+
python-version-file: "pyproject.toml"
87+
- run: git checkout ${{ github.ref_name }}
88+
- run: uv sync --no-sources --frozen --all-extras
89+
- run: uv build
90+
- name: Publish package distributions to PyPI
91+
uses: pypa/gh-action-pypi-publish@release/v1
92+
with:
93+
repository-url: https://test.pypi.org/legacy/.

.github/workflows/test.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ jobs:
2424
- name: Install dependencies
2525
run: >
2626
uv sync
27-
--index-strategy=unsafe-first-match
2827
--no-sources
2928
--all-extras
3029

src/py/.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.8

src/py/kaleido/_fig_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def build_fig_spec(fig, path, opts):
9191
path = Path(path)
9292

9393
if path and path.suffix and not opts.get("format"):
94-
opts["format"] = path.suffix.removeprefix(".")
94+
opts["format"] = path.suffix.lstrip(".")
9595

9696
spec = to_spec(fig, opts)
9797

src/py/kaleido/_mocker.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,20 @@ def _get_jsons_in_paths(path: str | Path) -> list[Path]:
2727
path = Path(path) if isinstance(path, str) else path
2828

2929
if path.is_dir():
30-
return [path / a for a in path.glob("*.json")]
31-
else:
30+
_logger.info(f"Input is path {path}")
31+
return list(path.glob("*.json"))
32+
elif path.is_file():
33+
_logger.info(f"Input is file {path}")
3234
return [path]
35+
else:
36+
raise TypeError("--input must be file or directory")
3337

3438

3539
def _load_figures_from_paths(paths: list[Path]):
3640
# Set json
3741
for path in paths:
3842
if path.is_file():
39-
with path.open() as file:
43+
with path.open(encoding="utf-8") as file:
4044
figure = orjson.loads(file.read())
4145
_logger.info(f"Yielding {path.stem}")
4246
yield {

src/py/kaleido/_page_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __init__(self, *, plotly=None, mathjax=None, others=None):
5151
self._scripts = []
5252
if not plotly:
5353
try:
54-
import plotly
54+
import plotly # type: ignore [import-not-found]
5555

5656
plotly = (
5757
(

src/py/kaleido/kaleido.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
_stepper = False
3535

3636

37+
async def _to_thread(func, *args, **kwargs):
38+
_loop = asyncio.get_running_loop()
39+
fn = partial(func, *args, **kwargs)
40+
await _loop.run_in_executor(None, fn)
41+
42+
3743
# this is kinda public but undocumented
3844
def set_stepper():
3945
"""
@@ -370,7 +376,7 @@ def write_image(binary):
370376
file.write(binary)
371377

372378
_logger.info(f"Starting write of {full_path.name}")
373-
await asyncio.to_thread(write_image, img)
379+
await _to_thread(write_image, img)
374380
_logger.info(f"Wrote {full_path.name}")
375381
if profiler is not None:
376382
self._finish_profile(profile, e, full_path.stat().st_size / 1000000)

src/py/pyproject.toml

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ name = "kaleido"
1616
description = "Plotly graph export library"
1717
license = {file = "LICENSE.md"}
1818
readme = "README.md"
19-
requires-python = ">=3.9"
19+
requires-python = ">=3.8"
2020
dynamic = ["version"]
2121
authors = [
2222
{name = "Andrew Pikul", email="[email protected]"},
@@ -27,7 +27,7 @@ maintainers = [
2727
]
2828
dependencies = [
2929
"async-timeout>=5.0.1",
30-
"choreographer>=1.0.0",
30+
"choreographer>=1.0.3",
3131
"logistro>=1.0.8",
3232
"orjson>=3.10.15",
3333
]
@@ -46,8 +46,8 @@ dev = [
4646
"pytest-asyncio",
4747
"pytest-xdist",
4848
"async-timeout",
49-
"poethepoet>=0.31.1",
5049
"mypy>=1.14.1",
50+
"poethepoet>=0.30.0",
5151
]
5252

5353
#docs = [
@@ -56,19 +56,10 @@ dev = [
5656
# "mkdocs-material>=9.5.49",
5757
#]
5858

59-
[[tool.uv.index]]
60-
name = "pypi"
61-
url = "https://pypi.org/simple/"
62-
63-
[[tool.uv.index]]
64-
name = "test.pypi"
65-
url = "https://test.pypi.org/simple/"
66-
67-
6859
[tool.uv.sources]
69-
mkquixote = { path = "../../../mkquixote", editable = true }
70-
choreographer = { path = "../../../devtools_protocol", editable = true }
71-
logistro = { path = "../../../logistro", editable = true }
60+
#mkquixote = { path = "../../../mkquixote", editable = true }
61+
#choreographer = { path = "../../../devtools_protocol", editable = true }
62+
#logistro = { path = "../../../logistro", editable = true }
7263

7364
[tool.ruff.lint]
7465
select = ["ALL"]

0 commit comments

Comments
 (0)