diff --git a/build.py b/build.py index e486a4c..cf6dcf8 100644 --- a/build.py +++ b/build.py @@ -83,6 +83,35 @@ def overlay(content, dest): tar.extractall(dest, members=members, filter="data") +def provenance(content, tag): + """The commit the text of a build comes from ({"ref": ...} or {"source": ...}), its date, and + the release tag of its version if that exists: the footer of each specification page links + them (site/_templates/spec-source.html). None when no commit is known, e.g. for a directory + that is not a git checkout.""" + if content.get("source"): + source = Path(content["source"]).resolve() + run = subprocess.run(["git", "-C", str(source), "rev-parse", "--show-toplevel"], capture_output=True, text=True) + if run.returncode or Path(run.stdout.strip()).resolve() != source: # not a checkout of its own + return None + head = subprocess.run( + ["git", "-C", str(source), "log", "-1", "--format=%H %cs"], capture_output=True, text=True + ) + status = subprocess.run(["git", "-C", str(source), "status", "--porcelain"], capture_output=True, text=True) + ref, dirty = None, bool(status.stdout.strip()) + else: + head = git("log", "-1", "--format=%H %cs", resolve(content["ref"]), check=False) + ref, dirty = content["ref"], False + if head.returncode or not head.stdout.strip(): + return None + commit, date = head.stdout.split() + info = {"ref": ref, "commit": commit, "date": date, "dirty": dirty} + tagged = git("rev-parse", "--verify", "--quiet", f"refs/tags/{tag}^{{commit}}", check=False) if tag else None + if tagged and tagged.returncode == 0: + info["tag"] = tag + info["released"] = tagged.stdout.strip() == commit and not dirty + return info + + PAGES = HERE / "pages" # pages of the site itself, built only at the root (latest) @@ -162,6 +191,7 @@ def build(version, listed, out, tmp, site_url, strict, preview_pr, preview_of): "SPEC_LATEST": "1" if version.get("latest") else "0", "SPEC_PREVIEW_PR": preview_pr, "SPEC_PREVIEW_OF": preview_of, + "SPEC_SOURCE": json.dumps(version.get("provenance", {})), "SITE_URL": site_url, } cmd = [sys.executable, "-m", "sphinx", "-b", "html", "-d", str(src / "_doctrees"), str(docs), str(out / path)] @@ -421,10 +451,19 @@ def main(): rfcs = {"source": args.rfcs_source} if args.rfcs_source else listing["rfcs"] latest = {"ref": preferred["ref"], "source": preferred.get("source"), "latest": True, "rfcs_from": rfcs} versions = [latest, *data_models(versions), *versions] + # the release tag of each storage format version, by the branch its text comes from + release_tags = {v["ref"]: f"storage-format-{v['storage_format']}" for v in listing["version"]} for version in versions: # the root and a preview show the data model of the preferred version model = version.get("data_model") or preferred["data_model"] if model in data_model_from: version["data_model_from"] = data_model_from[model] + sources = { + "content": provenance(version, release_tags.get(version["ref"])), + "data_model": provenance(version["data_model_from"], f"data-model-{model}") + if version.get("data_model_from") + else None, + } + version["provenance"] = {k: v for k, v in sources.items() if v} shutil.rmtree(args.out, ignore_errors=True) args.out.mkdir(parents=True, exist_ok=True) # a server may hold the emptied directory open diff --git a/pages/contributing.md b/pages/contributing.md index 07b92f2..8caa4f9 100644 --- a/pages/contributing.md +++ b/pages/contributing.md @@ -109,7 +109,9 @@ moved. Each branch holds the current version of its part, with the corrections made since its release: bug fixes to the prose, clarifications and non-normative additions, which do not open a new version. -They are pull requests against the branch, and the website shows them once merged. Older versions +They are pull requests against the branch, and the website shows them once merged. Under its +title, each specification page says whether its text is as released or corrected since, linking the +changes; its footer names the commit the text was built from and the release tag. Older versions stay as tagged; a correction to one, if needed, goes into a branch `maintenance/storage-format-` (or `maintenance/data-model-`) made from its tag, which the website then shows. A correction that touches both parts is two pull requests, one diff --git a/site/_static/css/custom.css b/site/_static/css/custom.css index aba7b41..1fb44f7 100644 --- a/site/_static/css/custom.css +++ b/site/_static/css/custom.css @@ -350,6 +350,17 @@ h1 img.heading-icon { font-size: 1.05rem; } +/* Version and status of a specification page, under its title (conf.py _add_status) */ +.spec-status { + margin-top: -0.75rem; + margin-bottom: 1.5rem; + color: var(--pst-color-text-muted); + font-size: 0.95rem; +} +.spec-status + .spec-authors { + margin-top: -1rem; +} + /* ORCID iD and GitHub icons after a name (_ext/spec_authors.py) */ .bd-content img.person-icon { display: inline; diff --git a/site/_templates/.gitkeep b/site/_templates/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/site/_templates/spec-source.html b/site/_templates/spec-source.html new file mode 100644 index 0000000..534e2c4 --- /dev/null +++ b/site/_templates/spec-source.html @@ -0,0 +1,17 @@ +{#- Where the text of a specification page comes from (conf.py _sources), for citing it exactly: + the commit it was built from, the release tag of its version, the changes since the release. -#} +{%- for s in spec_sources %} +

+ {{ s.name }} {{ s.version }} text: + {%- if s.released %} + as released, tag {{ s.tag }} (commit {{ s.commit }}). + {%- else %} + commit {{ s.commit }} of {{ s.date }}{% if s.ref %} (branch {{ s.ref }}){% endif %} + {%- if s.dirty %}, with local changes{% endif %} + {%- if s.tag %}; released as {{ s.tag }}, + changes since. + {%- else %}; not released yet. + {%- endif %} + {%- endif %} +

+{%- endfor %} diff --git a/site/conf.py b/site/conf.py index 4a064ce..bad8844 100644 --- a/site/conf.py +++ b/site/conf.py @@ -4,6 +4,7 @@ import dataclasses import json import os +import re import sys from datetime import datetime from importlib.metadata import metadata @@ -45,6 +46,8 @@ spec_doc_path = os.environ.get("SPEC_DOC_PATH", "docs") # branch or tag the text of the data model comes from (empty: the content's own) spec_data_model_ref = os.environ.get("SPEC_DATA_MODEL_REF", "") +# the commit, date and release tag of the content and of the data model text (build.py provenance) +spec_source = json.loads(os.environ.get("SPEC_SOURCE", "{}")) DATA_MODEL_PAGES = ("data-model", "data-model-versions") SPEC_PAGES = (*DATA_MODEL_PAGES, "storage-format", "storage-format-versions", "storage-format-conformance") @@ -180,6 +183,8 @@ def _editable(ref): "show_toc_level": 2, "footer_start": [], # the content footer already holds the author and the copyright "footer_end": [], + # where the text of a specification page comes from: commit, release tag, changes since + "footer_content_items": ["author.html", "copyright.html", "spec-source.html"], "announcement": announcement, "logo": { "text": "SpatialData specifications", @@ -272,7 +277,77 @@ def walk(buttons): context["header_buttons"] = walk(context["header_buttons"]) +def _sources(pagename): + """The texts a specification page shows, each with the links of its source line: the file at the + commit it was built from, the file as released, and the changes since the release. The storage + format page includes the data model text, so it has two.""" + if pagename not in SPEC_PAGES: + return [] + parts = ["data_model"] if pagename in DATA_MODEL_PAGES else ["content"] + if pagename == "storage-format": + parts.append("data_model") + sources = [] + for part in parts: + source = spec_source.get(part) + if part == "data_model" and source is None and pagename in DATA_MODEL_PAGES: + part, source = "content", spec_source.get("content") # no data model branch: its own + if source is None: + continue + # the data model branch holds its pages at the top level; the content in spec_doc_path + path = f"{'data-model' if pagename == 'storage-format' and part == 'data_model' else pagename}.md" + if part == "content" and spec_doc_path: + path = f"{spec_doc_path}/{path}" + commit, tag = source["commit"], source.get("tag") + own_version = spec_data_model if part == "data_model" else spec_storage_format + sources.append( + { + "name": "Data model" if part == "data_model" else "Storage format", + "version": tag.rsplit("-", 1)[1] if tag else own_version, + "label": ("Data model text" if part == "data_model" else "Storage format text") + if pagename == "storage-format" + else "This text", + "ref": source.get("ref"), + "commit": commit[:7], + "date": source["date"], + "dirty": source.get("dirty"), + "url": f"{repository_url}/blob/{commit}/{path}", + "tag": tag, + "released": source.get("released"), + "tag_url": f"{repository_url}/blob/{tag}/{path}" if tag else None, + "compare_url": f"{repository_url}/compare/{tag}...{commit}" if tag else None, + } + ) + return sources + + +def _status(s): + """One part of the status line: "Storage format 0.4, corrected 16 Nov 2026", the date linking + to the changes since the release; the commits and tags are in the footer (spec-source.html).""" + date = datetime.strptime(s["date"], "%Y-%m-%d") + day = f"{date.day} {date:%b %Y}" + what = f"{s['name']} {s['version']}".strip() + local = ", with local changes" if s["dirty"] else "" + if s["released"]: + return f"{what}, [as released]({s['tag_url']})" + if s["tag"]: + return f'{what}, [corrected {day}]({s["compare_url"]} "Changes since the release"){local}' + return f"{what}, [draft of {day}]({s['url']}){local}" + + +_H1 = re.compile(r"^# .+$", re.M) + + +def _add_status(app, docname, source): + """Under the title of each specification page, above the authors (_ext/spec_authors.py): its + version, and whether its text is as released or corrected since.""" + parts = [_status(s) for s in _sources(docname)] + if parts: + block = "\n\n:::{container} spec-status\n" + " ยท ".join(parts) + "\n:::\n" + source[0] = _H1.sub(lambda m: m.group(0) + block, source[0], count=1) + + def _page_context(app, pagename, templatename, context, doctree): + context["spec_sources"] = _sources(pagename) toctree = context.get("generate_toctree_html") if toctree is not None: @@ -293,6 +368,7 @@ def navigation(kind, *args, **kwargs): def setup(app): + app.connect("source-read", _add_status, priority=600) # after spec_authors: above its byline # after the post-transforms, which is where MyST adds the footnotes app.connect("doctree-resolved", _footnotes_into_notes) app.connect("html-page-context", _page_context, priority=900) # after the theme adds its functions