Repository navigation
Add Markdown pages and llms.txt generation for Common AI provider docs - #74536
SameerMesiah97 wants to merge 6 commits into
Conversation
7ddda23 to
a7c3e05
Compare
dabla
left a comment
There was a problem hiding this comment.
Addressed
- First round, no earlier reviews or threads.
- Of the issue's part 1 pre-merge list, three items are done and work on a real build:
- Markdown stubs for the 7 common.ai redirects. Each points at the same target as its HTML redirect, plus
.md. - The missing-Markdown check. Only
genindex,searchandpy-modindexlack a.html.md. - The unit tests: 68 tests, all passing.
- Markdown stubs for the 7 common.ai redirects. Each points at the same target as its HTML redirect, plus
Open
-
[6] uv.lock churn: +299/−267 where +33/−1 is enough (warning).
-
[1], [2], [4] The reasons the PoC gave for the ref choice, the doctree cache,
|version|and the redirect prefixes were dropped (nits). -
[3] When the whole Markdown build fails, the per-page list hides the cause (nit).
-
[5] Loose same-page link assertion (nit).
-
The issue's "cut the extension down" item is still open, and the PR body says so. It would help to open the upstream issues or PRs now and link them from the PR:
- sphinx-markdown-builder: tables, admonitions, same-page links;
- sphinx-llm: the sequential build sharing the HTML doctree cache.
sphinx-llm 1.1 already has
llms_txt_exclude,llms_txt_full_buildand meta-description summaries. Check whether any of those can replace code in_write_llms_txtbefore Kaxil asks. -
The branch now conflicts with
main(GitHub reportsCONFLICTING; the head is stilla7c3e05a04, last updated 2026-10-10). A rebase needsuv.lockregenerated anyway, so [6] can be fixed at the same time. -
Commit
7d24548da3keeps Kaxil as its author, which is good. Airflow squash-merges, though, so add aCo-authored-by: Kaxil Naik <kaxilnaik@gmail.com>line to the PR description; otherwise the credit is lost in the merged commit.
This was a full local review of head a7c3e05a04. I compared it against the PoC commit ddb2005f to separate the new work from the base.
- The Airflow audits ran: parity with the PoC and with the HTML redirects, build-finished ordering against sphinx-llm 1.1.0, the lock file, and test/claim wording. The Task SDK audits don't apply.
- The new tests pass:
test_airflow_llms_txt.py,test_redirects.pyandtest_example_source.py. build-docs --docs-only --one-pass-onlyfor common.ai succeeds in 94 s with the coverage check active. The output has:- 234
.html.mdpages; llms.txt(24 KB, 12 sections from the toctree captions) andllms-full.txt(833 KB);- no curly quotes in any Markdown output;
rel="alternate"links in the HTML.
- 234
- Not covered: spelling, CI (only the WIP check ran on the draft), and parts 2 and 3 of the issue.
a7c3e05 to
1c92de5
Compare
|
Can somone trigger CI? |
Done |
1c92de5 to
275eb27
Compare
275eb27 to
1c63a63
Compare
|
I was hoping you could review this. |
|
Related to the issue that was opened NVIDIA/sphinx-llm#203 it looks like there are some problems with cache reuse between html and markdown docs builds in this project. Specifically, it seems like there's a custom extension that makes output-specific transformations during the read of the sources. I'm happy to explore disabling cache reuse in I had Codex put together this dish, which should avoid these caching problems. Let me know what you think. diff --git a/devel-common/src/sphinx_exts/airflow_llms_txt.py b/devel-common/src/sphinx_exts/airflow_llms_txt.py
index 050bc335d6..9b4d1f18db 100644
--- a/devel-common/src/sphinx_exts/airflow_llms_txt.py
+++ b/devel-common/src/sphinx_exts/airflow_llms_txt.py
@@ -43,6 +43,7 @@ from typing import TYPE_CHECKING, Any
from urllib.parse import urljoin
from docutils import nodes
+from exampleinclude import ExampleHeader
from sphinx import addnodes
from sphinx.util import logging
from sphinx.util.matching import Matcher
@@ -51,7 +52,6 @@ from sphinx_markdown_builder.contexts import IndentContext, SubContext, SubConte
if TYPE_CHECKING:
from sphinx.application import Sphinx
- from sphinx.config import Config
from sphinx.environment import BuildEnvironment
logger = logging.getLogger(__name__)
@@ -219,40 +219,32 @@ def _xref_title(xref: addnodes.pending_xref, env: BuildEnvironment) -> str | Non
return None
-def _separate_markdown_doctrees(app: Sphinx, config: Config) -> None:
- """
- Give the Markdown build a doctree cache of its own.
-
- Without parallel mode sphinx-llm points the Markdown build at the HTML build's doctree cache.
- The Markdown build would then reuse doctrees read for HTML (curly quotes, none of this
- extension's ``doctree-read`` changes) or, once re-read, overwrite them. Its own directory sits
- inside sphinx-llm's temporary output, which is deleted after the Markdown files are copied.
- Sphinx creates the environment after ``config-inited``, so the change takes effect.
- """
- if app.tags.has("sphinx_llm_markdown"):
- app.doctreedir = Path(app.outdir) / ".doctrees"
-
-
def _is_markdown_build(app: Sphinx) -> bool:
return app.builder is not None and app.builder.name == MARKDOWN_BUILDER
-def _link_example_sources(app: Sphinx, doctree: nodes.document) -> None:
+def _remember_example_sources(app: Sphinx, doctree: nodes.document) -> None:
+ # exampleinclude replaces ExampleHeader during doctree-read. Keep its filename on
+ # the wrapper so either writer can render the same cached tree appropriately.
+ for header in doctree.findall(ExampleHeader):
+ header.parent["example_source_filename"] = header["filename"]
+
+
+def _link_example_sources(app: Sphinx, doctree: nodes.document, docname: str) -> None:
"""
Replace each ``exampleinclude`` header with a link to the whole example file.
- Runs before ``exampleinclude``'s own ``doctree-read`` handler, which would otherwise turn the
- header into a bare module path plus a "View Source" button that has no Markdown equivalent.
+ Run during output processing so Markdown can reuse the HTML build's cached doctrees
+ without changing their headers or running the source parser again.
"""
if not _is_markdown_build(app):
return
- # Imported by bare name, as conf.py loads it: another import path gives a different class.
- from exampleinclude import ExampleHeader
-
repo_root = Path(app.config.llms_txt_repo_root).resolve()
source_url = app.config.llms_txt_source_url.rstrip("/")
- for header in list(doctree.findall(ExampleHeader)):
- path = Path(header["filename"]).resolve()
+ for header in list(doctree.findall(nodes.paragraph)):
+ if "example-header" not in header["classes"] or "example_source_filename" not in header.parent:
+ continue
+ path = Path(header.parent["example_source_filename"]).resolve()
if not source_url or not path.is_relative_to(repo_root):
header.parent.remove(header)
continue
@@ -477,8 +469,8 @@ def setup(app: Sphinx) -> dict[str, Any]:
app.add_config_value("llms_txt_root_description", "", "env")
app.add_config_value("llms_txt_optional_docs", [], "env")
app.add_config_value("llms_txt_skip_docs", [], "env")
- app.connect("config-inited", _separate_markdown_doctrees)
- app.connect("doctree-read", _link_example_sources, priority=400)
+ app.connect("doctree-read", _remember_example_sources, priority=400)
+ app.connect("doctree-resolved", _link_example_sources)
app.connect("doctree-resolved", _clean_markdown_doctree)
app.connect("build-finished", _write_llms_txt, priority=102)
- return {"parallel_read_safe": True, "parallel_write_safe": True}
+ return {"env_version": 1, "parallel_read_safe": True, "parallel_write_safe": True} |
1c63a63 to
0c34ea8
Compare
|
Fork CI: green. CI for the latest commit passed in your fork. The pull request is ready for maintainer review. Pull requests from contributors run their CI in the contributor's own fork. GitHub Actions is free and has no minute limit on public forks, while the CI capacity of the Apache Software Foundation is shared by every ASF project and is finite. Fork CI tested this branch merged with Latest run: https://github.com/SameerMesiah97/airflow-oss-sm97/actions/runs/46722417148 How this works: CI in your fork. This comment was posted automatically by the fork CI monitor from templates drafted with an AI-assisted tool, so it may contain mistakes. An Apache Airflow maintainer, a real person, will review the pull request once its fork CI is green. Why the first pass is automated. |
I have implemented this fix and it appeared to have worked based on my manual tests. I have covered this in my latest commit with the associated test updates. |
|
Quickest fix: git fetch upstream main && git rebase upstream/main
rm uv.lock && uv lock
git add uv.lock && git rebase --continue
git push --force-with-leaseAutomated nudge — ignore if you're not ready to rebase. This comment is updated in place on future |
0c34ea8 to
7e03c3e
Compare
7e03c3e to
87c4d1f
Compare
dabla
left a comment
There was a problem hiding this comment.
Addressed
example_source_refexplains its ref choice again: release tag vsmain, and the local-only HEAD after a cherry-pick. Thread onexample_source.pyL26, fixed in 8c19ab8.- The doctree-cache docstring point no longer applies, because
_separate_markdown_doctreesis gone (87c4d1f, the approach suggested in the sphinx-llm#203 discussion). The|version|reason is back above the replacement in_clean_markdown_doctree(8c19ab8). - A failed Markdown build now raises one short error naming
<root_doc>.html.md, before the per-page coverage list. Tested forindexand a nested root, plus the partial-coverage case (8c19ab8). - The
redirects.pycomment explains the..depth again, including the core-API-to-provider case (8c19ab8). - The same-page link test asserts the exact
[Setup](#setup-section)(8c19ab8). uv.lockis +34/−0: the two new packages plus the devel-commondocsentries, with no unrelated churn (8c19ab8).
All six threads were marked resolved without a reply. I checked each one against the code at this head.
Open
- [1] The Markdown build repeats the spell check on every page, because sphinx-llm forwards
-D airflow_spelling_output. The HTML run overwrites the result only because it writes later (nit). - [2] The reason for the bare-name, function-level
exampleincludeimport was dropped (nit). - [3] Curly quotes are back in the
.html.mdpages, because the Markdown build reuses the HTML doctrees (warning). - The PR body is out of date after 87c4d1f. It still lists "Markdown builds use a separate doctree cache" under Tests and says the "doctree-cache workaround" remains pending upstream. That test was removed, and the workaround with it.
- From the previous round, not yet done: a
Co-authored-by: Kaxil Naikline in the PR description, so the credit survives the squash merge. Commit 140b80b keeps him as author, but the squash drops that. The sphinx-markdown-builder issues for tables, admonitions and same-page links are still not linked from the PR either.
This is the third pass at head 87c4d1f683. The PR has had no new commits or comments since 2026-11-07, and the earlier passes of this round were never posted. The third pass checked:
- the upstream state: sphinx-llm#203 was closed with #214, which is not yet released; added to [3];
main: it is 266 commits ahead and still merges cleanly. None of the 15 commits onmainthat touch the docs plumbing or the common.ai docs changes the findings;- CI: green, 15 passed and 1 skipped.
The second pass traced the Markdown subprocess against the plumbing on main that the branch now sits on (the spell check moved into the HTML build), which found [1]. The review ran in a detached worktree. I compared it with the previously reviewed head a7c3e05a04 for the fix round, and read the whole change again. Audits:
- parity with the PoC on the Markdown output (this found [3]);
- what the Markdown subprocess inherits from the HTML build (
-Doverrides, doctree directory, hook priorities atbuild-finished); - doctree-read/doctree-resolved ordering against
exampleinclude(priority 400 before 500; the header is replaced after viewcode's post-transform); - test wording;
- the lock file.
The Task SDK audits do not apply. test_airflow_llms_txt.py, test_redirects.py and test_example_source.py pass (72 tests). I did not run the full common.ai docs build: it needs the whole Airflow dev environment, every provider included, which is too heavy for this machine. Instead, [3] was reproduced with the extension itself in a Sphinx 9.1.1 / sphinx-llm 1.1.0 build. [1] was reproduced with a probe extension, because the enchant C library is not installed here. The test mocks are autospecced, and the only function-level imports are the exampleinclude ones in [2].
87c4d1f to
e56bea6
Compare
e56bea6 to
cb46eb7
Compare
Coding agents read docs best as Markdown with an llms.txt index, the way Pydantic AI publishes https://pydantic.dev/docs/ai/llms.txt. This adds that to the common.ai provider docs build: - sphinx-llm writes page.html.md next to every page.html and links it from the HTML head with rel="alternate" type="text/markdown". - A new airflow_llms_txt extension fixes the Markdown for Airflow docs (mermaid, code captions, admonitions, compact tables, same-page links, license headers, |version| links), links each exampleinclude excerpt to the full example file on GitHub, and writes llms.txt grouped by the docs navigation with absolute URLs and per-page descriptions, plus llms-full.txt with the same pages in one file. Enabled for common.ai only via PROVIDER_PACKAGES_WITH_LLMS_TXT.
Generate Markdown redirect stubs and fail builds with missing Markdown copies. Add tests for the extension, redirect resolution and example source references. Fix navigation caption rendering in Markdown.
Restore explanations for source refs, doctree isolation and redirects. Add a concise missing-root Markdown error and test partial coverage. Tighten the same-page link assertion and regenerate uv.lock to reduce churn.
Preserve example filenames before exampleinclude replaces its headers, then generate Markdown source links during doctree-resolved. Remove the separate Markdown doctree cache workaround and version the cached environment data. Update unit tests and add Sphinx build coverage for Markdown example links and preserved HTML headers.
Convert smart punctuation in Markdown prose while preserving literals and code blocks. Add build coverage for typography with shared doctrees. Restrict spell checking to HTML builds and document why ExampleHeader must be imported by its bare module name.
cb46eb7 to
09ecf22
Compare
dabla
left a comment
There was a problem hiding this comment.
Addressed
- The Markdown build no longer spell-checks every page a second time:
_startinairflow_spellingnow only runs for thehtmlbuilder (09ecf22, thread onprovider_conf.py). The PR body says so too. - The comment explaining the function-level, bare-name
exampleincludeimport is back (09ecf22, thread onairflow_llms_txt.pyL235). - The Markdown pages are ASCII again.
_clean_markdown_doctreeruns_TYPOGRAPHYover the text nodes that are not inside aliteral,mathorFixedTextElement. That keeps the shared doctree cache and leaves code alone (09ecf22, thread onairflow_llms_txt.pyL271).test_rendered_typographycovers three cases: prose, an inline literal and a code block. Therendered_docsfixture now sets the productionsmartquotes_excludes. - The PR body no longer describes the removed doctree-cache workaround or its test.
Open
- [2] Conflict markers and both versions of a paragraph in
durable_execution.rst(blocker). The meta description there is also out of date. - [1] No test for the new builder check in
airflow_spelling._start(nit). - Still open from earlier rounds: the PR description has no
Co-authored-by: Kaxil Naikline, so the credit to the PoC's author is lost in the squash merge.
This is a local review of head 09ecf22dc6, the rebase onto 94a793c2a6 plus the new typography commit. I compared each PR file with the previous head 87c4d1f683, so the rebase's own changes were checked too, which is where [2] came from. For each fix, I re-ran the scenario from its thread:
- the typography test, plus the earlier probe setup, now in the fixture;
- the spelling gate, read against
docs_builder.pyand sphinx-llm's-Dforwarding.
I checked the three fixes against each other: the normalization runs after _link_example_sources, whose path link is a literal, so it is left alone. test_airflow_llms_txt.py, test_redirects.py and test_example_source.py pass (73 tests). test_airflow_spelling.py needs the enchant C library, which is not installed here. Fork CI reports green for this head, which shows the docs build does not catch [2].
Verify that Markdown builds do not initialize a spelling run even when a spelling output path is configured. Resolve leftover merge conflicts in the durable execution documentation and align its content with the current behaviour.
Description
Add automatic generation of Markdown pages,
llms.txtandllms-full.txtfor the Common AI provider documentation.This builds on the proof of concept using
sphinx-llmto generate a.html.mdcopy alongside each documentation page. The Airflow extension groups the index by documentation navigation, uses versioned URLs and links example excerpts to their complete source files on GitHub.Markdown copies are also generated for redirect stubs. The build fails if a published HTML page has no Markdown copy, excluding
_modules/,genindex,searchandpy-modindex.The Markdown build runs after HTML and reuses its cached doctrees. Markdown-specific changes, including example source links and prose typography normalization, run during output processing. Spell checking runs only during the HTML build.
Rationale
Coding agents consume Airflow documentation to write DAGs, but fetching HTML can lose code samples and other useful context during extraction or summarisation.
Markdown copies provide the documentation content and code samples in a simpler format.
llms.txthelps agents discover relevant pages, whilellms-full.txtprovides the indexed content in one file.Redirect coverage ensures that older documentation URLs also have a Markdown response when Markdown serving is enabled.
Tests
Added tests verifying that:
Manually built the Common AI provider documentation and inspected generated Markdown pages, HTML example headers and redirect pages.
Notes
apache-airflow-providers-common-aionly.-The separate doctree-cache workaround has been removed. Rendering workarounds remain for compact tables, admonitions and same-page references; these have also been investigated or addressed upstream in
sphinx-markdown-builder.Documentation
The documentation build generates
.html.mdpages,llms.txtandllms-full.txt, with alternate Markdown links in the HTML pages.Backwards Compatibility
Existing HTML documentation remains available. Markdown generation is opt-in, so other provider packages retain their existing build behaviour.
Acknowledgements
This change builds on the proof of concept by @kaxil, which introduced Markdown pages,
llms.txtandllms-full.txtgeneration for the Common AI provider documentation.Related: #74376.
Was generative AI tooling used to co-author this PR?
Generated-by: [GPT 6.1] following the guidelines