Skip to content

Commit ee9e3c1

Browse files
committed
refactor: reuse docs version helpers
1 parent 30a41a4 commit ee9e3c1

4 files changed

Lines changed: 25 additions & 13 deletions

File tree

src/mcp_server_python_docs/__main__.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ def _consume_saved_stdout_fd() -> int:
6666
# === Now safe to import everything else ===
6767
import click # noqa: E402
6868

69+
from mcp_server_python_docs.ingestion.cpython_versions import ( # noqa: E402
70+
SUPPORTED_DOC_VERSIONS_CSV,
71+
)
72+
6973

7074
@click.group(invoke_without_command=True)
7175
@click.option("--version", "show_version", is_flag=True, help="Show version and exit.")
@@ -105,7 +109,7 @@ def serve() -> None:
105109
@click.option(
106110
"--versions",
107111
required=True,
108-
help="Comma-separated Python versions (e.g., 3.10,3.11,3.12,3.13,3.14)",
112+
help=f"Comma-separated Python versions (e.g., {SUPPORTED_DOC_VERSIONS_CSV})",
109113
)
110114
@click.option(
111115
"--skip-content",
@@ -149,7 +153,8 @@ def build_index(versions: str, skip_content: bool) -> None:
149153
version_list = parse_expected_versions(versions)
150154
if not version_list:
151155
logger.error(
152-
"No valid versions specified. Example: --versions 3.10,3.11,3.12,3.13,3.14"
156+
"No valid versions specified. Example: --versions %s",
157+
SUPPORTED_DOC_VERSIONS_CSV,
153158
)
154159
raise SystemExit(1)
155160

@@ -390,8 +395,8 @@ def validate_corpus(db_path: str | None) -> None:
390395
if not target.exists():
391396
logger.error("Index not found at %s", target)
392397
logger.error(
393-
"Run: mcp-server-python-docs build-index --versions "
394-
"3.10,3.11,3.12,3.13,3.14"
398+
"Run: mcp-server-python-docs build-index --versions %s",
399+
SUPPORTED_DOC_VERSIONS_CSV,
395400
)
396401
raise SystemExit(1)
397402

@@ -517,8 +522,8 @@ def doctor() -> None:
517522
index_detail = str(index_path)
518523
if not index_exists:
519524
index_detail += (
520-
" (not found -- run: mcp-server-python-docs build-index --versions "
521-
"3.10,3.11,3.12,3.13,3.14)"
525+
f" (not found -- run: mcp-server-python-docs build-index --versions "
526+
f"{SUPPORTED_DOC_VERSIONS_CSV})"
522527
)
523528
else:
524529
size_mb = index_path.stat().st_size / (1024 * 1024)

src/mcp_server_python_docs/ingestion/sphinx_json.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,12 @@ def build_sphinx_json_command(
183183

184184

185185
def build_sphinx_bootstrap_requirements(sphinx_pin: str) -> list[str]:
186-
"""Return packages needed before installing CPython Doc requirements."""
186+
"""Return packages needed before installing CPython Doc requirements.
187+
188+
setuptools<70 keeps ``pkg_resources`` available, which old Sphinx
189+
releases (e.g. the 3.4.x line pinned for the Python 3.10 docs build)
190+
still import at startup.
191+
"""
187192
return [
188193
"setuptools<70",
189194
sphinx_pin,

src/mcp_server_python_docs/server.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,14 @@ async def app_lifespan(server: FastMCP) -> AsyncIterator[AppContext]:
6767

6868
# Fail fast on missing index (SRVR-10)
6969
if not index_path.exists():
70+
from mcp_server_python_docs.ingestion.cpython_versions import (
71+
SUPPORTED_DOC_VERSIONS_CSV,
72+
)
73+
7074
msg = (
7175
f"No index found at {index_path}\n"
72-
"Run: mcp-server-python-docs build-index --versions "
73-
"3.10,3.11,3.12,3.13,3.14"
76+
f"Run: mcp-server-python-docs build-index --versions "
77+
f"{SUPPORTED_DOC_VERSIONS_CSV}"
7478
)
7579
logger.error(msg)
7680
print(msg, file=sys.stderr)

tests/test_publish.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from mcp_server_python_docs.ingestion.cpython_versions import SUPPORTED_DOC_VERSIONS
1616
from mcp_server_python_docs.ingestion.publish import (
1717
SMOKE_SENTINEL_SYMBOL,
18+
_version_sort_key,
1819
atomic_swap,
1920
compute_sha256,
2021
generate_build_path,
@@ -127,10 +128,7 @@ def _create_populated_db(
127128
bootstrap_schema(conn)
128129

129130
doc_set_ids: dict[str, int] = {}
130-
default_version = max(
131-
versions,
132-
key=lambda v: tuple(int(p) for p in v.split(".")),
133-
)
131+
default_version = max(versions, key=_version_sort_key)
134132

135133
# Insert doc_sets
136134
for version in versions:

0 commit comments

Comments
 (0)