-
Notifications
You must be signed in to change notification settings - Fork 208
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
Github Actions とpre-commitにpoetry exportを適用 #716
Conversation
pre-commit.ci をGithubのリポジトリ側で有効にしてもらわないとダメなのを忘れていました |
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.
プルリクエストありがとうございます!!
コードを書き足す箇所とかがかなり適切で、レビューがしやすかったです!!
.github/workflows/test.yml
Outdated
- name: Run poetry | ||
run: | | ||
poetry export --without-hashes -o requirements.txt | ||
poetry export --without-hashes --with dev -o requirements-dev.txt | ||
poetry export --without-hashes --with test -o requirements-test.txt | ||
poetry export --without-hashes --with license -o requirements-license.txt |
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.
このままだとrequirements.txt
とpoetry.toml
が乖離していた場合に勝手にrequirements.txt
が上書きされちゃいそうです。(exportなので)
やりたいことは乖離していった時にエラーを出すことかなと!
たとえばrequirements.txt.check
にexportして、requirements.txt
と差分があったらエラーにするのはどうでしょう?
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.
コメントで挙げてもらった方法で対応しました
.pre-commit-config.yaml
Outdated
- id: poetry-export | ||
name: poetry-export | ||
args: ["--without-hashes", "-o", "requirements.txt" ] |
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.
実際にpoetry add
してpoetry export
しないままpushしてみたらちゃんとエラーが出ました!
ただエラーメッセージが若干不親切だなとちょっと思いました。
これ実際にエクスポートしているのでrequirements.txt
ファイルが置き換わるんですよね。
なので出来上がったファイルを再度コミットしてくださいというエラメッセージにするのはどうでしょう?
(そういうことってできそうでしょうか?)
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.
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.
なるほどです!!
ちょっと1点だけ、環境によってはpythonではなくpython3コマンドとしてPythonスクリプトを実行している人もいるはずで、そういう人にとってはエラーが出てしまうなと思いました!
どうにかできる解決策を調べてみたんですが、何か良い方法は見つかりませんでした・・・。
(シェルスクリプトを書くとかがあったのですが、これまたOSによっては動かないことがあるので)
特に初学者の方がpython3コマンドを使っていた場合、なぜエラーが出るのかわからずにちょっと戸惑ってしまうかもです。
poetry-exportがエラーになるのはpoetryを使えるぐらい熟練者の方なので、自力でなんとかできるかもしれない。
この辺りのバランスを取ると、もしかしたらpoetry-exportを実行するのがいいのかもとちょっと思いました。
(せっかく書いていただいたのに申し訳ないです 🙇 )
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.
>pythonではなくpython3
このパターンが確かにありましたね……
pythonコマンドから 実行バージョンを取得して、そのバージョンに応じたコマンドで poetry_export_all.py
を呼び出すとかでしょうか
それかpoetry-exportは pre-commitのentryで呼び出してgit diffによる確認だけスクリプトを呼び出す形にするか
やりようはある気がするので探ってみます
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.
pre-commitのentryで呼び出してgit diffによる確認だけスクリプトを呼び出す形
これで問題なさそうだったので poetry_export_check.py にリネームして、git diffだけPythonスクリプトで呼び出すようにしました
pythonコマンドがなくてpython3だけ入ってるということは考慮から外したのですが、問題ないでしょうか?
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.
なるほどです!! 提案ありがとうございます!!
まあでも、「poetry-export
によるエラーの理由が分からずに混乱する人の数」よりも、「python3コマンドを使っていてエラーが発生し理由が分からずに混乱する人の数」の方が多いかもですかね。。。
だとしたらpoetry-export-check
の方はない方がいいかもです 🙇♂️
どの環境でも動く方法があればという感じかなと・・・!
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.
差分のチェックは bash コマンドから poetry_export_check.shを実行する方針にしました
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.
bashもwindowsだと動かないんですよね・・・・・・・。
ChatGPT君に聞いてみた感じ、なんか良い感じの方法はなさそうでした。
https://chat.openai.com/share/94cee641-dfe0-483d-b9f3-84085899db20
なにかの言語で書いたものをバイナリにビルドして~とかが紹介されていますが、流石に・・・。
せっかくチャレンジしてくださったのに申し訳ないです 🙇
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.
Windows10からbashが正式サポートされた認識でした……
消しておきます!
765c886
to
db21bde
Compare
@Hiroshiba |
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.
追加ありがとうございます!!
.github/workflows/test.yml
Outdated
- name: Add Path for ubuntu | ||
if: matrix.os == 'ubuntu-20.04' | ||
run: | ||
echo "$HOME/.local/bin" >> $GITHUB_PATH | ||
|
||
- name: Add Path for Windows | ||
if: matrix.os == 'windows-latest' | ||
run: | ||
echo "C:\Users\runneradmin\AppData\Roaming\Python\Scripts" >> $GITHUB_PATH | ||
|
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.
これもpip installでpoetry入れるようになったらいらないはず・・・?
これは何でしょう、pre commitの内容をテストしてくれる感じでしょうか? |
pre-commit.ci は Github上で確認してくれるようになるやつですね |
@Hiroshiba 再レビューお願いします! |
@Hiroshiba 再レビューお願いします! |
.github/workflows/test.yml
Outdated
env: | ||
POETRY_VERSION: "1.3.1" | ||
|
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.
未使用な気がします!
バージョンはrequirements.txtにて固定しているので、ここに書いちゃうとバージョン不一致になってしまうかもです。
.pre-commit-config.yaml
Outdated
repos: | ||
- repo: https://github.com/python-poetry/poetry | ||
rev: '1.3.1' |
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.
ここもバージョン不一致になっちゃう可能性がありますね!
まあさほど問題ないのですが、もしrequirements.txtをpip installしたときに入るpoetryを使えるとちょっとかっこいいかもとか思いました。
難しそうなら一旦このままでも!
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.
pip install -r requirements.txtしてからpoetry exportを叩くように変更しました
ほぼLGTMです!!! |
@Hiroshiba 再レビューお願いします |
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!!!
ちょっと細かい部分をこちらで調整させて頂きます!!
PRありがとうございました!
こちらのコメントに対してしっかり対応頂けて嬉しかったです。
もしよかったらまだまだいろんなissueがありますので、なにかできそうなのがあればぜひ・・・!
https://github.com/VOICEVOX/voicevox_engine/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc
.pre-commit-config.yaml
Outdated
entry: poetry export --without-hashes -o requirements.txt | ||
language: python | ||
pass_filenames: false | ||
stages: [commit] |
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.
pysen-lint
に合わせてstages: [push]
にしようと思います! 🙇
.pre-commit-config.yaml
Outdated
- id: pip-install | ||
name: pip-install | ||
entry: pip install -r requirements.txt | ||
language: python | ||
pass_filenames: false | ||
stages: [commit] |
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.
pip installが勝手に実行されるのは意図せず開発環境が壊れかねないので、一旦やめておく感じで・・・!
内容
Github Actions とpre-commit のそれぞれで
poetry export
を行うように対応しました関連 Issue
ref #566
スクリーンショット・動画など
その他