Skip to content

Default the SDK version to the contract's info.version - #43

Merged
glenn-jocher merged 2 commits into
mainfrom
version-from-contract
Aug 15, 2026
Merged

Default the SDK version to the contract's info.version#43
glenn-jocher merged 2 commits into
mainfrom
version-from-contract

Conversation

@glenn-jocher

@glenn-jocher glenn-jocher commented Aug 15, 2026

Copy link
Copy Markdown
Member

Summary

The API contract's info.version and the generated SDK's package version were two hand-maintained numbers and had already drifted (0.1.3 vs 0.1.5, ultralytics/portal#3620). This makes python.version optional: when omitted, the generated pyproject.toml takes the contract's info.version, so bumping the version in the API is the single source of truth and flows through the sdk repo's contract sync → regen → publish chain.

  • lib/config.ts: python.version optional (dropped from the required-key check).
  • lib/generators/python.ts: version = config.python.version ?? document.info.version.
  • README/README.zh-CN: document the default.

Companion: ultralytics/sdk removes its hard-coded "version" (regenerated output stays 0.1.5 since the live contract now reports 0.1.5).

Verification

bun run test|typecheck|lint|knip pass; regenerating with the sdk config (still pinning 0.1.5) yields version = "0.1.5", and with the key removed the live contract's 0.1.5 is used.

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Python SDK generation now defaults python.version to the OpenAPI contract’s info.version, making the contract the default version source while retaining explicit configuration overrides.

📊 Key Changes

  • Made python.version optional and removed it from the required configuration keys.
  • Updated Python generation to use config.python.version when provided, otherwise document.info.version.
  • Added validation that the resolved version matches the supported Python package version format.
  • Updated the English and Chinese README documentation to describe the new default behavior.

🎯 Purpose & Impact

  • Configurations can omit python.version; generated pyproject.toml then receives the contract’s info.version.
  • Explicit python.version values continue to override the contract version.
  • Invalid resolved versions now stop Python SDK generation with an error directing users to set python.version.

@UltralyticsAssistant UltralyticsAssistant added documentation Improvements or additions to documentation enhancement New feature or request labels Aug 15, 2026
@UltralyticsAssistant

Copy link
Copy Markdown
Member

👋 Hello @glenn-jocher, thank you for submitting a ultralytics/openapi 🚀 PR! This automated message confirms your contribution was received, and an Ultralytics engineer will assist with the review. To ensure a seamless integration of your work, please review the following checklist:

  • Define a Purpose: Clearly explain the purpose of your fix or feature in your PR description, and link to any relevant issues. Ensure your commit messages are clear, concise, and adhere to the project's conventions.
  • Synchronize with Source: Confirm your PR is synchronized with the ultralytics/openapi main branch. If it's behind, update it by clicking the 'Update branch' button or by running git pull and git merge main locally.
  • Ensure CI Checks Pass: Verify all Ultralytics Continuous Integration (CI) checks are passing. If any checks fail, please address the issues.
  • Update Documentation: Update the relevant documentation for any new or modified features.
  • Add Tests: If applicable, include or update tests to cover your changes, and confirm that all tests are passing.
  • Sign the CLA: Please ensure you have signed our Contributor License Agreement if this is your first Ultralytics PR by writing "I have read the CLA Document and I sign the CLA" in a new message.
  • Minimize Changes: Limit your changes to the minimum necessary for your bug fix or feature addition. "It is not daily increase but daily decrease, hack away the unessential. The closer to the source, the less wastage there is." — Bruce Lee

For more guidance, please refer to our Contributing Guide. Don't hesitate to leave a comment if you have any questions. Thank you for contributing to Ultralytics! 🚀

@UltralyticsAssistant UltralyticsAssistant left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🔍 PR Review

Made with ❤️ by Ultralytics Actions

Reviewed all four changed files and the config-to-generator flow. The optional override is wired consistently, but the new default does not validate that an OpenAPI document version is usable as Python package metadata, leaving a realistic SDK build failure path.

💬 Posted 1 inline comment
  • 💡 MEDIUM lib/generators/python.ts:847 info.version is only constrained to be a string identifying the OpenAPI document, while [project].version must use Python's packaging version format. A valid contract value such as release-2026-08-15 or 1.2.3-alpha.1 will therefore generate a package that fails at uv build/publish when python.version is omitted. Validate the fallback as a Python-compatible version and fail with an actionable error, or require an explicit python.version override for incompatible contract versions.…

Comment thread lib/generators/python.ts Outdated
Bun.write(
`${output}/pyproject.toml`,
`[build-system]\nrequires = ["uv_build>=0.12.3,<0.13"]\nbuild-backend = "uv_build"\n\n[project]\nname = "${config.python.project}"\nversion = "${config.python.version}"\n${projectMetadata}\nreadme = "README.md"\nlicense = "${license.id}"\nlicense-files = ["LICENSE"]\ndependencies = ["httpx>=0.28,<1"]${projectUrls}\n\n[tool.ruff]\nline-length = 120\n\n[tool.uv.build-backend]\nmodule-name = "${config.python.package}"\n`,
`[build-system]\nrequires = ["uv_build>=0.12.3,<0.13"]\nbuild-backend = "uv_build"\n\n[project]\nname = "${config.python.project}"\nversion = "${config.python.version ?? document.info.version}"\n${projectMetadata}\nreadme = "README.md"\nlicense = "${license.id}"\nlicense-files = ["LICENSE"]\ndependencies = ["httpx>=0.28,<1"]${projectUrls}\n\n[tool.ruff]\nline-length = 120\n\n[tool.uv.build-backend]\nmodule-name = "${config.python.package}"\n`,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

💡 MEDIUM: info.version is only constrained to be a string identifying the OpenAPI document, while [project].version must use Python's packaging version format. A valid contract value such as release-2026-08-15 or 1.2.3-alpha.1 will therefore generate a package that fails at uv build/publish when python.version is omitted. Validate the fallback as a Python-compatible version and fail with an actionable error, or require an explicit python.version override for incompatible contract versions. (spec.openapis.org)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Now validated: when python.version is omitted and info.version is not a valid Python package version, generation fails with Set python.version: contract version "…" is not a valid Python package version.

@glenn-jocher
glenn-jocher merged commit 0fed1a8 into main Aug 15, 2026
4 checks passed
@glenn-jocher
glenn-jocher deleted the version-from-contract branch August 15, 2026 18:51
@UltralyticsAssistant

Copy link
Copy Markdown
Member

🎉 Thanks @glenn-jocher—the PR has been merged!

“Alone we can do so little; together we can do so much.” — Helen Keller

This update makes the OpenAPI contract’s info.version the default for Python SDK generation while preserving explicit python.version overrides and validating the resolved version. Great work!

glenn-jocher added a commit to ultralytics/sdk that referenced this pull request Aug 15, 2026
## Summary

Removes the hard-coded `python.version` from `openapi.config.json`: with ultralytics/openapi#43 the generator defaults the package version to the contract's `info.version`, so the API version is the single source of truth and a contract bump reaching `main` publishes the SDK. README wording updated.

Also re-pins the live contract snapshot (now `info.version` 0.1.5 via ultralytics/portal#3620, plus the authored examples from ultralytics/portal#3619) and regenerates: only docstring example text in five resource modules changes; the package version stays 0.1.5, so no publish is triggered.

Depends on ultralytics/openapi#43 (CI regenerates from `openapi` `main`).

## Verification

`sha256sum --check`, `ruff check`, `pytest tests` (4 passed); regenerated `pyproject.toml` reports `version = "0.1.5"` from the contract.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants