Skip to content

Derive the docs version instead of hardcoding it - #477

Merged
ThomasMBury merged 1 commit into
ThomasMBury:mainfrom
energyscholar:docs/derive-version-from-package
Jul 30, 2026
Merged

Derive the docs version instead of hardcoding it#477
ThomasMBury merged 1 commit into
ThomasMBury:mainfrom
energyscholar:docs/derive-version-from-package

Conversation

@energyscholar

Copy link
Copy Markdown
Collaborator

Small follow-on to your docs pass this morning — different thing, so I split it out.

docs/source/conf.py had version = "2.1.1" hardcoded. It has to be bumped by hand, so it drifted: it was already stale for 2.1.2 and stayed stale through 2.1.3.

The reason nobody noticed is worth a sentence, because it's the actual bug. Only version was set, and sphinx_rtd_theme renders release. So the wrong number existed but was never displayed anywhere a reader could see it — the page title read "ewstools documentation" with no version at all.

This resolves the version instead:

  1. installed package metadata — which is how the docs are really built, since .readthedocs.yaml pip-installs the package and so does CI
  2. pyproject.toml, for a tree where the package isn't installed
  3. a literal fallback

and sets release as well as version, so it's actually rendered.

The resolver cannot raise. fail_on_warning: true is set, so an exception in conf.py would take the whole build down; every branch is wrapped and the last resort is the string unknown.

Verification

Built exactly as RTD does (docs/requirements.txt + the package, sphinx-build -W). Build clean, and the rendered title is now:

$ grep -o '[^<>]*2\.1\.3[^<>]*' index.html
ewstools &mdash; ewstools 2.1.3 documentation

Also checked the two fallbacks in isolation, since the first branch normally hides them: with the package absent it returns 2.1.3 from pyproject.toml, and on an interpreter without tomllib (3.10 and earlier) it returns unknown rather than raising.

One thing I did not change

.zenodo.json also pins "version": "v2.1.1" and a hardcoded "publication_date": "2023-02-10". I was going to clean those up in the same PR, but I couldn't confirm from Zenodo's own documentation what happens when those fields are omitted — their docs say publication_date defaults to the current date, but say nothing about version being taken from the release tag. Rather than guess in a metadata file, I've left it alone and mentioned it separately. It looks inert anyway: the Zenodo API only has the one 2023 record, so the GitHub integration doesn't appear to be firing.

No rush on this one.

docs/source/conf.py had to be bumped by hand, so it drifted: it still read
2.1.1 while the package was on 2.1.3. It went unnoticed because only `version`
was set, and the RTD theme renders `release` -- so the wrong value was never
displayed anywhere a reader would see it.

Resolve the version from installed package metadata first, since that is how
the docs are actually built (.readthedocs.yaml installs the package, and so
does CI), falling back to pyproject.toml for a tree where the package is not
installed, and finally to a literal. The resolver cannot raise: fail_on_warning
is set, so an exception here would take the whole build down.

Set `release` as well as `version`, so the number is actually rendered. The
page title changes from "ewstools documentation" to "ewstools 2.1.3
documentation".
@ThomasMBury

Copy link
Copy Markdown
Owner

thanks - looks good

@ThomasMBury ThomasMBury left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

looks good

@ThomasMBury
ThomasMBury merged commit a747d8a into ThomasMBury:main Jul 30, 2026
9 checks passed
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.

2 participants