Skip to content

Add scripts for OpenAPI generation and post-generation and more convenience - #100

Open
antalszava wants to merge 7 commits into
mainfrom
makefile
Open

Add scripts for OpenAPI generation and post-generation and more convenience#100
antalszava wants to merge 7 commits into
mainfrom
makefile

Conversation

@antalszava

@antalszava antalszava commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add scripts/regenerate_models.py as the canonical, OS-independent way to regenerate the client: stdlib-only (urllib, shutil, tempfile, subprocess), applies openapi-overlay.yaml when present, and supports --sync-spec to fetch the latest upstream spec first.
  • Replace the perl one-liner post_hooks in openapi-python-client-config.yaml with scripts/post_generate.py (same behavior: SPDX/@generated headers, token hidden from repr) — the perl quoting was Unix-only and broke generation on Windows.
  • Add an optional Makefile with shorthand targets (regen, sync-spec, check-generated, lint, test, ...) that wrap the script and the existing uv run commands.
  • generated.yml now runs the script on a Linux/macOS/Windows matrix (staleness gate on Linux), so the regeneration command is defined in one place and exercised on all supported platforms.
  • ci.yml test matrix gains macOS and Windows entries (Python 3.14, --no-cov).
  • Update CONTRIBUTING.md to document the script as the regeneration workflow.

Test plan

  • uv run --group regen python scripts/regenerate_models.py reproduces the committed generated code with zero diff (i.e. the Python post-hooks are byte-identical to the perl ones).
  • Full suite passes locally: 242 tests, 100% branch coverage on hand-written code; ruff check, ruff format --check, and ty check clean.
  • generated.yml staleness jobs pass on ubuntu, macos, and windows on this PR.

Note: Used the help of Claude Code for this PR. 🤖

@antalszava
antalszava requested a review from a team as a code owner August 31, 2026 13:30
@antalszava antalszava changed the title Add cross-platform regeneration script and optional Makefile Add scripts for OpenAPI generation and post-generation and more convenience Aug 31, 2026
@antalszava
antalszava requested review from natestemen and splch August 31, 2026 14:36

@splch splch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleanup. One Windows bug inline + two notes. Per plan on #95, this lands after the stack.

Comment thread scripts/post_generate.py

def main() -> None:
client_file = PACKAGE_DIR / "client.py"
client_file.write_text(

@splch splch Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

write_text emits CRLF on Windows, so regen output there isn't byte-identical (and the staleness gate is Linux-only). Add newline="\n" to both calls.

Comment thread .github/workflows/generated.yml Outdated
--overwrite
run: uv run --group regen python scripts/regenerate_models.py
- name: Check for uncommitted changes
if: runner.os == 'Linux'

@splch splch Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could run this check on macOS too - right now the mac/windows jobs only prove the script runs.

post_hooks:
- "perl -pi -e 's/token: str\\K$/ = field(repr=False)/' client.py"
- "perl -0777 -pi -e '$y=(gmtime)[5]+1900;s/\\A(?!# SPDX-FileCopyrightText)/# SPDX-FileCopyrightText: $y IonQ, Inc.\\n# SPDX-License-Identifier: Apache-2.0\\n# \\@generated\\n\\n/' $(find . -name '*.py')"
- "python ../scripts/post_generate.py"

@splch splch Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads up: #96 adds 3 more hooks here - whichever lands second ports them into post_generate.py (per #95 plan, this one).

hodgestar-ionq
hodgestar-ionq previously approved these changes Sep 1, 2026

@hodgestar-ionq hodgestar-ionq left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thank you for adding the Makefile. I left a couple of questions.

Comment thread .github/workflows/ci.yml
enable-cache: ${{ github.event_name == 'push' }}
- run: uv sync
- run: uv run pytest ${{ matrix.python-version != '3.11' && '--no-cov' || '' }}
- run: uv run pytest ${{ (matrix.python-version != '3.11' || matrix.os != 'ubuntu-latest') && '--no-cov' || '' }}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we'd want to run coverage on all targets, and then combine the output so that we can see coverage of target-specific branches. No for this PR, of course, just a big picture nice to have.

Comment thread .github/workflows/generated.yml Outdated
--overwrite
run: uv run --group regen python scripts/regenerate_models.py
- name: Check for uncommitted changes
if: runner.os == 'Linux'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering why this isn't matrix.os like elsewhere? Is the intention here to only fail one version of the check but test that generation works on all platforms? If so, I feel it's worth a comment.

Comment thread scripts/post_generate.py Outdated
)

year = datetime.datetime.now(datetime.UTC).year
header = f"# SPDX-FileCopyrightText: {year} IonQ, Inc.\n# SPDX-License-Identifier: Apache-2.0\n# @generated\n\n"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
header = f"# SPDX-FileCopyrightText: {year} IonQ, Inc.\n# SPDX-License-Identifier: Apache-2.0\n# @generated\n\n"
header = f"# SPDX-FileCopyrightText: YYYY-{year} IonQ, Inc.\n# SPDX-License-Identifier: Apache-2.0\n# @generated\n\n"

Should we include the year the generated file was first published in the copyright? Not sure which year that would be, so I just put YYYY in the suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants