|
5 | 5 | """ |
6 | 6 |
|
7 | 7 | # standard |
| 8 | +import json |
| 9 | +import logging |
8 | 10 | import sys |
9 | 11 | from datetime import datetime |
10 | | -from os import path |
| 12 | +from pathlib import Path |
| 13 | +from typing import Union |
11 | 14 |
|
12 | | -sys.path.insert(0, path.abspath("..")) # move into project package |
| 15 | +# move into project package |
| 16 | +sys.path.insert(0, f"{Path(__file__).parent.parent.resolve()}") |
| 17 | + |
| 18 | +# 3rd party |
| 19 | +import keepachangelog |
13 | 20 |
|
14 | 21 | # Package |
15 | 22 | from profile_manager import __about__ |
16 | 23 |
|
| 24 | +logger: logging.Logger = logging.getLogger(__name__) |
| 25 | + |
17 | 26 | # -- Project information ----------------------------------------------------- |
18 | | -author = __about__.__author__ |
19 | | -copyright = __about__.__copyright__ |
20 | | -description = __about__.__summary__ |
21 | | -project = __about__.__title__ |
22 | | -version = release = __about__.__version__ |
| 27 | +changes: dict[str, dict] = keepachangelog.to_dict("../CHANGELOG.md") |
| 28 | +latest_version: str = [ |
| 29 | + v for v in changes.keys() if v not in ("Unreleased", "version_tag") |
| 30 | +][0] |
| 31 | + |
| 32 | +author: str = __about__.__author__ |
| 33 | +copyright: str = __about__.__copyright__ |
| 34 | +description: str = __about__.__summary__ |
| 35 | +project: str = __about__.__title__ |
| 36 | +version = release = latest_version |
23 | 37 |
|
24 | 38 | # -- General configuration --------------------------------------------------- |
25 | 39 |
|
26 | 40 | # Add any Sphinx extension module names here, as strings. They can be |
27 | 41 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom |
28 | 42 | # ones. |
29 | | -extensions = [ |
| 43 | +extensions: list[str] = [ |
30 | 44 | # Sphinx included |
31 | 45 | "sphinx.ext.autodoc", |
32 | 46 | "sphinx.ext.autosectionlabel", |
|
127 | 141 | myst_url_schemes = ("http", "https", "mailto") |
128 | 142 |
|
129 | 143 |
|
| 144 | +# -- Functions ------------------------------------------------------------------ |
| 145 | +def generate_qdt_snippet(_) -> None: |
| 146 | + """Generate QDT snippet for profiles.json files.""" |
| 147 | + logger.warning("=== START GENERATING QDT SNIPPET ===") |
| 148 | + |
| 149 | + qdt_snippet: dict[str, Union[str, bool, int]] = { |
| 150 | + "name": "Profile Manager", |
| 151 | + "folder_name": "profile_manager", |
| 152 | + "official_repository": True, |
| 153 | + "plugin_id": 3547, |
| 154 | + "version": f"{ latest_version }", |
| 155 | + } |
| 156 | + |
| 157 | + with Path("./docs/static/qdt_snippet.json").open("w", encoding="UTF8") as wf: |
| 158 | + wf.write(json.dumps(qdt_snippet, indent=4, sort_keys=True)) |
| 159 | + |
| 160 | + |
130 | 161 | # -- API Doc -------------------------------------------------------- |
131 | 162 | # run api doc |
132 | 163 | def run_apidoc(_): |
133 | 164 | from sphinx.ext.apidoc import main |
134 | 165 |
|
135 | | - cur_dir = path.normpath(path.dirname(__file__)) |
136 | | - output_path = path.join(cur_dir, "_apidoc") |
137 | | - modules = path.normpath(path.join(cur_dir, "../profile_manager")) |
| 166 | + logger.info("=== START SPHINX API AUTODOC ===") |
| 167 | + |
| 168 | + cur_dir = Path(__file__).parent.resolve() |
| 169 | + output_path = str(cur_dir.joinpath("_apidoc").resolve()) |
| 170 | + modules = str(cur_dir.joinpath("../profile_manager/").resolve()) |
138 | 171 | exclusions = ["../.venv", "../tests"] |
139 | 172 | main(["-e", "-f", "-M", "-o", output_path, modules] + exclusions) |
140 | 173 |
|
141 | 174 |
|
142 | 175 | # launch setup |
143 | 176 | def setup(app): |
144 | 177 | app.connect("builder-inited", run_apidoc) |
| 178 | + app.connect("builder-inited", generate_qdt_snippet) |
0 commit comments