Make the local documentation build work, and document it - #36
hakonhagland wants to merge 5 commits into
Conversation
docs/conf.py picks the directory to read docstrings_common.json and docstrings_simulators.json from by branch name: release branches use the snapshots committed under python/, every other branch uses python/master-tmp/. opmdoc-download-files always wrote to python/, and wrote dune.module to the repository root, which matches neither layout. So on any branch other than a release branch, the documented sequence opmdoc-download-files make docs fails on a file the user has just downloaded: Exception occurred: FileNotFoundError: [Errno 2] No such file or directory: '.../python/master-tmp/docstrings_common.json' Pick the destination the same way conf.py does, and create python/master-tmp when it does not exist yet, as on a fresh clone. All three files now go to the same directory, which is also what the workflow does for the published build.
Checks that docstrings_dir() follows the same branch rule as docs/conf.py, and that it creates python/master-tmp when it is missing, which is the case on a fresh clone since that directory is gitignored.
The section pointed at .github/workflows/python_sphinx_docs.yml, which interleaves the local build with the multi-branch machinery, the gh-pages deployment and the CI-only setup, and does not say which parts someone building locally needs. Replace it with the four commands that do the job, and state the two things that are not discoverable from the workflow: that sphinx-versioned builds from git history rather than the working tree, so changes have to be committed first, and that the docstring JSON files come from opm-common and opm-simulators rather than from this repository. Also mention make view-docs and opmdoc-view-doc, which already exist but were only reachable through a link to another README, and note that the built pages open straight from disk without a web server.
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
README instructions may overwrite release-branch inputs and need correction before approval.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (1)
What changed in this PR
This PR fixes local documentation builds by aligning downloaded assets with branch-specific Sphinx paths and documenting the complete workflow.
Changes:
- Added branch-aware download destinations and tests.
- Creates
python/master-tmpwhen needed. - Expanded README setup, build, and viewing instructions.
| File | Summary |
|---|---|
README.md |
Documents the local workflow; requires updates for release-branch safety, portability, and virtualenv usage. |
python/sphinx_docs/tests/test_download_files.py |
Tests branch-specific destinations and fresh-clone directory creation. |
python/sphinx_docs/src/opm_python_docs/download_files.py |
Aligns downloaded files with the paths expected by the documentation build. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
The previous commits made opmdoc-download-files write where the build reads, following docs/conf.py's branch rule: python/master-tmp/ on most branches, python/ on release branches. That rule is right for reading but wrong for writing. On a release branch, python/ holds the committed snapshot of docstrings_common.json, docstrings_simulators.json and dune.module, taken from the release's own sources. Downloading master's copies there replaces that snapshot and leaves the files modified in the working tree, ready to be committed by mistake. Reproduced in a worktree of release-2026.04: the command wrote all three files and git status showed them modified. The code before this branch already overwrote the two JSON files there; the previous commits added dune.module. A release branch needs nothing downloaded, so the command now stops with an explanation and a non-zero exit before any request is made. docstrings_dir() therefore only returns python/master-tmp. The tests check both paths through main(): three files written to python/master-tmp/ on master, and on a release branch no request, no change to the snapshot, and no python/master-tmp created. The README says the download step is not for release branches.
The README told users to open the result with make view-docs, but that Makefile target runs xdg-open, which exists on Linux only; on macOS the documented step fails. opmdoc-view-doc opens the same page, python/sphinx_docs/docs/_build/ <branch>/index.html, through click.launch, which uses the platform's own opener. Without --branch it opens the current branch, as make view-docs does, so it replaces that step directly. The README already mentioned it for opening other branches.
|
Copilot's overview also flagged that the README instructions "may overwrite release-branch inputs", without filing it as a finding. It is right, and it is the more important of the two points. I reproduced it: on a release branch the download writes into |
I'd rather leave this out. |

Updated after Copilot's review: commits 4 and 5 added, and the statement about release branches under commit 1 corrected.
Following the repository's own instructions for building the documentation locally fails on any branch that is not a release branch.
opmdoc-download-fileswrites the docstring JSON files to a directory (pythonin the root) thatdocs/conf.pydoes not read (it readspython/master-tmp), so the build stops on a file the user has just downloaded:Download the files where the build looks for them (commit 1)
docs/conf.pypicks the directory by branch name: release branches read the snapshots committed underpython/, every other branch readspython/master-tmp/.opmdoc-download-filesalways wrote the JSON files topython/, and wrotedune.moduleto the repository root — That matches neither layout: on most branches the build readspython/master-tmp/, and on a release branchpython/holds the committed release snapshot, which the download overwrote (fixed in commit 4).docstrings_dir()now applies the same branch ruleconf.pydoes, and createspython/master-tmpwhen it is missing. For release branches that rule is wrong for writing, and commit 4 replaces it. That directory is gitignored, so it is absent on a fresh clone.Add tests for the destination (commit 2)
masterand an ordinary feature branch, asserting the directory each one resolves to. Commit 4 replaces the release-branch case.python/master-tmpdoes not exist yet and has to be created.Give the README the steps (commit 3)
The section previously read, in full, "Follow the commands in
.github/workflows/python_sphinx_docs.ymlfor your local setup!" That workflow interleaves the local build withsphinx-versioned's multi-branch machinery, the gh-pages deployment and CI-only setup, and does not indicate which parts a person building locally actually needs.It is replaced with the four commands that do the job, plus the two things that cannot be worked out from the workflow at all:
sphinx-versionedbuilds from git history, not from the working tree, so changes have to be committed before the build will see them. TheMakefilesays so in a comment; the README did not.opm-commonandopm-simulators, not from this repository, which is why a download step exists at all.It also mentions
make view-docsandopmdoc-view-doc, which already existed but were only reachable through a link to another README, and notes that the built pages open straight from disk — no web server needed, since the generated HTML references its stylesheet by relative path.Refuse to download on a release branch (commit 4)
release-2026.04, the download replaced the committedpython/docstrings_common.json,python/docstrings_simulators.jsonandpython/dune.modulewith master's copies and left them modified. The code before this PR already overwrote the two JSON files there; commit 1 addeddune.module.docstrings_dir()only returnspython/master-tmp.main()on a release branch makes no request, leaves the snapshot unchanged and creates nopython/master-tmp. A new test checks that onmasterall three files are written topython/master-tmp/.Use
opmdoc-view-docin the README (commit 5)make view-docsrunsxdg-open, which exists on Linux only, so the documented step failed on macOS (from Copilot's review). Step 3 now usesopmdoc-view-doc, which opens the same page throughclick.launchon any platform and defaults to the current branch.Verification
Reproduced the failure and confirmed the fix end to end: removed
python/master-tmpto stand in for a fresh clone, ranopmdoc-download-files, then built. Before commit 1 that sequence raised theFileNotFoundErrorabove and produced nosimulators.html. After it, the three files land inpython/master-tmp/, the build reportsbuild succeeded, andsimulators.htmlcontains the generated API documentation. The full test suite passes.After commit 4, the same release-branch worktree check exits with status 1 and the explanation,
git statusstays clean, and nopython/master-tmpis created. The full test suite passes: 6 tests.