Derive the version from distribution metadata in one place - #87
Open
tschm wants to merge 1 commit into
Open
Conversation
Three different versions shipped in the same artifact: 0.2.16 in
pyproject.toml, 0.2.14 in __init__.py (behind a "keep this in sync"
comment that had not been honoured for two releases), and 0.1.0 passed
to FastAPI, which is what /api/docs and the OpenAPI schema advertised.
Both now read importlib.metadata.version("pycharting"), so the manifest
is the only place to bump. server.py resolves it directly rather than
importing pycharting.__version__, which would be circular:
pycharting/__init__ -> api.interface -> core.lifecycle -> core.server.
test_openapi_has_version and test_app_has_correct_metadata asserted the
literal "0.1.0" — they pinned the stale value instead of catching the
drift, which is how this survived a 100% coverage gate. Both now compare
against the distribution metadata, and a new test asserts the served
version, pycharting.__version__ and the metadata all agree.
Closes alihaskar#83
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR reconciles previously divergent version strings by deriving both pycharting.__version__ and the FastAPI app’s advertised version from the installed distribution metadata (importlib.metadata.version("pycharting")), making pyproject.toml the single source of truth.
Changes:
- Update
pycharting.__version__to resolve from distribution metadata instead of a hard-coded literal. - Update
create_app()to pass the distribution version intoFastAPI(..., version=...). - Update/add tests to compare OpenAPI/app version against the distribution metadata and ensure all three version sources agree.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/pycharting/__init__.py |
Switches __version__ to be derived from installed distribution metadata. |
src/pycharting/core/server.py |
Switches FastAPI app version to be derived from installed distribution metadata. |
tests/pycharting/core/test_server.py |
Updates version assertions to compare against metadata and adds a drift-prevention test. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+41
to
+42
| from importlib.metadata import version as _distribution_version | ||
|
|
Comment on lines
119
to
123
| app = FastAPI( | ||
| title="PyCharting", | ||
| description="Interactive charting and data visualization API", | ||
| version="0.1.0", | ||
| version=_distribution_version("pycharting"), | ||
| docs_url="/api/docs", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #83
Problem
Three different versions shipped in the same artifact:
pyproject.toml:30.2.16src/pycharting/__init__.py:460.2.14src/pycharting/core/server.py:1210.1.0pycharting.__version__was two patch releases stale, and/api/docsplus the OpenAPI schema advertised0.1.0.Change
Both sites now read
importlib.metadata.version("pycharting"), so the manifest is the only place to bump.server.pyresolves it directly rather than importingpycharting.__version__, which would be circular:pycharting/__init__→api.interface→core.lifecycle→core.server.The
# Keep this in sync with pyproject.tomlcomment is gone, because nothing needs syncing by hand now.Why the tests didn't catch it
test_openapi_has_versionandtest_app_has_correct_metadataasserted the literal"0.1.0"— they pinned the stale value rather than detecting the drift, which is how this survived a 100% coverage gate. Both now compare against the distribution metadata, and a new test asserts the served version,pycharting.__version__and the metadata all agree.Verification
make test— 173 passed (was 172), coverage 100%make typecheck,make fmt— cleanpycharting.__version__andcreate_app().versionboth resolve to0.2.16🤖 Generated with Claude Code