fix: derive sub-package __version__ from a single source of truth#182
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
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
WalkthroughCentralizes SDK version handling in ChangesVersion consolidation to single source of truth
Estimated code review effort: 4 (Complex) | ~45 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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
dtoxvanilla1991
left a comment
There was a problem hiding this comment.
Good work, left some comments.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@testv2/testv2_core/test_version_sync.py`:
- Around line 53-67: The test test_distribution_metadata_matches_source_of_truth
currently skips entirely when dist_version("kinde-python-sdk") raises
PackageNotFoundError; instead, preserve the installed-metadata assertion path
but change the except block to read the version from pyproject.toml and assert
it equals kinde_sdk._version (i.e., don't call pytest.skip on
PackageNotFoundError); use dist_version for the installed case, and in the
fallback parse pyproject.toml (or use tomlkit/pip's metadata API) to extract the
version string and compare it to kinde_sdk._version so drift is detected in raw
checkouts as well.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 0f61f49c-2634-4450-9592-ae5f84923311
⛔ Files ignored due to path filters (3)
openapitools.jsonis excluded by!**/*.jsonpoetry.lockis excluded by!**/*.lock,!**/*.lockpyproject.tomlis excluded by!**/*.toml
📒 Files selected for processing (5)
.gitignoregenerate_frontend_sdk.pygenerate_management_sdk.pykinde_sdk/_version.pytestv2/testv2_core/test_version_sync.py
✅ Files skipped from review due to trivial changes (1)
- .gitignore
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.