diff --git a/pueblo/sphinx/__init__.py b/pueblo/sphinx/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pueblo/sphinx/inventory.py b/pueblo/sphinx/inventory.py new file mode 100644 index 0000000..7e4edd8 --- /dev/null +++ b/pueblo/sphinx/inventory.py @@ -0,0 +1,44 @@ +# ruff: noqa: T201 +from sphinx.ext.intersphinx import fetch_inventory, inspect_main + + +class SphinxInventoryDecoder: + """ + Decode and process intersphinx inventories created by Sphinx. + + https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html + """ + + def __init__(self, name: str, url: str): + self.name = name + self.url = url + + def as_text(self): + inspect_main([self.url]) + + def as_markdown(self, omit_documents: bool = False, labels_only: bool = False): + class MockConfig: + intersphinx_timeout: int | None = None + tls_verify = False + tls_cacerts: str | dict[str, str] | None = None + user_agent: str = "" + + class MockApp: + srcdir = "" + config = MockConfig() + + app = MockApp() + inv_data = fetch_inventory(app, "", self.url) + print(f"# {self.name}") + for key in sorted(inv_data or {}): + if omit_documents and key == "std:doc": + continue + if labels_only and key != "std:label": + continue + print(f"## {key}") + inv_entries = sorted(inv_data[key].items()) + print("```text") + for entry, (_proj, _ver, url_path, display_name) in inv_entries: + display_name = display_name * (display_name != "-") + print(f"{entry: <40} {display_name: <40}: {url_path}") + print("```") diff --git a/pyproject.toml b/pyproject.toml index 3cc5a90..12bfabe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -70,7 +70,7 @@ dependencies = [ [project.optional-dependencies] all = [ - "pueblo[cli,dataframe,fileio,nlp,notebook,proc,testing,web]", + "pueblo[cli,dataframe,fileio,nlp,notebook,proc,sphinx,testing,web]", ] cli = [ "click<9", @@ -117,6 +117,9 @@ release = [ "build<2", "twine<6", ] +sphinx = [ + "sphinx", +] test = [ "pueblo[testing]", ]