From b86c8729a830c8cfa6fd21ad14a8fff0a53f8941 Mon Sep 17 00:00:00 2001 From: James Gerity Date: Mon, 13 Nov 2023 19:21:04 -0500 Subject: [PATCH] docs: move git introspection to Makefile --- Makefile | 8 ++++++++ docs/source/conf.py | 22 +++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 35decee8c..e7de4c346 100644 --- a/Makefile +++ b/Makefile @@ -43,6 +43,14 @@ clean_docs: build_docs: $(MAKE) -C docs html +.ONESHELL: +build_docs_preview: +ifneq "$(shell git status --untracked-files=no --porcelain)" "" + @export SOPEL_GIT_DIRTY=1 +endif + @export SOPEL_GIT_COMMIT="$$(git rev-parse HEAD)" + $(MAKE) build_docs + docs: build_docs cleandoc: clean_docs build_docs diff --git a/docs/source/conf.py b/docs/source/conf.py index 1fec02b24..d0b1a48b8 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -10,7 +10,7 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import subprocess +import os from datetime import date from packaging.version import Version @@ -313,17 +313,21 @@ #texinfo_show_urls = 'footnote' -try: - if Version(__version__).is_prerelease: - tags.add("preview") - - is_dirty = bool(subprocess.check_output(["git", "status", "--untracked-files=no", "--porcelain"], text=True).strip()) - commit_hash = subprocess.check_output(["git", "rev-parse", "HEAD"], text=True).strip() +commit_hash = os.environ.get("SOPEL_GIT_COMMIT", "")[:7] +is_dirty = bool(os.environ.get("SOPEL_GIT_DIRTY")) +if commit_hash: github_ref = "https://github.com/sopel-irc/sopel/commit/{commit_hash}".format(commit_hash=commit_hash) - build_info = "(built against `{commit_hash} <{github_ref}>`_)".format(commit_hash=commit_hash[:7], github_ref=github_ref) -except Exception as exc: + build_info = "(built against `{commit_hash}{dirty} <{github_ref}>`_)".format( + commit_hash=commit_hash[:7], + dirty="-dirty" if is_dirty else "", + github_ref=github_ref + ) +else: build_info = "(built against an unknown commit)" +if Version(__version__).is_prerelease or commit_hash: + tags.add("preview") + rst_prolog = """ .. only:: preview