feat(cli): identify the running version on every envelope (WI-P2)#97
Merged
Conversation
Nothing in the package identified itself: no `__version__`, no field on the envelope. A consumer holding a response could not tell whether a missing field meant "this release doesn't support it" or "the call failed" — and a checkout on sys.path answers in place of the installed release with no way to notice, so "which version told me this?" had no answer at all. `__version__` is a literal in `moleg_api/_version.py`, not an importlib.metadata lookup, because metadata describes the *installed distribution* while the code that runs may come from elsewhere. A literal travels with the code, so the version an envelope reports is always the one that produced it. pyproject reads that attribute via [tool.setuptools.dynamic], so build and runtime cannot disagree; a test pins that wiring, since a duplicated literal drifts the first time one side is bumped and the other is forgotten. Stamped inside `_emit` rather than at each call site so no envelope — success, error, or catalog — can ship without it, including usage errors raised before a command is even parsed. `--version` now reports the same literal instead of distribution metadata, so the flag and the envelope can no longer disagree. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
tomllib is stdlib only from 3.11; this package supports 3.10 with zero dependencies, so the guard has to parse the file without it. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
What
The package never said which version answered. No
moleg_api.__version__, noversionfield on the envelope. Two consequences for a consumer:sys.pathshadows site-packages, sopython -m moleg_apiruns checkout code while the install stays untouched. Nothing in the response revealed which one had answered.How
moleg_api/_version.pyholds the version as a literal, not animportlib.metadatalookup. Metadata describes the installed distribution; the code that actually runs may come from somewhere else. A literal travels with the code, so the version on an envelope is always the version that produced it.pyproject.tomlreads that attribute through[tool.setuptools.dynamic], making the package the single source of truth. A test pins the wiring — a literal duplicated inpyproject.tomldrifts the moment one side is bumped and the other is forgotten, and the resulting wheel reports a version its own code disagrees with._emit, the one funnel all output passes through, so no envelope can ship without it — success, error, catalog, and usage errors raised before a command is even parsed.--versionnow reports the same literal rather than distribution metadata, so the flag and the envelope cannot disagree.Verification
python -m build+twine checksucceed with the dynamic version (0.2.4 resolved from the package literal).🤖 Generated with Claude Code