diff --git a/setup.py b/setup.py index 9b8d1bfe0e19c4d8d40689f86687b2986c81f6d9..6c2540fff23e3fd2b03f3b57ba82edd226d650d2 100644 --- a/setup.py +++ b/setup.py @@ -44,4 +44,5 @@ setup( "building": parse_requirements("swh"), }, include_package_data=True, + data_files=[("share/swh-docs", ["docs/devel/glossary.rst"])], ) diff --git a/swh/docs/sphinx/conf.py b/swh/docs/sphinx/conf.py index e14a26bff8c16f3aff4fcb7df1c9778cc17c9b85..bf46b5b3fbbd047617bbf38b71094525a0a0bc90 100644 --- a/swh/docs/sphinx/conf.py +++ b/swh/docs/sphinx/conf.py @@ -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():