Skip to content

armgit / dspy

Public Imported from GitHub
0

DSPy: The framework for programming—not prompting—language models

Python

docs: pin historical release badges (#10413)

Isaac Miller1bfab9511499
diff --git a/docs/scripts/build_docs.py b/docs/scripts/build_docs.py
index a63610c10..d09fefe0d 100644
--- a/docs/scripts/build_docs.py
+++ b/docs/scripts/build_docs.py
@@ -23,6 +23,9 @@ ROOT_URL_ATTRIBUTE = re.compile(
re.IGNORECASE,
)
VERSIONED_PATH = re.compile(r"^/(?:current|\d+\.\d+(?:\.\d+(?:(?:a|b|rc)\d+)?)?)(?:/|$)")
+RELEASE_BADGE_VERSION = re.compile(
+ r'(?s)(<div class=(?:"hp-hero-badge"|hp-hero-badge)>.*?\bDSPy )(\S+)(\s+&mdash;)'
+)
SHARED_HEADER_STYLES = Path(__file__).parent.parent / "versioning" / "header.css"
@@ -116,6 +119,19 @@ def scope_root_relative_urls(site: Path, identifier: str) -> None:
page.write_text(scoped)
+def set_release_badge_version(site: Path, version: str) -> None:
+ """Keep a historical home page from advertising the latest live release."""
+ home = site / "index.html"
+ html = home.read_text()
+ updated, count = RELEASE_BADGE_VERSION.subn(
+ lambda match: f"{match.group(1)}{version}{match.group(3)}",
+ html,
+ count=1,
+ )
+ if count:
+ home.write_text(updated)
+
+
def installed_packages() -> dict[str, str]:
return dict(
sorted(
@@ -204,6 +220,7 @@ def build(
if version:
if artifact is None or package_source is None:
raise ValueError("release builds require an artifact and package source")
+ set_release_badge_version(output, version)
scope_root_relative_urls(output, identifier)
if version:
validate_release_site(output, config, version)
diff --git a/tests/docs/test_versioned_docs.py b/tests/docs/test_versioned_docs.py
index 2109a8efb..b23ab1d77 100644
--- a/tests/docs/test_versioned_docs.py
+++ b/tests/docs/test_versioned_docs.py
@@ -5,7 +5,13 @@ import subprocess
import pytest
-from docs.scripts.build_docs import patched_config, release_version, remove_source_maps, scope_root_relative_urls
+from docs.scripts.build_docs import (
+ patched_config,
+ release_version,
+ remove_source_maps,
+ scope_root_relative_urls,
+ set_release_badge_version,
+)
from docs.scripts.publish_versioned_docs import publish_site, version_tuple
requires_mike = pytest.mark.skipif(importlib.util.find_spec("mike") is None, reason="Mike is a docs-only dependency")
@@ -107,6 +113,22 @@ def test_root_relative_links_stay_inside_the_selected_version(tmp_path):
assert 'href="//example.com/path"' in html
+def test_release_badge_uses_snapshot_version_without_changing_other_content(tmp_path):
+ site = tmp_path / "site"
+ site.mkdir()
+ home = site / "index.html"
+ home.write_text(
+ '<div class="hp-hero-badge">\n<span></span>\nDSPy 3.4.0b1 &mdash; Historical blurb\n</div>'
+ '<p>Documentation example for DSPy 3.4.0b1</p>'
+ )
+
+ set_release_badge_version(site, "3.3.1")
+
+ html = home.read_text()
+ assert "DSPy 3.3.1 &mdash; Historical blurb" in html
+ assert "Documentation example for DSPy 3.4.0b1" in html
+
+
@requires_mike
def test_mike_preserves_patches_and_moves_minor_redirect(tmp_path):
repository = make_repository(tmp_path)