Skip to content

SWEET_python reports which commit it was installed from - #69

Merged
HughRunyan merged 1 commit into
mainfrom
wastemap-says-which-model-it-is-running
Sep 28, 2026
Merged

HughRunyan merged 1 commit into
mainfrom
wastemap-says-which-model-it-is-running

Conversation

@HughRunyan

@HughRunyan HughRunyan commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

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 $REF does not exist in this repo, the
image silently gets main instead, while the release manifest goes on recording $REF.

How it resolves

In order, inventing nothing:

  1. SWEET_GIT_SHA, which the image build now sets from the ref it actually installed
  2. a .git directory beside the package, for a local editable checkout
  3. the string "unknown"

VERSION_SOURCE says which of the three it was. A wrong SHA in a log is worse than no
SHA, because a reader believes it.

No version number, on purpose

This does not add a 1.4.2-style version, and setup.py's version="0.1" is left
exactly 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_id and a
release 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.md in
RMI_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_SHA
into both images, and prints it when the API starts.

Acceptance criteria

  • SWEET_GIT_SHA wins when set; a blank or whitespace value falls through to the next source
  • A local editable checkout reports its own HEAD
  • An install that can read neither reports "unknown", never a guess
  • version_info() returns the source alongside the value
  • Importing the package in a container starts no subprocess — the .git check comes first, and every multiprocessing worker imports this

Definition of done

  • Acceptance criteria met
  • Tests pass — 247 passed, 6 of them new (tests/test_version_stamp.py)
  • Docs updated — the package docstring explains it; setup.py is annotated
  • Reviewed & merged

🤖 Generated with Claude Code

@HughRunyan HughRunyan added enhancement New feature or request test Adds or modifies tests labels Sep 28, 2026
@HughRunyan HughRunyan changed the title SWEET says which commit it is, so a caller can log which model it ran SWEET_python reports which commit it was installed from Sep 28, 2026
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
HughRunyan force-pushed the wastemap-says-which-model-it-is-running branch from 096d440 to b6cd48e Compare September 28, 2026 22:53
@HughRunyan
HughRunyan merged commit c498523 into main Sep 28, 2026
2 checks passed
@HughRunyan
HughRunyan deleted the wastemap-says-which-model-it-is-running branch September 28, 2026 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request test Adds or modifies tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant