mirror of
https://github.com/zrepl/zrepl.git
synced 2024-11-28 19:34:58 +01:00
8b0637ddcc
The sphinxcontrib-versioning seems unmaintainted and I can't get the fork that we used before this PR working on Python 3.10. The situation wrt maintenance doesn't seem much better for sphinx-multiversion, but, at least I could get it to work with current sphinx versions. The main problem with sphinx-multiversion is that it doesn't render anything at `/`. I.e., `https://zrepl.github.io/configuration.html` will be 404. That's different from `sphinxcontrib-versioning`, and thus switching to sphinx-multiversion would break URLs. We host on GitHub pages and don't control the webserver, so, we can't use webserver-level redirects to keep the URLs working. We could create JS-level redirects, or `http-equiv`, but that's ugly as well. The simplest solution was to fork sphinx-multiversion and hard-code zrepl's specific needs into that fork. The fork is based off v0.2.4 and pinned via requirements.txt. Here are its unique commits: https://github.com/Holzhaus/sphinx-multiversion/compare/master...zrepl:sphinx-multiversion:zrepl We should revisit `sphinx-polyversion` in the future once its docs improve. See https://github.com/Holzhaus/sphinx-multiversion/issues/88#issuecomment-1606221194 This PR updates the various Python packages, as I couldn't get sphinx-multiversion to work with the (very old) versions that were pinned in `requirements.txt` prior to this PR. This PR's `requirements.txt` is from a clean Python 3.10 venv on Ubuntu 22.10 after running ``` pip install sphinx sphinx-rtd-theme pip install 'git+https://github.com/zrepl/sphinx-multiversion/@52c915d7ad898d9641ec48c8bbccb7d4f079db93#egg=sphinx_multiversion' ```
73 lines
1.9 KiB
Python
73 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
|
|
from pathlib import Path
|
|
import subprocess
|
|
import re
|
|
import argparse
|
|
import distutils
|
|
|
|
argparser = argparse.ArgumentParser()
|
|
argparser.add_argument("docsroot")
|
|
argparser.add_argument("outdir")
|
|
args = argparser.parse_args()
|
|
|
|
output = subprocess.run(["git", "tag", "-l"], capture_output=True, check=True, text=True)
|
|
tagRE = re.compile(r"^v(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(-rc(?P<rc>\d+))?$")
|
|
class Tag:
|
|
orig: str
|
|
major: int
|
|
minor: int
|
|
patch: int
|
|
rc: int
|
|
|
|
def __str__(self):
|
|
return self.orig
|
|
|
|
def __repr__(self):
|
|
return self.orig
|
|
|
|
tags = []
|
|
for line in output.stdout.split("\n"):
|
|
m = tagRE.match(line)
|
|
if not m:
|
|
continue
|
|
m = m.groupdict()
|
|
|
|
t = Tag()
|
|
t.orig = line
|
|
t.major = int(m["major"])
|
|
t.minor = int(m["minor"])
|
|
t.patch = int(m["patch"])
|
|
t.rc = int(m["rc"] if m["rc"] is not None else 0)
|
|
|
|
tags.append(t)
|
|
|
|
by_major_minor = {}
|
|
|
|
for tag in tags:
|
|
key = (tag.major, tag.minor)
|
|
l = by_major_minor.get(key, [])
|
|
l.append(tag)
|
|
by_major_minor[key] = l
|
|
|
|
latest_by_major_minor = []
|
|
for (mm, l) in by_major_minor.items():
|
|
# sort ascending by patch-level (rc's weigh less)
|
|
l.sort(key=lambda tag: (tag.patch, int(tag.rc == 0), tag.rc))
|
|
latest_by_major_minor.append(l[-1])
|
|
latest_by_major_minor.sort(key=lambda tag: (tag.major, tag.minor))
|
|
|
|
cmdline = [
|
|
"sphinx-multiversion",
|
|
"-D", "smv_tag_whitelist=^({})$".format("|".join([re.escape(tag.orig) for tag in latest_by_major_minor])),
|
|
"-D", "smv_branch_whitelist=^(master|stable)$",
|
|
"-D", "smv_remote_whitelist=^.*$",
|
|
"-D", "smv_latest_version=stable",
|
|
"-D", r"smv_released_pattern=^refs/(tags|heads|remotes/[^/]+)/(?!master).*$", # treat everything except master as released, that way, the banner message makes sense
|
|
# "--dump-metadata", # for debugging
|
|
args.docsroot,
|
|
args.outdir,
|
|
]
|
|
print(cmdline)
|
|
subprocess.run(cmdline, check=True)
|