Skip to content

Commit 4f67494

Browse files
authored
Merge pull request #94 from WhereGroup/docs/autogenerate-qdt-snippet
add(docs): auto generate QDT snippet and use keepachangelog to retrieve latest published verison from CHANGELOG.md
2 parents d143c48 + 691a7ed commit 4f67494

File tree

5 files changed

+58
-11
lines changed

5 files changed

+58
-11
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,4 @@ profile_manager/**/*.db
146146
# packaging
147147
plugins.xml
148148
zip_build
149+
docs/static/qdt_snippet.json

docs/conf.py

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,42 @@
55
"""
66

77
# standard
8+
import json
9+
import logging
810
import sys
911
from datetime import datetime
10-
from os import path
12+
from pathlib import Path
13+
from typing import Union
1114

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
1320

1421
# Package
1522
from profile_manager import __about__
1623

24+
logger: logging.Logger = logging.getLogger(__name__)
25+
1726
# -- 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
2337

2438
# -- General configuration ---------------------------------------------------
2539

2640
# Add any Sphinx extension module names here, as strings. They can be
2741
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
2842
# ones.
29-
extensions = [
43+
extensions: list[str] = [
3044
# Sphinx included
3145
"sphinx.ext.autodoc",
3246
"sphinx.ext.autosectionlabel",
@@ -127,18 +141,38 @@
127141
myst_url_schemes = ("http", "https", "mailto")
128142

129143

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+
130161
# -- API Doc --------------------------------------------------------
131162
# run api doc
132163
def run_apidoc(_):
133164
from sphinx.ext.apidoc import main
134165

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())
138171
exclusions = ["../.venv", "../tests"]
139172
main(["-e", "-f", "-M", "-o", output_path, modules] + exclusions)
140173

141174

142175
# launch setup
143176
def setup(app):
144177
app.connect("builder-inited", run_apidoc)
178+
app.connect("builder-inited", generate_qdt_snippet)

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ caption: Usage
1616
maxdepth: 1
1717
---
1818
usage/installation
19+
usage/with_qdt
1920
```
2021

2122
```{toctree}

docs/usage/with_qdt.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Using this plugin with QGIS Deployment Toolbelt (QDT)
2+
3+
If you want to use this plugin with [QGIS Deployment Toolbelt (QDT)](https://qgis-deployment.github.io/qgis-deployment-toolbelt-cli/), you can add the following snippet to your `profile.json` file, under the `plugins` attribute:
4+
5+
```{eval-rst}
6+
.. literalinclude:: ../static/qdt_snippet.json
7+
:language: json
8+
```
9+
10+
Remember to replace the `version` attribute with the version you want to install.

requirements/documentation.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# -----------------------
33

44
furo>=2024
5+
keepachangelog>=2.0.0
56
myst-parser[linkify]>=2
67
sphinx-autobuild>=2024
78
sphinx-copybutton>=0.5,<1

0 commit comments

Comments
 (0)