Gorialis / jishaku

A debugging and testing cog for discord.py rewrite bots.
https://jishaku.readthedocs.io/en/latest/
MIT License
541 stars 179 forks source link

Jishaku version occasionally appears as vNone in selftest #205

Open tuna2134 opened 1 year ago

tuna2134 commented 1 year ago

Summary

When I run jsk root command, jishaku show me like this image. IMG_0470

Reproduction steps

When I run jsk command.

Checklist

System information

- Python v3.10.7-final
- discord.py v2.2.2-final
- aiohttp v3.8.3
- system info: Linux 5.15.0-48-generic #54~20.04.1-Ubuntu SMP Thu Sep 1 16:17:26 UTC 2022
Gorialis commented 1 year ago

I've encountered this a few times around the place, and last I checked, it traces back to module lookup creation in distutils. If with pip you somehow break one of your packages - or one ends up in a transient state while distutils is trying to deal with it, the creation will fail and distutils will remain forever unable to pull information from any package until the interpreter is restarted.

It's not an easy bug to reproduce, and its root cause is not possible to fix because it is caused by pip not us. But, some kind of workaround should be implemented that maybe doesn't rely on distutils if it coughs up evidence that it broke its database.

tuna2134 commented 1 year ago

なにか必要な情報ありますか?

Gorialis commented 1 year ago

jishakuのバージョン情報を取得するには二つの方法があります: ① jishaku内のバージョン情報 (jishaku.version_info, jishaku.__version__) ② pkg_resourcesの記録されたバージョン (つまり pip show とかで出るバージョン) 内容はほとんど同じですが、 GitHubからインストールした場合、gitハッシュとコミット数 (a1234+g1234abc.master の部分) はもちろんパッケージに埋め込んでないので、selftestはそれを表示するには 3fd14708c6ad8d71617d03e301e96cc1359c87ae で取得方法は ① から ② になりました。 ですが、pkg_resourcesはなぜかかなり敏感なもので、一瞬でも異常事態が起こったら (例えばpipがクラッシュするとか) 内部データベースが破損されてしまい、お待ちかねの vNone が出てしまいます。 だから、正確に言えばこれは jishaku 自体のバグじゃないけど、それでも煩わしいので修正したいです。今破損してる環境持ってないので、site-packagesのコンテンツをzipにしてアップロードできれば助かるけど、そうではない場合は自分でこの状態になるまで待つしかない。

逆に早速で直したいのであれば、site-packagesを確認して異変があるかを確かめてみてください。おそらく、~が先頭にある (例えば ~iohttp とか) pipの痕跡フォルダーが残っていて、それを消してインタプリタを再起動すればデータベースが無事に再構築されるはず。

tuna2134 commented 1 year ago

Okay, I'll do after I finish exam.