Skip to content
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

Conversation

qryxip
Copy link
Member

@qryxip qryxip commented Jan 28, 2025

内容

関連 Issue

Resolves: #951

その他

数時間調べたけど、これ以外に方法は無さそう。

Copy link
Member

@Hiroshiba Hiroshiba left a 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書くかだけでも、という気持ち!

@qryxip
Copy link
Member Author

qryxip commented Jan 28, 2025

ちょっとどっちもキツそうではありますね。一番ありうるシナリオとしてはSphinx & Sphinx AutoAPIがちゃんと対応してワークアラウンドが要らなくなる、という感じな気が…

@qryxip
Copy link
Member Author

qryxip commented Jan 28, 2025

よくわかってないのですが、これはautoapi.extensionではなくautodocでも同じように問題になるんですかね・・・?

ですね。型エイリアス系については、まあよくわからなかったのですが、なんかどうもSphinx本体とSphinx AutoAPIで別々の問題を抱えてるっぽく…

@qryxip qryxip merged commit 5de33e2 into VOICEVOX:main Jan 28, 2025
29 checks passed
@qryxip qryxip deleted the docs-workaround-for-sphinx-links-to-newtypes-and-typealiases branch January 28, 2025 03:50
@Hiroshiba
Copy link
Member

Hiroshiba commented Jan 28, 2025

なるほどです・・・まあそうですよねぇ。

とりあえずやるなら、TARGETSそれぞれに対して1回以上Noneではないxrefが得られていればOK、そうじゃなければraise、とかかなぁ。

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)

@Hiroshiba
Copy link
Member

僕達はドキュメントをめったに見ないので、こういうエラーハンドリングをしっかりやっていくのがドキュメントの品質に繋がる・・・のかもなぁとそこそこ強めに思ってます!

qryxip added a commit to qryxip/voicevox_core that referenced this pull request Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sphinx AutoAPIがNewTypeTypeAliasへのリンクを張ってくれない
2 participants