Skip to content

Telemetry: track Sphinx extensions and html_theme variables #9639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 17, 2022
49 changes: 49 additions & 0 deletions readthedocs/telemetry/collectors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Data collectors."""

import json
import os

import dparse
import structlog
Expand Down Expand Up @@ -89,8 +90,56 @@ def collect(self):
"all": all_apt_packages,
},
}
data["doctool"] = {
"name": self._get_doctool_name(),
"extensions": self._get_doctool_extensions(),
"theme": self._get_doctool_theme(),
}
return data

def _get_doctool_name(self):
if self.config.sphinx:
return "sphinx"

if self.config.mkdocs:
return "mkdocs"

return "generic"

def _get_doctool_extensions(self):
if self._get_doctool_name() != "sphinx":
return []

code, stdout, _ = self.run(
"python",
"-c",
"import conf; import json; print(json.dumps(conf.extensions))",
cwd=os.path.join(
self.checkout_path,
os.path.dirname(self.config.sphinx.configuration),
),
)
if code == 0 and stdout:
return self._safe_json_loads(stdout, [])
return []

def _get_doctool_theme(self):
if self._get_doctool_name() != "sphinx":
return []

code, stdout, _ = self.run(
"python",
"-c",
"import conf; import json; print(json.dumps(conf.html_theme))",
cwd=os.path.join(
self.checkout_path,
os.path.dirname(self.config.sphinx.configuration),
),
)
if code == 0 and stdout:
return self._safe_json_loads(stdout, "")
return ""

def _get_all_conda_packages(self):
"""
Get all the packages installed by the user using conda.
Expand Down