🌀

Houdini houモジュールの入力補完の為のStubファイル生成メモ

2024/08/06に公開

下記の記事の内容を追えば叶う。
https://pakreht.com/houdini/configure-vscode-for-python/

情報を足しつつメモ
VSCodeでProfileを作成してExtensionとsetting.jsonが他の設定と競合しないようにしておく。
VSCodeなどのIDEから参照すべきパスを出力させるPythonコードをHoudiniで実行。
出力された文字列をsetting.jsonにコピペ。
houモジュールのスタブファイルを生成して型情報を参照できるようにする。
スタブ生成はmypyのstubgenでやろうとしたが失敗した。もうちょっとちゃんと理解できればmypyとかで生成も出来るんだとは思うがよく分からず。
冒頭の記事で紹介されているHoudini Stub Generatorを使用してスタブを生成した。
スタブファイルがある階層の親フォルダの親フォルダをsetting.json"python.analysis.stubPath"に記述。(フォルダをどこに置くかは任意。)
macで生成したstubファイルはどの環境でも使いまわせるので、OSが異なっていても同じものを共有して環境ごとにsetting.jsonを設定すれば良い。

スタブファイルはこんな感じ

面倒なのでGithubにおきつつ必要なバージョンのスタブファイルをフォルダ毎に分けて置くことにした。めでたし。よしなに使って下さい。
https://github.com/HarukaKajita/Houdini_Stubs

VSCodeではProfileの作成は画面左下の歯車アイコンから作成するが、Cursorを使用したい場合はCtrl+Shift+PでコマンドパレットからCreate Profileを実行すればVSCodeと同様にProfileを作れる。

参考として、mac環境でのsetting.jsonがこうなった。(extraPathsに不要っぽいパスが一つ混じってたのでそれは消してある。)

{
    "python.defaultInterpreterPath": "/Applications/Houdini/Houdini20.5.278/Frameworks/Python.framework/Versions/3.11/python.exe",
    "python.analysis.extraPaths": [
        "/Applications/Houdini/Houdini20.5.278/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages-forced",
        "/Applications/Houdini/Houdini20.5.278/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages-forced",
        "/Applications/Houdini/Houdini20.5.278/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages-ui-forced",
        "/Applications/Houdini/Houdini20.5.278/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages-forced",
        "/Applications/Houdini/Houdini20.5.278/Frameworks/Python.framework/Versions/3.11/lib/python311.zip",
        "/Applications/Houdini/Houdini20.5.278/Frameworks/Python.framework/Versions/3.11/lib/python3.11",
        "/Applications/Houdini/Houdini20.5.278/Frameworks/Python.framework/Versions/3.11/lib/python3.11/lib-dynload",
        "/Applications/Houdini/Houdini20.5.278/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages",
        "/Applications/Houdini/Houdini20.5.278/Frameworks/Houdini.framework/Versions/20.5/Resources/packages/sculpt/python3.11libs",
        "/Applications/Houdini/Houdini20.5.278/Frameworks/Houdini.framework/Versions/20.5/Resources/packages/kinefx/python3.11libs",
        "/Applications/Houdini/Houdini20.5.278/Frameworks/Houdini.framework/Versions/20.5/Resources/packages/apex/python3.11libs",
        "/Applications/Houdini/Houdini20.5.278/Frameworks/Houdini.framework/Versions/20.5/Resources/houdini/python3.11libs",
        "/Applications/Houdini/sidefx_packages/SideFXLabs20.5/scripts/python",
        "/Applications/Houdini/Houdini20.5.278/Frameworks/Houdini.framework/Versions/20.5/Resources/packages/kinefx/viewer_states",
        "/Applications/Houdini/Houdini20.5.278/Frameworks/Houdini.framework/Versions/20.5/Resources/packages/apex/viewer_states",
        "/Applications/Houdini/Houdini20.5.278/Frameworks/Houdini.framework/Versions/20.5/Resources/houdini/viewer_states",
        "/Applications/Houdini/Houdini20.5.278/Frameworks/Houdini.framework/Versions/20.5/Resources/packages/kinefx/viewer_handles",
        "/Applications/Houdini/Houdini20.5.278/Frameworks/Houdini.framework/Versions/20.5/Resources/houdini/viewer_handles",
        "/Applications/Houdini/Houdini20.5.278/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages",
        "/Applications/Houdini/Houdini20.5.278/Frameworks/Houdini.framework/Versions/20.5/Resources/houdini/python3.11libs",
        "/Applications/Houdini/Houdini20.5.278/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages",
        "/Applications/Houdini/Houdini20.5.278/Frameworks/Houdini.framework/Versions/20.5/Resources/houdini/python3.11libs",
        "/Applications/Houdini/Houdini20.5.278/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages",
        "/Applications/Houdini/sidefx_packages/SideFXLabs20.5/viewer_states",
        "/Applications/Houdini/Houdini20.5.278/Frameworks/Houdini.framework/Versions/20.5/Resources/packages/sculpt/viewer_states"
    ],
    "python.analysis.stubPath": "/Users/kajitaharuka/stubs/houdini20.5"
}

windowsでのsetting.jsonはこうなった。(extraPathsに不要っぽいパスが一つ混じってたのでそれは消してある。)

{
    "python.defaultInterpreterPath": "C:/Program Files/Side Effects Software/Houdini 20.5.278/python311/python.exe",
    "python.analysis.extraPaths": [
        "C:/Program Files/Side Effects Software/Houdini 20.5.278/python311/lib/site-packages-forced",
        "C:/Program Files/Side Effects Software/Houdini 20.5.278/python311/lib/site-packages-forced",
        "C:/Program Files/Side Effects Software/Houdini 20.5.278/python311/lib/site-packages-ui-forced",
        "C:/Program Files/Side Effects Software/Houdini 20.5.278/python311/lib/site-packages-forced",
        "C:/Program Files/Side Effects Software/Houdini 20.5.278/bin/python311.zip",
        "C:/Program Files/Side Effects Software/Houdini 20.5.278/python311/dlls",
        "C:/Program Files/Side Effects Software/Houdini 20.5.278/python311/lib",
        "C:/Program Files/Side Effects Software/Houdini 20.5.278/bin",
        "C:/Program Files/Side Effects Software/Houdini 20.5.278/python311",
        "C:/Program Files/Side Effects Software/Houdini 20.5.278/python311/lib/site-packages",
        "C:/Program Files/Side Effects Software/Houdini 20.5.278/packages/sculpt/python3.11libs",
        "C:/Program Files/Side Effects Software/Houdini 20.5.278/packages/kinefx/python3.11libs",
        "C:/Program Files/Side Effects Software/Houdini 20.5.278/packages/apex/python3.11libs",
        "C:/Program Files/Side Effects Software/Houdini 20.5.278/houdini/python3.11libs",
        "C:/Program Files/Side Effects Software/sidefx_packages/SideFXLabs20.5/scripts/python",
        "C:/Program Files/Side Effects Software/Houdini 20.5.278/packages/kinefx/viewer_states",
        "C:/Program Files/Side Effects Software/Houdini 20.5.278/packages/apex/viewer_states",
        "C:/Program Files/Side Effects Software/Houdini 20.5.278/houdini/viewer_states",
        "C:/Program Files/Side Effects Software/Houdini 20.5.278/packages/kinefx/viewer_handles",
        "C:/Program Files/Side Effects Software/Houdini 20.5.278/houdini/viewer_handles",
        "C:/Program Files/Side Effects Software/Houdini 20.5.278/python311/lib/site-packages",
        "C:/Program Files/Side Effects Software/Houdini 20.5.278/houdini/python3.11libs",
        "C:/Program Files/Side Effects Software/Houdini 20.5.278/python311/lib/site-packages",
        "C:/Program Files/Side Effects Software/Houdini 20.5.278/houdini/python3.11libs",
        "C:/Program Files/Side Effects Software/Houdini 20.5.278/python311/lib/site-packages",
        "C:/Program Files/Side Effects Software/sidefx_packages/SideFXLabs20.5/viewer_states"
    ],
    "python.analysis.stubPath": "C:/Stubs/houdini20.5"
}

Discussion