Skip to content

Commit

Permalink
Telemetry: track Sphinx extensions and html_theme variables (#9639)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
humitos committed Oct 17, 2022
1 parent 68fd63b commit 575afb8
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 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,6 +90,37 @@ def collect(self):
"all": all_apt_packages,
},
}
data["doctool"] = self._get_doctool()
return data

def _get_doctool_name(self):
if self.version.is_sphinx_type:
return "sphinx"

if self.version.is_mkdocs_type:
return "mkdocs"

return "generic"

def _get_doctool(self):
data = {
"name": self._get_doctool_name(),
"extensions": [],
"html_theme": "",
}

if self._get_doctool_name() != "sphinx":
return data

conf_py_dir = os.path.join(
self.checkout_path,
os.path.dirname(self.config.sphinx.configuration),
)
filepath = os.path.join(conf_py_dir, "_build", "json", "telemetry.json")
if os.path.exists(filepath):
with open(filepath, "r") as json_file:
content = json_file.read()
data.update(self._safe_json_loads(content, {}))
return data

def _get_all_conda_packages(self):
Expand Down

0 comments on commit 575afb8

Please sign in to comment.