Skip to content
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

Sphinx: Add inventory decoder for Sphinx #73

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added pueblo/sphinx/__init__.py
Empty file.
44 changes: 44 additions & 0 deletions pueblo/sphinx/inventory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# ruff: noqa: T201
from sphinx.ext.intersphinx import fetch_inventory, inspect_main

Check warning on line 2 in pueblo/sphinx/inventory.py

View check run for this annotation

Codecov / codecov/patch

pueblo/sphinx/inventory.py#L2

Added line #L2 was not covered by tests


class SphinxInventoryDecoder:

Check warning on line 5 in pueblo/sphinx/inventory.py

View check run for this annotation

Codecov / codecov/patch

pueblo/sphinx/inventory.py#L5

Added line #L5 was not covered by tests
"""
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

Check warning on line 14 in pueblo/sphinx/inventory.py

View check run for this annotation

Codecov / codecov/patch

pueblo/sphinx/inventory.py#L12-L14

Added lines #L12 - L14 were not covered by tests

def as_text(self):
inspect_main([self.url])

Check warning on line 17 in pueblo/sphinx/inventory.py

View check run for this annotation

Codecov / codecov/patch

pueblo/sphinx/inventory.py#L16-L17

Added lines #L16 - L17 were not covered by tests

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 = ""

Check warning on line 24 in pueblo/sphinx/inventory.py

View check run for this annotation

Codecov / codecov/patch

pueblo/sphinx/inventory.py#L19-L24

Added lines #L19 - L24 were not covered by tests

class MockApp:
srcdir = ""
config = MockConfig()

Check warning on line 28 in pueblo/sphinx/inventory.py

View check run for this annotation

Codecov / codecov/patch

pueblo/sphinx/inventory.py#L26-L28

Added lines #L26 - L28 were not covered by tests

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("```")

Check warning on line 44 in pueblo/sphinx/inventory.py

View check run for this annotation

Codecov / codecov/patch

pueblo/sphinx/inventory.py#L30-L44

Added lines #L30 - L44 were not covered by tests
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -117,6 +117,9 @@ release = [
"build<2",
"twine<6",
]
sphinx = [
"sphinx",
]
test = [
"pueblo[testing]",
]
Expand Down
Loading