Skip to content

Commit

Permalink
docs: move git introspection to Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
SnoopJ committed Nov 14, 2023
1 parent a755e02 commit b86c872
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 13 additions & 9 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b86c872

Please sign in to comment.