|
15 | 15 |
|
16 | 16 | import sys |
17 | 17 | import os |
| 18 | +import subprocess |
18 | 19 |
|
19 | 20 | # If extensions (or modules to document with autodoc) are in another directory, |
20 | 21 | # add these directories to sys.path here. If the directory is relative to the |
|
37 | 38 | build_date = _dt.date.today().strftime("%d %b %Y") |
38 | 39 |
|
39 | 40 | # Values exposed to topindex.html and footer templates. |
| 41 | +# Resolve the parent (openmv-doc) repo's HEAD SHA at build time so |
| 42 | +# "Edit this page" and the AI dropdown's raw-source link both pin to |
| 43 | +# the exact commit that produced the page. Falls back to "master" if |
| 44 | +# `git` isn't available (e.g. shallow tarball checkouts). |
| 45 | +try: |
| 46 | + _parent_repo = os.path.abspath( |
| 47 | + os.path.join(os.path.dirname(__file__), "..", "..") |
| 48 | + ) |
| 49 | + source_version = subprocess.check_output( |
| 50 | + ["git", "rev-parse", "HEAD"], |
| 51 | + cwd=_parent_repo, |
| 52 | + stderr=subprocess.DEVNULL, |
| 53 | + ).decode().strip() |
| 54 | +except Exception: |
| 55 | + source_version = "master" |
| 56 | + |
40 | 57 | html_context = { |
41 | 58 | "openmv_version": openmv_version, |
42 | 59 | "micropython_version": micropython_version, |
43 | 60 | "build_date": build_date, |
44 | | - # Tells Shibuya where the page source lives — used as a fallback |
45 | | - # for the "Copy page" / "Open in ChatGPT/Claude/Perplexity" links |
46 | | - # when html_baseurl isn't set (in which case Shibuya reads from |
47 | | - # the deployed site's /_sources/ tree instead). |
| 61 | + # Tells Shibuya where the page source lives — used by the "Edit |
| 62 | + # this page" link, and as a fallback for the AI dropdown's |
| 63 | + # "Open in ChatGPT/Claude/Perplexity" raw-source links when |
| 64 | + # html_baseurl isn't reachable. Points at the user-facing |
| 65 | + # openmv-doc parent repo (GitHub renders submodule contents |
| 66 | + # through the parent's path). |
48 | 67 | "source_type": "github", |
49 | 68 | "source_user": "openmv", |
50 | 69 | "source_repo": "openmv-doc", |
51 | 70 | "source_docs_path": "/micropython/docs/", |
52 | | - "source_version": "master", |
| 71 | + "source_version": source_version, |
53 | 72 | } |
54 | 73 |
|
55 | 74 | # Site root — used by sphinx-llms-txt to emit absolute URLs in |
|
0 commit comments