Skip to content
Snippets Groups Projects
Commit b04e14ef authored by David Douard's avatar David Douard
Browse files

distribute the glossary.rst file as package data

Distribute this docs/devel/glossary.rst file as package data in
share/swh-docs since it is needed for locally building the doc
from swh packages.

Adapt the add_glossary_to_index sphinx hook to look for this file in
share/swh-docs in addition to the current relative path (which only
works if swh-docs in installed in editable with proper pip
config-settings and who knows what else). For local/editable installed
swh-docs, look a bit more than previously to attempt to catch the case
of editable_mode=strict pip config
parent fae28a33
No related branches found
No related tags found
No related merge requests found
......@@ -44,4 +44,5 @@ setup(
"building": parse_requirements("swh"),
},
include_package_data=True,
data_files=[("share/swh-docs", ["docs/devel/glossary.rst"])],
)
......@@ -5,7 +5,9 @@
import logging
import os
from pathlib import Path
import re
import sys
from typing import Dict
from sphinx import addnodes
......@@ -314,11 +316,21 @@ def set_django_settings(app, env, docname):
# to the terms it contains
def add_glossary_to_index(app, docname, source):
if docname == "index":
glossary_path = os.path.join(
os.path.dirname(__file__), "../../../docs/devel/glossary.rst"
lookup = (
Path(sys.prefix) / "share/swh-docs/glossary.rst",
Path(sys.prefix) / "local/share/swh-docs/glossary.rst",
Path(__file__).parents[3] / "docs/devel/glossary.rst",
Path(__file__).parents[4] / "docs/devel/glossary.rst",
Path(__file__).parents[5] / "docs/devel/glossary.rst",
)
with open(glossary_path, "r") as glossary:
source[0] += "\n" + glossary.read()
for glossary in lookup:
if glossary.is_file():
print(f"Injecting glossary from {glossary} in index")
with glossary.open("r") as f:
source[0] += "\n" + f.read()
break
else:
raise EnvironmentError("glossary file not found")
def get_sphinx_warning_handler():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment