-
Notifications
You must be signed in to change notification settings - Fork 10.4k
generate community extensions index from catalog #2564
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
Open
DyanGalih
wants to merge
10
commits into
github:main
Choose a base branch
from
DyanGalih:003-generate-community-docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+483
−139
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1e13fd6
feat: generate community extensions index from catalog
DyanGalih 16ce990
fix: resolve community docs rebase conflicts
DyanGalih efe252f
chore: drop unrelated review fixes
DyanGalih 4c9a37f
revert: use upstream main versions
DyanGalih d6ac193
Revert "revert: use upstream main versions"
DyanGalih 7806cc6
fix: align prerelease and docs rendering behavior
DyanGalih b3ed73b
fix: address PR 2564 feedback
DyanGalih d6b7c07
chore: add explanatory comments for prereleases=True
DyanGalih a8afb50
fix: embed community extensions table in docs and add tests
DyanGalih 744d004
fix: address final PR feedback on prerelease flags and tests
DyanGalih File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "body": "## What changed\n- Added a generator for `docs/community/extensions.md` backed by `extensions/catalog.community.json`.\n- Replaced the hand-maintained community extensions table with a generated index block.\n- Added a regression test that checks the committed page stays in sync with the generator.\n- Added `--markdown` flag to the `specify extension search` command to generate the docs.\n- **Compatibility Behavior Change:** Presets and extensions now evaluate `prereleases=True` if `current.is_devrelease` is True, allowing source/dev installations to satisfy version specifiers without accidentally accepting normal RC/beta builds.\n\n## Why\n- The community extensions page was a large manual table and was easy to drift from the catalog source of truth.\n- Moving the page to generated output keeps the community index aligned with the catalog as entries change.\n- This reduces maintainer overhead and makes the published list more trustworthy for contributors and users.\n\n## Impact\n- Contributors now update the catalog JSON instead of editing the rendered table by hand.\n- The community extensions page is more consistent and less likely to go stale.\n- CI and local tests can detect drift before it lands.\n\n## Validation\n- `specify extension search --markdown > docs/community/extensions.md` (to update the page)\n- `pytest tests/test_community_catalog_docs.py -q`\n" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| ## What changed | ||
| - Added a generator for `docs/community/extensions.md` backed by `extensions/catalog.community.json`. | ||
| - Replaced the hand-maintained community extensions table with a generated index block. | ||
| - Added a regression test that checks the committed page stays in sync with the generator. | ||
| - Added `--markdown` flag to the `specify extension search` command to generate the docs. | ||
| - **Compatibility Behavior Change:** Presets and extensions now evaluate `prereleases=True` if `current.is_devrelease` is True, allowing source/dev installations to satisfy version specifiers without accidentally accepting normal RC/beta builds. | ||
|
|
||
| ## Why | ||
| - The community extensions page was a large manual table and was easy to drift from the catalog source of truth. | ||
| - Moving the page to generated output keeps the community index aligned with the catalog as entries change. | ||
| - This reduces maintainer overhead and makes the published list more trustworthy for contributors and users. | ||
|
|
||
| ## Impact | ||
| - Contributors now update the catalog JSON instead of editing the rendered table by hand. | ||
| - The community extensions page is more consistent and less likely to go stale. | ||
| - CI and local tests can detect drift before it lands. | ||
|
|
||
| ## Validation | ||
| - `specify extension search --markdown > docs/community/extensions.md` (to update the page) | ||
| - `pytest tests/test_community_catalog_docs.py -q` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| """Helpers for rendering the community extensions reference table.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| import re | ||
| from pathlib import Path | ||
| from typing import Any | ||
|
|
||
|
|
||
| ROOT_DIR = Path(__file__).resolve().parents[2] | ||
| COMMUNITY_CATALOG_PATH = ROOT_DIR / "extensions" / "catalog.community.json" | ||
|
|
||
|
|
||
| def _render_cell(value: str) -> str: | ||
| return value.replace("\r\n", " ").replace("\r", " ").replace("\n", " ").replace("|", "\\|") | ||
|
|
||
|
|
||
| def _format_inline_code(value: str) -> str: | ||
| text = _render_cell(value) | ||
| runs = [len(match) for match in re.findall(r"`+", text)] | ||
| fence = "`" * (max(runs, default=0) + 1) | ||
| return f"{fence}{text}{fence}" | ||
|
|
||
|
|
||
| def _sanitize_link_target(value: str) -> str: | ||
| return value.replace("\r\n", "").replace("\r", "").replace("\n", "").replace("|", "%7C") | ||
|
|
||
|
|
||
| def _format_tags(tags: Any) -> str: | ||
| if not isinstance(tags, list) or not tags: | ||
| return "—" | ||
| # Clean first, then filter: a tag of " | " would pass str(tag).strip() but produce | ||
| # an empty code span after pipe removal, so filter on the cleaned value. | ||
| cleaned = [_format_inline_code(c) for tag in tags if (c := str(tag).replace("|", "").strip())] | ||
| return ", ".join(cleaned) if cleaned else "—" | ||
|
|
||
|
|
||
| def list_community_extensions(path: Path = COMMUNITY_CATALOG_PATH) -> list[dict[str, Any]]: | ||
| """Return community extensions sorted alphabetically by name then ID.""" | ||
| if not path.exists(): | ||
| raise FileNotFoundError( | ||
| f"Community catalog not found: {path}. " | ||
| "The --markdown flag requires a spec-kit source checkout." | ||
| ) | ||
| data = json.loads(path.read_text(encoding="utf-8")) | ||
| if not isinstance(data, dict): | ||
| raise ValueError(f"Expected {path} to contain a JSON object") | ||
| extensions = data.get("extensions") | ||
| if not isinstance(extensions, dict): | ||
| raise ValueError(f"Expected {path} to contain an 'extensions' object") | ||
|
|
||
| rows: list[dict[str, Any]] = [] | ||
| for ext_id, ext in extensions.items(): | ||
| if not isinstance(ext, dict): | ||
| raise ValueError(f"Community extension {ext_id!r} must be a mapping") | ||
| rows.append( | ||
| { | ||
| "name": str(ext.get("name") or ext_id), | ||
| "id": str(ext.get("id") or ext_id), | ||
| "description": str(ext.get("description") or ""), | ||
| "tags": ext.get("tags") or [], | ||
| "verified": "Yes" if bool(ext.get("verified")) else "No", | ||
| "repository": str(ext.get("repository") or ""), | ||
| } | ||
| ) | ||
|
|
||
| return sorted(rows, key=lambda row: (row["name"].casefold(), row["id"].casefold())) | ||
|
|
||
|
|
||
| def render_community_extensions_table(path: Path = COMMUNITY_CATALOG_PATH) -> str: | ||
| """Render the community extensions table from catalog.community.json.""" | ||
| rows = list_community_extensions(path=path) | ||
| if not rows: | ||
| raise ValueError("Community catalog has no extensions") | ||
|
|
||
| table_rows: list[list[str]] = [] | ||
| for row in rows: | ||
| # Escape raw field values *before* composing Markdown syntax so that | ||
| # a pipe inside a name or description doesn't break a link target. | ||
| safe_name = _render_cell(row["name"]) | ||
| safe_repository = _sanitize_link_target(row["repository"]) | ||
| link = ( | ||
| f"[{safe_name}]({safe_repository})" | ||
| if safe_repository | ||
| else safe_name | ||
| ) | ||
| table_rows.append( | ||
| [ | ||
| link, | ||
| _format_inline_code(row["id"]), | ||
| _render_cell(row["description"]), | ||
| _format_tags(row["tags"]), | ||
| row["verified"], | ||
| ] | ||
| ) | ||
|
|
||
| headers = ("Extension", "ID", "Description", "Tags", "Verified") | ||
|
|
||
| def render_row(values: list[str]) -> str: | ||
| # Values are already escaped; do not re-apply _render_cell here. | ||
| return "| " + " | ".join(values) + " |" | ||
|
|
||
| separator = "| " + " | ".join("---" for _ in headers) + " |" | ||
| lines = [render_row(list(headers)), separator] | ||
| lines.extend(render_row(row) for row in table_rows) | ||
| return "\n".join(lines) + "\n" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| from specify_cli.community_catalog_docs import list_community_extensions, render_community_extensions_table | ||
|
|
||
|
|
||
| def _write_catalog(tmp_path: Path, extensions: dict) -> Path: | ||
| p = tmp_path / "catalog.community.json" | ||
| p.write_text(json.dumps({"extensions": extensions}), encoding="utf-8") | ||
| return p | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Happy-path tests against the real catalog | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| def test_community_extensions_table_renders() -> None: | ||
| table = render_community_extensions_table() | ||
| assert "| Extension" in table | ||
| assert "| ID" in table | ||
| assert "| Description" in table | ||
| assert "| Tags" in table | ||
| assert "| Verified" in table | ||
|
|
||
|
|
||
| def test_community_extensions_are_sorted_by_name() -> None: | ||
| rows = list_community_extensions() | ||
| names = [row["name"] for row in rows] | ||
| assert names == sorted(names, key=str.casefold) | ||
|
|
||
|
DyanGalih marked this conversation as resolved.
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Edge-case tests using synthetic catalogs | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| def test_missing_catalog_file(tmp_path: Path) -> None: | ||
| with pytest.raises(FileNotFoundError, match="spec-kit source checkout"): | ||
| list_community_extensions(path=tmp_path / "missing.json") | ||
|
|
||
|
|
||
| def test_malformed_json(tmp_path: Path) -> None: | ||
| bad = tmp_path / "bad.json" | ||
| bad.write_text("not valid json", encoding="utf-8") | ||
| with pytest.raises(json.JSONDecodeError): | ||
| list_community_extensions(path=bad) | ||
|
|
||
|
|
||
| def test_non_dict_root(tmp_path: Path) -> None: | ||
| f = tmp_path / "catalog.json" | ||
| f.write_text(json.dumps([{"id": "foo"}]), encoding="utf-8") | ||
| with pytest.raises(ValueError, match="JSON object"): | ||
| list_community_extensions(path=f) | ||
|
|
||
|
|
||
| def test_missing_extensions_key(tmp_path: Path) -> None: | ||
| f = tmp_path / "catalog.json" | ||
| f.write_text(json.dumps({"other": {}}), encoding="utf-8") | ||
| with pytest.raises(ValueError, match="'extensions' object"): | ||
| list_community_extensions(path=f) | ||
|
|
||
|
|
||
| def test_non_dict_extension_value(tmp_path: Path) -> None: | ||
| f = _write_catalog(tmp_path, {"foo": "not-a-dict"}) | ||
| with pytest.raises(ValueError, match="must be a mapping"): | ||
| list_community_extensions(path=f) | ||
|
|
||
|
|
||
| def test_empty_catalog_raises(tmp_path: Path) -> None: | ||
| f = _write_catalog(tmp_path, {}) | ||
| with pytest.raises(ValueError, match="no extensions"): | ||
| render_community_extensions_table(path=f) | ||
|
|
||
|
|
||
| def test_extension_without_repository(tmp_path: Path) -> None: | ||
| f = _write_catalog(tmp_path, { | ||
| "foo": {"name": "Foo", "id": "foo", "description": "A foo tool", "tags": [], "verified": False, "repository": ""}, | ||
| }) | ||
| table = render_community_extensions_table(path=f) | ||
| assert "Foo" in table | ||
| assert "[Foo](" not in table # plain name, no link | ||
|
|
||
|
|
||
| def test_backticks_in_ids_and_tags_render_safely(tmp_path: Path) -> None: | ||
| f = _write_catalog(tmp_path, { | ||
| "foo": { | ||
| "name": "Foo", | ||
| "id": "foo`bar", | ||
| "description": "", | ||
| "tags": ["a`b"], | ||
| "verified": False, | ||
| "repository": "", | ||
| }, | ||
| }) | ||
| table = render_community_extensions_table(path=f) | ||
| assert "``foo`bar``" in table | ||
| assert "``a`b``" in table | ||
| foo_row = next(line for line in table.split("\n") if line.startswith("| ") and "Foo" in line) | ||
| assert foo_row.count("|") == 6 | ||
|
|
||
|
|
||
| def test_repository_values_are_sanitized_for_table_cells(tmp_path: Path) -> None: | ||
| f = _write_catalog(tmp_path, { | ||
| "foo": { | ||
| "name": "Foo", | ||
| "id": "foo", | ||
| "description": "", | ||
| "tags": [], | ||
| "verified": False, | ||
| "repository": "https://example.com/a|b\nnext", | ||
| }, | ||
| }) | ||
| table = render_community_extensions_table(path=f) | ||
| assert "https://example.com/a%7Cbnext" in table | ||
| foo_row = next(line for line in table.split("\n") if line.startswith("| ") and "Foo" in line) | ||
| assert foo_row.count("|") == 6 | ||
|
|
||
|
|
||
| def test_tags_containing_pipe_do_not_break_table(tmp_path: Path) -> None: | ||
| f = _write_catalog(tmp_path, { | ||
| # No "id" field — exercises ext_id fallback; tag has pipe — exercises stripping | ||
| "foo": {"name": "Foo", "description": "", "tags": ["foo|bar"], "verified": False, "repository": ""}, | ||
| }) | ||
| table = render_community_extensions_table(path=f) | ||
| # pipe stripped from tag value | ||
| assert "`foobar`" in table | ||
| # id falls back to the dict key when "id" field is absent | ||
| assert "`foo`" in table | ||
| # row is well-formed: 5-column table has exactly 6 pipe separators per row | ||
| foo_row = next(line for line in table.split("\n") if line.startswith("| ") and "Foo" in line) | ||
| assert foo_row.count("|") == 6 | ||
|
|
||
|
|
||
| def test_non_list_tags_renders_em_dash(tmp_path: Path) -> None: | ||
| f = _write_catalog(tmp_path, { | ||
| "foo": {"name": "Foo", "description": "", "tags": "not-a-list", "verified": False, "repository": ""}, | ||
| }) | ||
| table = render_community_extensions_table(path=f) | ||
| assert "—" in table | ||
|
|
||
| def test_community_extensions_markdown_rejects_filters() -> None: | ||
| from typer.testing import CliRunner | ||
| from specify_cli import app | ||
| runner = CliRunner() | ||
| result = runner.invoke(app, ["extension", "search", "--markdown", "--tag", "foo"]) | ||
| assert result.exit_code == 1 | ||
| assert "The --markdown flag outputs the full community catalog" in result.stdout | ||
|
|
||
| def test_docs_extensions_md_is_up_to_date() -> None: | ||
| from pathlib import Path | ||
| from specify_cli.community_catalog_docs import render_community_extensions_table | ||
|
|
||
| root_dir = Path(__file__).resolve().parents[1] | ||
| docs_path = root_dir / "docs" / "community" / "extensions.md" | ||
|
|
||
| assert docs_path.exists(), "docs/community/extensions.md not found" | ||
| docs_content = docs_path.read_text(encoding="utf-8") | ||
|
|
||
| generated_table = render_community_extensions_table() | ||
|
|
||
| # Extract the block between markers and compare it exactly | ||
| start_marker = "<!-- BEGIN GENERATED TABLE -->\n" | ||
| end_marker = "<!-- END GENERATED TABLE -->" | ||
|
|
||
| start_idx = docs_content.find(start_marker) | ||
| end_idx = docs_content.find(end_marker) | ||
|
|
||
| assert start_idx != -1, f"Missing '{start_marker.strip()}' in docs/community/extensions.md" | ||
| assert end_idx != -1, f"Missing '{end_marker}' in docs/community/extensions.md" | ||
|
|
||
| actual_table = docs_content[start_idx + len(start_marker):end_idx] | ||
|
|
||
| assert actual_table.strip() == generated_table.strip(), ( | ||
| "docs/community/extensions.md is out of sync with catalog.community.json. " | ||
| "Please run `specify extension search --markdown` and update the docs file." | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.