-
Notifications
You must be signed in to change notification settings - Fork 122
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
docs: [Python] 型エイリアス系へのリンクについてワークアラウンド #952
docs: [Python] 型エイリアス系へのリンクについてワークアラウンド #952
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!!
よくわかってないのですが、これはautoapi.extension
ではなくautodoc
でも同じように問題になるんですかね・・・?
将来sphinxのバージョンを上げたときなどに、いつの間にか動かなくなってるだろうなーと感じました。
ビルド後のドキュメントに対してリンクが貼られてるかのテストを書くか、conf.pyで予想外の動きをしたときにraiseするかした方が良いかも・・・?
まあ前者はビルド後のテストをどう書くべきなのか、後者は予想外をどう予想すれば良いのか課題はありますが。。。
とりあえずissue作るかTODO書くかだけでも、という気持ち!
ちょっとどっちもキツそうではありますね。一番ありうるシナリオとしてはSphinx & Sphinx AutoAPIがちゃんと対応してワークアラウンドが要らなくなる、という感じな気が… |
ですね。型エイリアス系については、まあよくわからなかったのですが、なんかどうもSphinx本体とSphinx AutoAPIで別々の問題を抱えてるっぽく… |
なるほどです・・・まあそうですよねぇ。 とりあえずやるなら、 def _on_missing_reference(
app: Sphinx, env: BuildEnvironment, node: pending_xref, contnode: TextElement
) -> reference | None:
"""
`NewType や TypeAlias について class
宛てにリンクしようとしてmissingになったものを、 `data 宛てに修正する。
"""
# 参考: https://github.com/sphinx-doc/sphinx/issues/10785#issue-1348601826
TARGETS = {
"CharacterVersion",
"StyleId",
"VoiceModelId",
}
resolved_targets = {} # 追加
if (
node["refdomain"] == "py"
and node["reftype"] == "class"
and node["reftarget"].split(".")[-1] in TARGETS
):
xref = app.env.get_domain("py").resolve_xref(
env, node["refdoc"], app.builder, "data", node["reftarget"], node, contnode
)
xref = typing.cast(reference | None, xref) # ?
if not xref:
raise new Exception("unresolved link to %s", node["reftarget"]) # 変更
resolved_targets.add(どうにかしてtargetを得る)
return xref
assert len(resolved_targets) == len(TARGETS) |
僕達はドキュメントをめったに見ないので、こういうエラーハンドリングをしっかりやっていくのがドキュメントの品質に繋がる・・・のかもなぁとそこそこ強めに思ってます! |
内容
関連 Issue
Resolves: #951
その他
数時間調べたけど、これ以外に方法は無さそう。