Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
9cc3760
Merge pull request #233 from swgoh-utils/backmerge/main-to-develop-41…
MarTrepodi Nov 5, 2026
4ec7597
fix(exceptions): truncate response bodies in HTTP error messages
MarTrepodi Nov 7, 2026
652af41
ci: pin GitHub Actions to commit SHAs
MarTrepodi Nov 7, 2026
1672812
fix(core): validate and URL-encode the get_unit_stats language parameter
MarTrepodi Nov 7, 2026
0467afe
fix(core): replace runtime asserts and raw KeyErrors with library errors
MarTrepodi Nov 7, 2026
63ed346
fix(client): read HMAC keys from COMLINK_ACCESS_KEY and COMLINK_SECRE…
MarTrepodi Nov 7, 2026
7288a1f
fix(hmac): warn when HMAC is used over plain HTTP to a non-loopback host
MarTrepodi Nov 7, 2026
06b0227
fix(statcalc): cap and optionally verify the game data download
MarTrepodi Nov 7, 2026
3201dbe
perf(statcalc): run StatCalcAsync calculations off the event loop
MarTrepodi Nov 7, 2026
81623d0
feat(client): add opt-in max_response_bytes and max_game_data_bytes l…
MarTrepodi Nov 7, 2026
14b5858
test(parity): add a repeatable StatCalc benchmark script
MarTrepodi Nov 7, 2026
8b51989
fix(async): use httpx default keep-alive and add a limits argument
MarTrepodi Nov 7, 2026
433b764
Merge branch 'fix/error-body-truncation' into refactor/sans-io-retry
MarTrepodi Nov 7, 2026
3648460
perf(statcalc): normalise game data tables to str keys once
MarTrepodi Nov 7, 2026
0190952
perf(statcalc): copy normalized units shallowly instead of deep-copying
MarTrepodi Nov 7, 2026
d228fa1
perf(statcalc): index each unit's skills by id in set_game_data
MarTrepodi Nov 7, 2026
07b3db2
refactor(core): move request preparation and retry decisions into a s…
MarTrepodi Nov 7, 2026
ae35c6d
perf(statcalc): drop key-list copies and probing lookups in _format_s…
MarTrepodi Nov 7, 2026
1a71544
perf(statcalc): map mod stat ids to their target stats with lookup ta…
MarTrepodi Nov 7, 2026
d8b5b07
perf(statcalc): fold final stat ids by lookup and loop the percent co…
MarTrepodi Nov 7, 2026
1f81a80
perf(statcalc): run all percent conversions in one _convert_percent call
MarTrepodi Nov 7, 2026
e02f7fb
perf(statcalc): key the summed raw mod stats by int stat id
MarTrepodi Nov 7, 2026
17d35de
perf(statcalc): index mod GP by int (pips, level, tier) in set_game_data
MarTrepodi Nov 7, 2026
ccc3198
perf(statcalc): build renamed stat dicts with a comprehension
MarTrepodi Nov 7, 2026
24684ea
docs(migration): note that set_game_data indexes the mod GP table
MarTrepodi Nov 7, 2026
18bd2ee
fix(examples): skip comment lines when decoding language bundles
MarTrepodi Nov 7, 2026
e4665fd
Merge pull request #249 from swgoh-utils/fix/error-body-truncation
MarTrepodi Nov 7, 2026
f8c8387
Merge pull request #250 from swgoh-utils/fix/statcalc-gamedata-integrity
MarTrepodi Nov 7, 2026
d2940af
Merge pull request #251 from swgoh-utils/perf/statcalc-async-offload
MarTrepodi Nov 7, 2026
59e9c8e
Merge pull request #252 from swgoh-utils/perf/statcalc-lookups
MarTrepodi Nov 7, 2026
92ac4ed
Merge pull request #258 from swgoh-utils/refactor/sans-io-retry
MarTrepodi Nov 7, 2026
7b82b69
Merge pull request #257 from swgoh-utils/ci/pin-actions
MarTrepodi Nov 7, 2026
db4c198
Merge pull request #259 from swgoh-utils/fix/language-bundle-examples
MarTrepodi Nov 7, 2026
20a7bb4
chore(deps): Bump astral-sh/setup-uv
dependabot[bot] Nov 8, 2026
f9aaaef
chore(deps): Bump the astral-tools group with 2 updates
dependabot[bot] Nov 8, 2026
48d2859
chore(deps): Bump the python group with 2 updates
dependabot[bot] Nov 8, 2026
f7cc744
Merge pull request #262 from swgoh-utils/dependabot/uv/develop/python…
MarTrepodi Nov 8, 2026
c7c5834
Merge pull request #261 from swgoh-utils/dependabot/uv/develop/astral…
MarTrepodi Nov 8, 2026
11df406
Merge pull request #260 from swgoh-utils/dependabot/github_actions/de…
MarTrepodi Nov 8, 2026
a23b611
fix(async): give back the pacing slot on any exception while sleeping
MarTrepodi Nov 7, 2026
921148b
refactor(core): generate the sync client from the async client
MarTrepodi Nov 7, 2026
374541a
fix(client): attribute the credential deprecation warning past in-pac…
MarTrepodi Nov 7, 2026
a7d47ca
chore(ci): regenerate the sync client in a pre-commit hook
MarTrepodi Nov 9, 2026
6e24746
Merge pull request #263 from swgoh-utils/refactor/sync-client-codegen
MarTrepodi Nov 9, 2026
4f7e96e
feat(helpers): accept type-prefixed enum names in guild roles and ite…
MarTrepodi Nov 2, 2026
beff74a
Merge pull request #264 from swgoh-utils/feat/type-prefixed-enum-names
MarTrepodi Nov 9, 2026
07bffd6
fix(helpers): accept tier 0 in is_omicron_skill
MarTrepodi Nov 9, 2026
d79193a
feat(statcalc): apply a named datacron's stat affixes to characters
MarTrepodi Nov 9, 2026
c201655
test(statcalc): add the datacron golden fixture from in-game readings
MarTrepodi Nov 9, 2026
c213f68
docs(examples): add sync and async datacron calculation examples
MarTrepodi Nov 9, 2026
ff158cd
feat(helpers): add get_omicron_breakdown for guild-wide omicron adoption
MarTrepodi Nov 9, 2026
0c3bf6a
docs(examples): add guild omicron breakdown examples
MarTrepodi Nov 9, 2026
0783d9e
Merge pull request #265 from swgoh-utils/feat/guild-omicron-breakdown
MarTrepodi Nov 10, 2026
c9bd8bc
Merge pull request #266 from swgoh-utils/feat/datacron-statcalc
MarTrepodi Nov 10, 2026
3b63a7a
feat(client): add strip_empty option to get_game_data
MarTrepodi Nov 10, 2026
f2746ba
Merge pull request #267 from swgoh-utils/feat/game-data-strip-empty
MarTrepodi Nov 10, 2026
48fa566
chore(deps): Bump the astral-tools group with 2 updates
dependabot[bot] Nov 15, 2026
7a6c9f0
chore(deps): Bump the python group with 3 updates
dependabot[bot] Nov 15, 2026
6be4756
Merge pull request #268 from swgoh-utils/dependabot/uv/develop/astral…
MarTrepodi Nov 17, 2026
79b143c
Merge pull request #269 from swgoh-utils/dependabot/uv/develop/python…
MarTrepodi Nov 17, 2026
f41fa55
chore(deps): Bump astral-sh/setup-uv
dependabot[bot] Nov 22, 2026
3f35921
chore(deps): Bump the astral-tools group with 2 updates
dependabot[bot] Nov 22, 2026
a326aaa
chore(deps): Bump the python group with 2 updates
dependabot[bot] Nov 22, 2026
5f9c71f
Merge pull request #270 from swgoh-utils/dependabot/github_actions/de…
MarTrepodi Nov 23, 2026
b507d15
Merge pull request #271 from swgoh-utils/dependabot/uv/develop/astral…
MarTrepodi Nov 23, 2026
5e73732
Merge pull request #272 from swgoh-utils/dependabot/uv/develop/python…
MarTrepodi Nov 23, 2026
3100f3c
feat(helpers): sync game data constants with client schema 0.41.2115745
MarTrepodi Nov 4, 2026
3f54d7e
Merge pull request #273 from swgoh-utils/feat/gamedata-0.41-overcharge
MarTrepodi Nov 23, 2026
7c4f01e
test(hmac): assert the plain-HTTP warning argument exactly
MarTrepodi Nov 23, 2026
f7a27ff
Merge pull request #275 from swgoh-utils/test/codeql-hmac-warning-assert
MarTrepodi Nov 23, 2026
11802b5
chore(changelog): update for v2.9.0
github-actions[bot] Nov 23, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions .github/release-pr/v2.9.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
Automated release prep for **v2.9.0**. CHANGELOG.md regenerated via git-changelog.

Merging promotes `develop` -> `main` with the changelog already in place.
Afterwards, run the **release** workflow on `main` to build, publish, and tag v2.9.0.

### Issues resolved by this release

Merging this PR into `main` closes:

- Closes #216 (via #273)
- Closes #234 (via #250)
- Closes #235 (via #258)
- Closes #236 (via #258)
- Closes #237 (via #258)
- Closes #238 (via #249)
- Closes #239 (via #249)
- Closes #240 (via #258)
- Closes #241 (via #258)
- Closes #242 (via #257)
- Closes #243 (via #251)
- Closes #244 (via #251)
- Closes #245 (via #252)
- Closes #246 (via #258)
- Closes #248 (via #259)

---

<a name="v2.9.0"></a>

## [v2.9.0](https://github.com/swgoh-utils/comlink-python/compare/v2.8.0...v2.9.0) (2026-11-23)

### Features

- **client:** add strip_empty option to get_game_data ([3b63a7a](https://github.com/swgoh-utils/comlink-python/commit/3b63a7a73aed527f052c59e1e9f2bd7f14785c58))
- **helpers:** add get_omicron_breakdown for guild-wide omicron adoption ([ff158cd](https://github.com/swgoh-utils/comlink-python/commit/ff158cd4891acda6823387e4bee925d1c6503c85))
- **statcalc:** apply a named datacron's stat affixes to characters ([d79193a](https://github.com/swgoh-utils/comlink-python/commit/d79193a90341acfffc9a687b715003726d9d21dd))
- **client:** add opt-in max_response_bytes and max_game_data_bytes limits ([81623d0](https://github.com/swgoh-utils/comlink-python/commit/81623d0d573e1a0e6f2c0c1463d129e9a2c632b2))
- **helpers:** sync game data constants with client schema 0.41.2115745 ([3100f3c](https://github.com/swgoh-utils/comlink-python/commit/3100f3cbf5e003f946f2255a90735c52f2b944db))
- **helpers:** accept type-prefixed enum names in guild roles and item names ([4f7e96e](https://github.com/swgoh-utils/comlink-python/commit/4f7e96e23227d092ab8bdb1118ce227e1bb667f8))

### Bug Fixes

- **helpers:** accept tier 0 in is_omicron_skill ([07bffd6](https://github.com/swgoh-utils/comlink-python/commit/07bffd6a960cf0a1afc6623bbbbf33997a2d553a))
- **client:** attribute the credential deprecation warning past in-package subclasses ([374541a](https://github.com/swgoh-utils/comlink-python/commit/374541ad5d564a931e3e589973346b107426618c))
- **async:** give back the pacing slot on any exception while sleeping ([a23b611](https://github.com/swgoh-utils/comlink-python/commit/a23b611f717189780968babc0971b077c5d5cfbe))
- **examples:** skip comment lines when decoding language bundles ([18bd2ee](https://github.com/swgoh-utils/comlink-python/commit/18bd2ee95d80c9f57e10ae67b1a147b243adaa25))
- **async:** use httpx default keep-alive and add a limits argument ([8b51989](https://github.com/swgoh-utils/comlink-python/commit/8b51989b02639d8005788be4c71d884eba2ca433))
- **statcalc:** cap and optionally verify the game data download ([06b0227](https://github.com/swgoh-utils/comlink-python/commit/06b02274e91de2ff09851fad83e7e43e63385324))
- **hmac:** warn when HMAC is used over plain HTTP to a non-loopback host ([7288a1f](https://github.com/swgoh-utils/comlink-python/commit/7288a1f7ed71500c6040f34e212c89c7a4ae1d75))
- **client:** read HMAC keys from COMLINK_ACCESS_KEY and COMLINK_SECRET_KEY ([63ed346](https://github.com/swgoh-utils/comlink-python/commit/63ed3460ab1fa88ef861f8088bcad99350e75653))
- **core:** replace runtime asserts and raw KeyErrors with library errors ([0467afe](https://github.com/swgoh-utils/comlink-python/commit/0467afe9c11329ced8b34483bb7c86314dbb6abc))
- **core:** validate and URL-encode the get_unit_stats language parameter ([1672812](https://github.com/swgoh-utils/comlink-python/commit/16728120e8a440a2d5b08f33e1c90d345c9b6275))
- **exceptions:** truncate response bodies in HTTP error messages ([4ec7597](https://github.com/swgoh-utils/comlink-python/commit/4ec7597e5aa32b7e67014349f6c255f3dd721417))

### Code Refactoring

- **core:** generate the sync client from the async client ([921148b](https://github.com/swgoh-utils/comlink-python/commit/921148b6c64ebb836059753df00a9830e2715b25))
- **core:** move request preparation and retry decisions into a sans-I/O core ([07b3db2](https://github.com/swgoh-utils/comlink-python/commit/07b3db2226b7d0f72d89161369fa25afe3797677))

### Performance Improvements

- **statcalc:** build renamed stat dicts with a comprehension ([ccc3198](https://github.com/swgoh-utils/comlink-python/commit/ccc3198142f361c656274622a25d52e26adfc5dc))
- **statcalc:** index mod GP by int (pips, level, tier) in set_game_data ([17d35de](https://github.com/swgoh-utils/comlink-python/commit/17d35deb528bafde93e1311ff1acc0f90a5330ae))
- **statcalc:** key the summed raw mod stats by int stat id ([e02f7fb](https://github.com/swgoh-utils/comlink-python/commit/e02f7fbb9c4006e43f7d7e401d2dd7c3a9b95770))
- **statcalc:** run all percent conversions in one _convert_percent call ([1f81a80](https://github.com/swgoh-utils/comlink-python/commit/1f81a805f2a8e19ee99152db3a5e7cf03bc674cc))
- **statcalc:** fold final stat ids by lookup and loop the percent conversions ([d8b5b07](https://github.com/swgoh-utils/comlink-python/commit/d8b5b07b7d902654d7e716cdf12f1efc631f61fa))
- **statcalc:** map mod stat ids to their target stats with lookup tables ([1a71544](https://github.com/swgoh-utils/comlink-python/commit/1a715447ecfc18ba4774e3dcf7b0d98240447c0c))
- **statcalc:** drop key-list copies and probing lookups in _format_stats ([ae35c6d](https://github.com/swgoh-utils/comlink-python/commit/ae35c6db0f05c98c61ffdfa672fcdbaa0f33e87e))
- **statcalc:** index each unit's skills by id in set_game_data ([d228fa1](https://github.com/swgoh-utils/comlink-python/commit/d228fa110e7854cb138f4adba0e752f606ddf16b))
- **statcalc:** copy normalized units shallowly instead of deep-copying ([0190952](https://github.com/swgoh-utils/comlink-python/commit/0190952e5a5f10ad559109063b8af556367b2359))
- **statcalc:** normalise game data tables to str keys once ([3648460](https://github.com/swgoh-utils/comlink-python/commit/36484609918590e828f5354e0045df4594f59d63))
- **statcalc:** run StatCalcAsync calculations off the event loop ([3201dbe](https://github.com/swgoh-utils/comlink-python/commit/3201dbee7322ad981dd334a145d5a105dbd10242))

### Docs

- **examples:** add guild omicron breakdown examples ([0c3bf6a](https://github.com/swgoh-utils/comlink-python/commit/0c3bf6ad5dae0b1f58914d136fade3f74627b966))
- **examples:** add sync and async datacron calculation examples ([c213f68](https://github.com/swgoh-utils/comlink-python/commit/c213f68a248b9b540b3eaffa545914f4d2dd8f5d))
- **migration:** note that set_game_data indexes the mod GP table ([24684ea](https://github.com/swgoh-utils/comlink-python/commit/24684ea7a1d90fba62367aadefbae0aace4d3225))
235 changes: 235 additions & 0 deletions .github/scripts/unasync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
"""Generate the sync clients from the async ones.

The async client is the source. Each sync client is its async twin with these token rewrites, passed
through ``ruff`` so it is import-sorted and formatted like any hand-written file:

* ``async`` before ``def``, ``with`` or ``for`` is dropped, and so is every ``await``. Parentheses that
only group an awaited primary expression, as in ``(await self._get_versions()).require_game()``, go too.
* Names are renamed by :data:`NAME_RENAMES` and dotted names by :data:`DOTTED_RENAMES`;
``import asyncio`` becomes ``import threading``.
* Docstrings and comments get :data:`NAME_RENAMES` as whole words plus :data:`TEXT_RENAMES`, which turn
the code in examples sync. Everything else in them is copied verbatim, so their prose must hold for both
runtimes.

Usage::

uv run python .github/scripts/unasync.py # rewrite the sync files
uv run python .github/scripts/unasync.py --check # exit 1 and print a diff when one is out of date

Only the standard library and ``ruff``, already a dev dependency, are used.
"""

from __future__ import annotations

import argparse
import difflib
import io
import keyword
import re
import shutil
import subprocess
import sys
import tokenize
from pathlib import Path

ROOT = Path(__file__).resolve().parents[2]
PACKAGE = ROOT / "src" / "swgoh_comlink"

#: (async source, sync target) pairs, relative to the package directory.
FILES: tuple[tuple[str, str], ...] = (("swgoh_comlink_async.py", "swgoh_comlink.py"),)

#: Whole-name renames, applied to NAME tokens in code and as whole words in docstrings and comments.
NAME_RENAMES: dict[str, str] = {
"SwgohComlinkAsync": "SwgohComlink",
"swgoh_comlink_async": "swgoh_comlink",
"AsyncClient": "Client",
"aclose": "close",
"__aenter__": "__enter__",
"__aexit__": "__exit__",
"aiter_bytes": "iter_bytes",
"_async_sleep": "_sleep",
}

#: Dotted-name renames in code, matched as ``NAME . NAME``.
DOTTED_RENAMES: dict[tuple[str, str], tuple[str, str]] = {("asyncio", "Lock"): ("threading", "Lock")}

#: Module renames in a bare ``import x`` statement.
IMPORT_RENAMES: dict[str, str] = {"asyncio": "threading"}

#: Extra regex renames for docstrings and comments: the runtime adjective and the code in examples.
TEXT_RENAMES: tuple[tuple[str, str], ...] = (
(r"\bAsynchronous\b", "Synchronous"),
(r"\basync (def|with|for)\b", r"\1"),
(r"\bawait\s+", ""),
)

HEADER = "# GENERATED from {source} by .github/scripts/unasync.py. Do not edit: change the source and rerun.\n"

_TEXT_PATTERNS = tuple(
(re.compile(pattern), new)
for pattern, new in [*((rf"\b{re.escape(old)}\b", new) for old, new in NAME_RENAMES.items()), *TEXT_RENAMES]
)

# Tokens after which ``(`` opens a call or subscript rather than a group.
_CALLABLE_ENDS = {")", "]"}


def _rename_text(text: str) -> str:
for pattern, replacement in _TEXT_PATTERNS:
text = pattern.sub(replacement, text)
return text


def _closing_paren(tokens: list[tokenize.TokenInfo], open_index: int) -> int:
"""Index of the token that closes the bracket at *open_index*."""
depth = 0
for j in range(open_index, len(tokens)):
if tokens[j].string in "([{":
depth += 1
elif tokens[j].string in ")]}":
depth -= 1
if depth == 0:
return j
raise ValueError(f"unbalanced bracket at line {tokens[open_index].start[0]}")


def _is_grouping_paren(tokens: list[tokenize.TokenInfo], index: int) -> bool:
"""Whether the ``(`` at *index* groups an expression instead of opening a call or a subscript."""
if index == 0:
return True
before = tokens[index - 1]
if before.type == tokenize.NAME:
return keyword.iskeyword(before.string) and before.string not in ("True", "False", "None")
return before.string not in _CALLABLE_ENDS and before.type not in (tokenize.STRING, tokenize.NUMBER)


def _is_primary(tokens: list[tokenize.TokenInfo], start: int, stop: int) -> bool:
"""Whether ``tokens[start:stop]`` is one primary expression: names, dots, calls and subscripts only."""
j = start
while j < stop:
tok = tokens[j]
if tok.string in "([":
j = _closing_paren(tokens, j) + 1
elif tok.type == tokenize.NAME and not keyword.iskeyword(tok.string) or tok.string == ".":
j += 1
else:
return False
return True


def _ends_line(tok: tokenize.TokenInfo | None) -> bool:
return tok is None or tok.type == tokenize.NEWLINE


def unasync_source(source: str) -> str:
"""Rewrite async Python *source* as its sync twin, before import sorting and formatting."""
line_starts = [0]
for line in source.splitlines(keepends=True):
line_starts.append(line_starts[-1] + len(line))

def offset(point: tuple[int, int]) -> int:
return line_starts[point[0] - 1] + point[1]

skipped = (tokenize.NL, tokenize.INDENT, tokenize.DEDENT, tokenize.ENDMARKER)
tokens = [t for t in tokenize.generate_tokens(io.StringIO(source).readline) if t.type not in skipped]
edits: dict[int, tuple[int, str]] = {} # start offset -> (end offset, replacement)

def replace(first: tokenize.TokenInfo, until: tokenize.TokenInfo | None, text: str) -> None:
"""Replace from the start of *first* to the start of *until* (or the end of *first*) with *text*."""
end = offset(until.start) if until is not None else offset(first.end)
edits[offset(first.start)] = (end, text)

for i, tok in enumerate(tokens):
prev = tokens[i - 1] if i else None
nxt = tokens[i + 1] if i + 1 < len(tokens) else None
if tok.type in (tokenize.STRING, tokenize.COMMENT):
if (renamed := _rename_text(tok.string)) != tok.string:
replace(tok, None, renamed)
elif tok.type != tokenize.NAME:
continue
elif tok.string == "async" and nxt is not None and nxt.string in ("def", "with", "for"):
replace(tok, nxt, "")
elif tok.string == "await":
assert nxt is not None
replace(tok, nxt, "")
if prev is not None and prev.string == "(" and _is_grouping_paren(tokens, i - 1):
close = _closing_paren(tokens, i - 1)
if _is_primary(tokens, i + 1, close):
replace(prev, tok, "")
replace(tokens[close], None, "")
elif prev is not None and prev.string == "import" and tok.string in IMPORT_RENAMES and _ends_line(nxt):
replace(tok, None, IMPORT_RENAMES[tok.string])
elif nxt is not None and nxt.string == "." and i + 2 < len(tokens):
pair = (tok.string, tokens[i + 2].string)
if pair in DOTTED_RENAMES:
replace(tok, None, DOTTED_RENAMES[pair][0])
replace(tokens[i + 2], None, DOTTED_RENAMES[pair][1])
elif tok.string in NAME_RENAMES:
replace(tok, None, NAME_RENAMES[tok.string])
elif tok.string in NAME_RENAMES:
replace(tok, None, NAME_RENAMES[tok.string])

out = source
for start in sorted(edits, reverse=True):
end, text = edits[start]
out = out[:start] + text + out[end:]
return out


def _ruff(source: str, filename: Path) -> str:
"""Import-sort and format *source* with the project's ruff settings."""
ruff = shutil.which("ruff")
if ruff is None:
raise SystemExit("ruff not found: run this through `uv run` so the dev dependencies are on PATH.")
for args in (["check", "--select", "I", "--fix", "--exit-zero", "--quiet"], ["format", "--quiet"]):
source = subprocess.run(
[ruff, *args, "--stdin-filename", str(filename), "-"],
input=source,
capture_output=True,
text=True,
check=True,
cwd=ROOT,
).stdout
return source


def generate(source_path: Path, target_path: Path) -> str:
"""The text *source_path* generates for *target_path*, header included."""
body = unasync_source(source_path.read_text(encoding="utf-8"))
header = HEADER.format(source=source_path.name)
# A leading ``# coding`` line must stay first; the header follows it.
first, sep, rest = body.partition("\n")
body = f"{first}{sep}{header}{rest}" if first.startswith("# coding") else header + body
return _ruff(body, target_path)


def main(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser(description="Generate the sync clients from the async ones.")
parser.add_argument("--check", action="store_true", help="exit 1 and print a diff when a sync file is stale")
args = parser.parse_args(argv)
stale = []
for source_name, target_name in FILES:
source_path, target_path = PACKAGE / source_name, PACKAGE / target_name
expected = generate(source_path, target_path)
current = target_path.read_text(encoding="utf-8") if target_path.exists() else ""
if current == expected:
continue
rel = target_path.relative_to(ROOT).as_posix()
if args.check:
stale.append(rel)
sys.stdout.writelines(
difflib.unified_diff(
current.splitlines(keepends=True), expected.splitlines(keepends=True), rel, f"{rel} (generated)"
)
)
else:
target_path.write_text(expected, encoding="utf-8")
print(f"wrote {rel}")
if stale:
print(f"\nOut of date: {', '.join(stale)}. Run `uv run python .github/scripts/unasync.py`.", file=sys.stderr)
return 1
return 0


if __name__ == "__main__":
raise SystemExit(main())
2 changes: 1 addition & 1 deletion .github/workflows/backmerge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
github.event_name == 'workflow_dispatch' ||
github.event.workflow_run.conclusion == 'success'
steps:
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: main
fetch-depth: 0
Expand Down
Loading