2019-09-10 00:54:28 +00:00
|
|
|
# Copyright 2018 Virgil Dupras
|
|
|
|
#
|
|
|
|
# This software is licensed under the "GPLv3" License as described in the "LICENSE" file,
|
|
|
|
# which should be included with this package. The terms are also available at
|
|
|
|
# http://www.gnu.org/licenses/gpl-3.0.html
|
|
|
|
|
2021-08-26 08:29:24 +00:00
|
|
|
from pathlib import Path
|
2019-09-10 00:54:28 +00:00
|
|
|
import re
|
|
|
|
|
|
|
|
from .build import read_changelog_file, filereplace
|
2021-08-08 00:28:41 +00:00
|
|
|
from sphinx.cmd.build import build_main as sphinx_build
|
2019-09-10 00:54:28 +00:00
|
|
|
|
|
|
|
CHANGELOG_FORMAT = """
|
|
|
|
{version} ({date})
|
|
|
|
----------------------
|
|
|
|
|
|
|
|
{description}
|
|
|
|
"""
|
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2019-09-10 00:54:28 +00:00
|
|
|
def tixgen(tixurl):
|
|
|
|
"""This is a filter *generator*. tixurl is a url pattern for the tix with a {0} placeholder
|
|
|
|
for the tix #
|
|
|
|
"""
|
2021-08-15 09:10:18 +00:00
|
|
|
urlpattern = tixurl.format("\\1") # will be replaced buy the content of the first group in re
|
2020-01-01 02:16:27 +00:00
|
|
|
R = re.compile(r"#(\d+)")
|
2022-04-28 01:53:12 +00:00
|
|
|
repl = f"`#\\1 <{urlpattern}>`__"
|
2019-09-10 00:54:28 +00:00
|
|
|
return lambda text: R.sub(repl, text)
|
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
|
|
|
|
def gen(
|
|
|
|
basepath,
|
|
|
|
destpath,
|
|
|
|
changelogpath,
|
|
|
|
tixurl,
|
|
|
|
confrepl=None,
|
|
|
|
confpath=None,
|
|
|
|
changelogtmpl=None,
|
|
|
|
):
|
2019-09-10 00:54:28 +00:00
|
|
|
"""Generate sphinx docs with all bells and whistles.
|
|
|
|
|
|
|
|
basepath: The base sphinx source path.
|
|
|
|
destpath: The final path of html files
|
|
|
|
changelogpath: The path to the changelog file to insert in changelog.rst.
|
|
|
|
tixurl: The URL (with one formattable argument for the tix number) to the ticket system.
|
|
|
|
confrepl: Dictionary containing replacements that have to be made in conf.py. {name: replacement}
|
|
|
|
"""
|
|
|
|
if confrepl is None:
|
|
|
|
confrepl = {}
|
|
|
|
if confpath is None:
|
2021-08-26 08:29:24 +00:00
|
|
|
confpath = Path(basepath, "conf.tmpl")
|
2019-09-10 00:54:28 +00:00
|
|
|
if changelogtmpl is None:
|
2021-08-26 08:29:24 +00:00
|
|
|
changelogtmpl = Path(basepath, "changelog.tmpl")
|
2019-09-10 00:54:28 +00:00
|
|
|
changelog = read_changelog_file(changelogpath)
|
|
|
|
tix = tixgen(tixurl)
|
|
|
|
rendered_logs = []
|
|
|
|
for log in changelog:
|
2020-01-01 02:16:27 +00:00
|
|
|
description = tix(log["description"])
|
2019-09-10 00:54:28 +00:00
|
|
|
# The format of the changelog descriptions is in markdown, but since we only use bulled list
|
|
|
|
# and links, it's not worth depending on the markdown package. A simple regexp suffice.
|
2020-01-01 02:16:27 +00:00
|
|
|
description = re.sub(r"\[(.*?)\]\((.*?)\)", "`\\1 <\\2>`__", description)
|
2021-08-15 09:10:18 +00:00
|
|
|
rendered = CHANGELOG_FORMAT.format(version=log["version"], date=log["date_str"], description=description)
|
2019-09-10 00:54:28 +00:00
|
|
|
rendered_logs.append(rendered)
|
2020-01-01 02:16:27 +00:00
|
|
|
confrepl["version"] = changelog[0]["version"]
|
2021-08-26 08:29:24 +00:00
|
|
|
changelog_out = Path(basepath, "changelog.rst")
|
2020-01-01 02:16:27 +00:00
|
|
|
filereplace(changelogtmpl, changelog_out, changelog="\n".join(rendered_logs))
|
2021-08-26 08:29:24 +00:00
|
|
|
if Path(confpath).exists():
|
|
|
|
conf_out = Path(basepath, "conf.py")
|
2019-09-10 00:54:28 +00:00
|
|
|
filereplace(confpath, conf_out, **confrepl)
|
2021-08-08 00:28:41 +00:00
|
|
|
# Call the sphinx_build function, which is the same as doing sphinx-build from cli
|
|
|
|
try:
|
2021-08-26 08:29:24 +00:00
|
|
|
sphinx_build([str(basepath), str(destpath)])
|
2021-08-08 00:28:41 +00:00
|
|
|
except SystemExit:
|
2021-08-15 09:10:18 +00:00
|
|
|
print("Sphinx called sys.exit(), but we're cancelling it because we don't actually want to exit")
|