Skip to content

Commit 27132bd

Browse files
jambaykCopilot
andauthored
Fix docs build broken by sphinx-argparse commands domain (microsoft#2551)
## Describe your changes sphinx-argparse 0.6.0 registers a `commands` domain (`ArgParseDomain`) that does not implement the standard Sphinx `Domain.resolve_any_xref` API. MyST falls back to calling the domain's `resolve_xref` for every markdown cross-reference, and that method logs `Error, no command xref target from ...` for each target it doesn't own, including links that already resolve via doc/std resolution. Under `-W`, this flood of warnings fails the docs build. This adds a `resolve_any_xref` implementation to `ArgParseDomain` in `docs/source/conf.py`, supplying the API the extension omits so MyST resolves real command targets and skips the noisy fallback. This also removes the `myst.domains` legacy-domain warning, so the earlier `suppress_warnings` entry for it is dropped. No version pin is added to `docs/requirements.txt`. The rendered HTML is byte-identical to before; only the spurious warnings are gone. The `sphinx-build -W` build passes. ## Checklist before requesting a review - [ ] Add unit tests for this change. - [x] Make sure all tests can pass. - [x] Update documents if necessary. - [ ] Lint and apply fixes to your code by running `lintrunner -a` - [ ] Is this a user-facing change? If yes, give a description of this change to be included in the release notes. ## (Optional) Issue link --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 2bf92ed commit 27132bd

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

docs/source/conf.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,38 @@
6565

6666
suppress_warnings = ["myst.xref_missing"]
6767

68+
69+
def setup(app):
70+
# sphinx-argparse >= 0.6.0 registers a "commands" domain that does not implement
71+
# resolve_any_xref. MyST then falls back to calling its resolve_xref for every
72+
# markdown link, which logs "Error, no command xref target ..." for each unmatched
73+
# target. Providing resolve_any_xref lets MyST resolve real command targets and
74+
# skips the noisy fallback (and the "myst.domains" legacy-domain warning).
75+
try:
76+
from sphinxarg.ext import ArgParseDomain
77+
from sphinxarg.utils import target_to_anchor_id
78+
except ImportError:
79+
# Older sphinx-argparse (< 0.6.0) has no "commands" domain, nothing to patch.
80+
return
81+
82+
# Don't override a native implementation a future release might provide.
83+
if "resolve_any_xref" in ArgParseDomain.__dict__:
84+
return
85+
86+
from sphinx.util.nodes import make_refnode
87+
88+
def resolve_any_xref(self, env, fromdocname, builder, target, node, contnode):
89+
anchor_id = target_to_anchor_id(target)
90+
results = []
91+
for _cmd, _sig, _type, docname, anchor, _prio in self.get_objects():
92+
if anchor_id == anchor:
93+
refnode = make_refnode(builder, fromdocname, docname, anchor, contnode, anchor)
94+
results.append(("commands:command", refnode))
95+
return results
96+
97+
ArgParseDomain.resolve_any_xref = resolve_any_xref
98+
99+
68100
# -- Options for HTML output -------------------------------------------------
69101
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
70102
html_theme = "pydata_sphinx_theme"

0 commit comments

Comments
 (0)