Skip to content

Commit 857abeb

Browse files
committed
docs(refactor[widgets]): switch widget imports to docs._ext.widgets
why: Use one canonical module path for the docs widget extension so tools and tests resolve it consistently. what: - load the Sphinx extension via docs._ext.widgets - put the repo root on sys.path for docs and widget tests - update widget test imports to the canonical package path
1 parent 86d2b90 commit 857abeb

3 files changed

Lines changed: 15 additions & 15 deletions

File tree

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
project_root = cwd.parent
2020
project_src = project_root / "src"
2121

22+
sys.path.insert(0, str(project_root))
2223
sys.path.insert(0, str(project_src))
23-
sys.path.insert(0, str(cwd / "_ext"))
2424

2525
# package data
2626
about: dict[str, str] = {}
@@ -40,7 +40,7 @@
4040
"sphinx_autodoc_api_style",
4141
"sphinx.ext.todo",
4242
"sphinx_autodoc_fastmcp",
43-
"widgets",
43+
"docs._ext.widgets",
4444
],
4545
intersphinx_mapping={
4646
"python": ("https://docs.python.org/", None),

tests/docs/conftest.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""pytest config for widget tests: wire Sphinx's test fixtures + path.
22
33
``sphinx.testing.fixtures`` provides ``make_app``, ``app``, etc. that build a
4-
throw-away Sphinx project in a tmp dir. We also add ``docs/_ext`` to
5-
``sys.path`` so tests can import the ``widgets`` extension the same way
6-
``conf.py`` does in production.
4+
throw-away Sphinx project in a tmp dir. We also add the repo root to
5+
``sys.path`` so tests can import the docs extension via
6+
``docs._ext.widgets``, matching ``conf.py`` in production.
77
"""
88

99
from __future__ import annotations
@@ -17,9 +17,8 @@
1717

1818
_REPO_ROOT = pathlib.Path(__file__).resolve().parents[2]
1919
_DOCS_DIR = _REPO_ROOT / "docs"
20-
_EXT_DIR = _DOCS_DIR / "_ext"
21-
if str(_EXT_DIR) not in sys.path:
22-
sys.path.insert(0, str(_EXT_DIR))
20+
if str(_REPO_ROOT) not in sys.path:
21+
sys.path.insert(0, str(_REPO_ROOT))
2322

2423

2524
@pytest.fixture
@@ -44,8 +43,8 @@ def real_widget_srcdir(tmp_path: pathlib.Path, docs_dir: pathlib.Path) -> pathli
4443
(srcdir / "conf.py").write_text(
4544
f"""
4645
import sys
47-
sys.path.insert(0, {str(_EXT_DIR)!r})
48-
extensions = ["myst_parser", "widgets"]
46+
sys.path.insert(0, {str(_REPO_ROOT)!r})
47+
extensions = ["myst_parser", "docs._ext.widgets"]
4948
exclude_patterns = ["_build"]
5049
master_doc = "index"
5150
source_suffix = {{".md": "markdown"}}

tests/docs/test_widgets.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
import typing as t
1010

1111
import pytest
12-
from widgets import BaseWidget
13-
from widgets._base import make_highlight_filter
14-
from widgets._discovery import discover
15-
from widgets.mcp_install import (
12+
13+
from docs._ext.widgets import BaseWidget
14+
from docs._ext.widgets._base import make_highlight_filter
15+
from docs._ext.widgets._discovery import discover
16+
from docs._ext.widgets.mcp_install import (
1617
CLIENTS,
1718
METHODS,
1819
MCPInstallWidget,
@@ -73,7 +74,7 @@ def test_body_for_json_client_returns_config_snippet() -> None:
7374

7475
def test_body_for_unknown_kind_raises() -> None:
7576
"""An unrecognised ``client.kind`` surfaces as a ``ValueError``."""
76-
from widgets.mcp_install import Client
77+
from docs._ext.widgets.mcp_install import Client
7778

7879
fake = Client(id="x", label="X", kind="bogus", config_file="")
7980
with pytest.raises(ValueError, match="unknown client kind"):

0 commit comments

Comments
 (0)