fix: derive sub-package __version__ from a single source of truth#182
fix: derive sub-package __version__ from a single source of truth#182KomanRudden wants to merge 2 commits into
Conversation
The OpenAPI-generated kinde_sdk.management and kinde_sdk.frontend sub-packages have been emitting __version__ = "2.0.0" since the 2.x line was cut, regardless of what the SDK is actually shipped as. The 2.3.0 wheel on PyPI demonstrates the drift: kinde_sdk.__version__ is "2.3.0" but kinde_sdk.management.__version__ and kinde_sdk.frontend.__version__ both report "2.0.0". Root cause: packageVersion was hard-coded across both generator scripts and their config files. Every regeneration wrote the stale value back into the sub-package __init__.py files, and bumping the top-level SDK didn't propagate. This change introduces a single source of truth and keeps the generated sub-packages dynamically in sync, so the literal version no longer appears in any sub-package __init__.py at all. Changes: - New kinde_sdk/_version.py contains the only literal version string in the SDK. It has zero imports so it can be safely re-exported from any sub-package without risking a circular import. - kinde_sdk/__init__.py re-exports __version__ from _version. - kinde_sdk/management/__init__.py and kinde_sdk/frontend/__init__.py now do the same: `from kinde_sdk._version import __version__`. No literal version string in either file - cannot drift. - generate_management_sdk.py and generate_frontend_sdk.py both gain a make_version_dynamic() post-generation step that rewrites the OpenAPI-emitted `__version__ = "X"` line back to the import on every regeneration. Idempotent: a no-op if already rewritten. - Both generator scripts still derive packageVersion from kinde_sdk._version (via _read_sdk_version) so other generated artifacts that embed the version literally - notably user-agent headers in the generated configuration.py - also stay in lockstep. - generate_frontend_sdk.py now (re)writes generator/frontend_config.yaml on every run rather than only when missing, so a stale local config can no longer silently override the SDK version. - openapitools.json packageVersion bumped to 2.2.0 to match today's SDK version. This file is overwritten by generate_management_sdk.py on every run from kinde_sdk._version, so it stays in sync going forward; the bump just brings the checked-in config into agreement. Going forward, bump kinde_sdk/_version.py and you're done - kinde_sdk.__version__, kinde_sdk.management.__version__, kinde_sdk.frontend.__version__, and importlib.metadata all report the new value, with no need to touch any sub-package __init__.py. Verified end-to-end in a clean venv (pip install -e .): all three namespaces resolve to the same __version__ object, no circular import. Made-with: Cursor
WalkthroughThis PR consolidates Python SDK version management to a single source of truth. It creates ChangesVersion consolidation to single source of truth
🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
generate_frontend_sdk.py (1)
241-254: 💤 Low valueMinor: Comment references wrong source file.
Line 243 states
packageVersion is derived from kinde_sdk/__init__.py's __version__, but the generator actually reads fromkinde_sdk/_version.pydirectly via_read_sdk_version(). Consider updating the comment for accuracy.📝 Suggested fix
-# packageVersion is derived from kinde_sdk/__init__.py's __version__. +# packageVersion is derived from kinde_sdk/_version.py's __version__.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@generate_frontend_sdk.py` around lines 241 - 254, Comment in generate_frontend_sdk.py incorrectly states the packageVersion is derived from kinde_sdk/__init__.py; update that comment to reference kinde_sdk/_version.py (or the _read_sdk_version() helper) and/or say it is derived from SDK_VERSION which is populated by _read_sdk_version(), so the config header using CONFIG_FILE and packageVersion: {SDK_VERSION} accurately documents the source.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@generate_frontend_sdk.py`:
- Around line 241-254: Comment in generate_frontend_sdk.py incorrectly states
the packageVersion is derived from kinde_sdk/__init__.py; update that comment to
reference kinde_sdk/_version.py (or the _read_sdk_version() helper) and/or say
it is derived from SDK_VERSION which is populated by _read_sdk_version(), so the
config header using CONFIG_FILE and packageVersion: {SDK_VERSION} accurately
documents the source.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 37baef7a-7643-463f-9f09-4b4e6142ec0f
⛔ Files ignored due to path filters (2)
kinde_sdk/frontend/__init__.pyis excluded by!kinde_sdk/frontend/**openapitools.jsonis excluded by!**/*.json
📒 Files selected for processing (5)
generate_frontend_sdk.pygenerate_management_sdk.pykinde_sdk/__init__.pykinde_sdk/_version.pykinde_sdk/management/__init__.py
Makes
kinde_sdk/_version.pythe source of truth for the SDK version: the top-level package, both generated sub-packages, andpyproject.tomlnow all derive from it.Generator scripts read the same value to set
packageVersion, and bumps the SDK to 2.3.0.Adds a regression test that fail if any of those four versions ever go out of sync.
Checklist
🛟 If you need help, consider asking for advice over in the Kinde community.