Skip to content

Commit 575afb8

Browse files
authored
Telemetry: track Sphinx extensions and html_theme variables (#9639)
* Telemetry: track Sphinx `extensions` and `html_theme` variables Pretty simple implementation to track Sphinx's extensions and theme. This is not the best implementation, but I think it could be good as a first start. The new `doctool` key added will have this shape: ``` "doctool": { "extensions": [ "readthedocs_ext.readthedocs", "notfound.extension", "autoapi.extension", "sphinx_tabs.tabs", "sphinx-prompt", "sphinxemoji.sphinxemoji" ], "name": "sphinx", "theme": "sphinx_rtd_theme" }, ``` Closes #9627 * Lint * Lint * Use `Version.is___type()` to know if it's Sphinx/MkDocs or generic * Telemetry: use `readthedocs-sphinx-ext`'s dump to load the data Our extension is now dumping the data we want to consume here. So, we are just reading that file and saving it as part of the `BuildData` object. * These are properties, not functions * Missing `return` * Return `doctool` data even if the file does not exist
1 parent 68fd63b commit 575afb8

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

readthedocs/telemetry/collectors.py

+32
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Data collectors."""
22

33
import json
4+
import os
45

56
import dparse
67
import structlog
@@ -89,6 +90,37 @@ def collect(self):
8990
"all": all_apt_packages,
9091
},
9192
}
93+
data["doctool"] = self._get_doctool()
94+
return data
95+
96+
def _get_doctool_name(self):
97+
if self.version.is_sphinx_type:
98+
return "sphinx"
99+
100+
if self.version.is_mkdocs_type:
101+
return "mkdocs"
102+
103+
return "generic"
104+
105+
def _get_doctool(self):
106+
data = {
107+
"name": self._get_doctool_name(),
108+
"extensions": [],
109+
"html_theme": "",
110+
}
111+
112+
if self._get_doctool_name() != "sphinx":
113+
return data
114+
115+
conf_py_dir = os.path.join(
116+
self.checkout_path,
117+
os.path.dirname(self.config.sphinx.configuration),
118+
)
119+
filepath = os.path.join(conf_py_dir, "_build", "json", "telemetry.json")
120+
if os.path.exists(filepath):
121+
with open(filepath, "r") as json_file:
122+
content = json_file.read()
123+
data.update(self._safe_json_loads(content, {}))
92124
return data
93125

94126
def _get_all_conda_packages(self):

0 commit comments

Comments
 (0)