Skip to content

Derive the version from distribution metadata in one place - #87

Open
tschm wants to merge 1 commit into
alihaskar:masterfrom
tschm:fix/83-version-single-source
Open

Derive the version from distribution metadata in one place#87
tschm wants to merge 1 commit into
alihaskar:masterfrom
tschm:fix/83-version-single-source

Conversation

@tschm

@tschm tschm commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Closes #83

Problem

Three different versions shipped in the same artifact:

Location Was
pyproject.toml:3 0.2.16
src/pycharting/__init__.py:46 0.2.14
src/pycharting/core/server.py:121 0.1.0

pycharting.__version__ was two patch releases stale, and /api/docs plus the OpenAPI schema advertised 0.1.0.

Change

Both sites 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.interfacecore.lifecyclecore.server.

The # Keep this in sync with pyproject.toml comment is gone, because nothing needs syncing by hand now.

Why the tests didn't catch it

test_openapi_has_version and test_app_has_correct_metadata asserted 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 — clean
  • pycharting.__version__ and create_app().version both resolve to 0.2.16

🤖 Generated with Claude Code

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>
Copilot AI lite review requested due to automatic review settings August 17, 2026 08:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 into FastAPI(..., 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",
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.

Reconcile three divergent version strings

2 participants