SWEET_python reports which commit it was installed from - #69
Merged
Merged
Conversation
The DST endpoints call this package when a request comes in, so whatever model code is in the deployed API image is live immediately -- there is no pipeline run and no manifest to look it up in. Nothing logged which commit that was. What we did record could also be wrong. WasteMAP's Dockerfiles install this with `pip install ...@$REF || pip install ...@main`, so an image built from a ref this repo does not have silently gets main, while the release manifest goes on recording the ref. __version__ is now the commit this copy was installed from: SWEET_GIT_SHA if the image build passed it, else a .git read beside the package, else the string "unknown" with VERSION_SOURCE saying which. It invents nothing. A wrong SHA in a log is worse than no SHA, because a reader believes it. This is not a version number and does not add one. SWEET_python never ships on its own -- it reaches production only inside a Climate TRACE run or a WasteMAP deploy, and both are already identified. A number maintained by hand here would be a second, weaker name for a commit already recorded automatically in every run's manifest. setup.py's version="0.1" is unchanged, now with a comment saying it is decoration. The .git check runs before any subprocess, so importing this in a container costs nothing: the image holds source, not a repository, and every multiprocessing worker imports it. Pairs with the WasteMAP branch of the same name, which passes SWEET_GIT_SHA into both images and logs it at API startup. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
HughRunyan
force-pushed
the
wastemap-says-which-model-it-is-running
branch
from
September 28, 2026 22:53
096d440 to
b6cd48e
Compare
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 this is
SWEET_python.__version__now tells you the git commit this copy was installed from.Why
The DST endpoints (
/sdst,/adst,/cdst) call SWEET_python when a request comes in,so whatever model code is in the deployed API image is live immediately — there is no
pipeline run and no manifest to look it up in. Nothing logged which commit that was.
Worse, what we recorded could be wrong. WasteMAP's Dockerfiles install SWEET_python with
pip install …@$REF || pip install …@main. If$REFdoes not exist in this repo, theimage silently gets
maininstead, while the release manifest goes on recording$REF.How it resolves
In order, inventing nothing:
SWEET_GIT_SHA, which the image build now sets from the ref it actually installed.gitdirectory beside the package, for a local editable checkout"unknown"VERSION_SOURCEsays which of the three it was. A wrong SHA in a log is worse than noSHA, because a reader believes it.
No version number, on purpose
This does not add a
1.4.2-style version, andsetup.py'sversion="0.1"is leftexactly as it is (now with a comment saying it is decoration).
SWEET_python never ships on its own. It reaches production only inside a Climate TRACE
run or a WasteMAP deploy, and both of those are already identified — by a
run_idand arelease tag. A number maintained by hand here would be a second, weaker name for a commit
already recorded automatically, and it would need bumping on every model change by the
same person who has to remember the tag.
Background:
VERSIONING.mdinRMI_Climate_TRACE_Waste_Methane#181.
Pairing
Goes with WasteMAP branch
wastemap-says-which-model-it-is-running(RMI/WasteMAP#833), which resolves the ref in the deploy workflow, passes
SWEET_GIT_SHAinto both images, and prints it when the API starts.
Acceptance criteria
SWEET_GIT_SHAwins when set; a blank or whitespace value falls through to the next sourceHEAD"unknown", never a guessversion_info()returns the source alongside the value.gitcheck comes first, and every multiprocessing worker imports thisDefinition of done
247 passed, 6 of them new (tests/test_version_stamp.py)setup.pyis annotated🤖 Generated with Claude Code