
要約
- pre-commitのpoetry-export hookで警告が表示された
poetry-plugin-exportをインストールするpoetry self show pluginsでインストール内容を確認し、poetry config warnings.export falseで警告表示を無効にする
追加情報(2025/01/07)
GitHub Actionでpoetry exportコマンドを実行するステップで以下エラーになりました。 GitHub Actionについては以下記事でも紹介しています。
7rikazhexde-techlog.hatenablog.com
Run poetry export -f requirements.txt -o requirements.txt --without-hashes
poetry export -f requirements.txt -o requirements.txt --without-hashes
poetry export -f requirements.txt -o requirements-dev.txt --without-hashes --with dev
shell: /usr/bin/bash -e {0}
env:
pythonLocation: /opt/hostedtoolcache/Python/3.13.1/x64
PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.13.1/x64/lib/pkgconfig
Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.13.1/x64
Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.13.1/x64
Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.13.1/x64
LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.13.1/x64/lib
The command "export" does not exist.
Error: Process completed with exit code 1.
対象方法として、以下の解決方法記載のコマンドをworkflowに記載することで実行できるようになりました。
- name: Set up Python uses: actions/setup-python@v5.3.0 with: python-version: '3.13' - name: Install Poetry run: pip install poetry - name: Install dependencies run: poetry install - name: Add plugin #追加 run: poetry self add poetry-plugin-export #追加 - name: Update requirements files run: | poetry export -f requirements.txt -o requirements.txt --without-hashes poetry export -f requirements.txt -o requirements-dev.txt --without-hashes --with dev - name: Commit and push changes run: | git config --local user.email "33836132+github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" git add requirements.txt requirements-dev.txt git commit -m ":wrench:Update requirements files after dependency update [skip ci]" || echo "No changes to commit" git push
現象
pre-commitでpoetry-export hookを使用しているのですが、v1.7.1に変更し、poetry run pre-commit run --all-filesを実行したところ、以下の警告が表示されました。
Warning: poetry-plugin-export will not be installed by default in a future version of Poetry. In order to avoid a breaking change and make your automation forward-compatible, please install poetry-plugin-export explicitly. See https://python-poetry.org/docs/plugins/#using-plugins for details on how to install a plugin. To disable this warning run 'poetry config warnings.export false'.
公式ドキュメントにも同様の警告内容が記載されていました。
This command is provided by the Export Poetry Plugin. The plugin is no longer installed by default with Poetry 2.0.
実行環境
.pre-commit-config.yaml(poetry部分抜粋)
# https://python-poetry.org/docs/pre-commit-hooks/#usage
- repo: https://github.com/python-poetry/poetry
# Cannot be executed with local designation (as of 23.11.25)
rev: 1.7.1
hooks:
- id: poetry-check
verbose: true
- id: poetry-lock
verbose: true
- id: poetry-export
args: ["-f", "requirements.txt", "-o", "requirements.txt"]
verbose: true
files: ^pyproject\.toml$
- id: poetry-export
args: ["--dev", "-f", "requirements.txt", "-o", "requirements-dev.txt"]
verbose: true
files: ^pyproject\.toml$
解決方法
警告メッセージの記載通りですが、将来のPoetryのバージョンでは、poetry-plugin-exportはデフォルトではインストールされないようです。したがって、自動化が前方互換性を持つように、poetry-plugin-exportを明示的にインストールすることが推奨されます。そこで、公式のインストール手順を確認し、poetry-plugin-exportをインストールします。
poetry self add poetry-plugin-export Using version ^1.6.0 for poetry-plugin-export Updating dependencies Resolving dependencies... (0.2s) No dependencies to install or update Writing lock file
念の為以下のコマンドでインストールされたプラグインを確認します。
poetry self show plugins
• poetry-plugin-export (1.6.0) Poetry plugin to export the dependencies to various formats
1 application plugin
Dependencies
- poetry (>=1.6.0,<2.0.0)
- poetry-core (>=1.7.0,<2.0.0)
動作確認
poetry run pre-commit run --all-filesによる確認
poetry run pre-commit run --all-files # 省略 poetry-export............................................................Passed - hook id: poetry-export - duration: 0.69s Warning: poetry-plugin-export will not be installed by default in a future version of Poetry. In order to avoid a breaking change and make your automation forward-compatible, please install poetry-plugin-export explicitly. See https://python-poetry.org/docs/plugins/#using-plugins for details on how to install a plugin. To disable this warning run 'poetry config warnings.export false'. poetry-export............................................................Passed - hook id: poetry-export - duration: 0.7s Warning: poetry-plugin-export will not be installed by default in a future version of Poetry. In order to avoid a breaking change and make your automation forward-compatible, please install poetry-plugin-export explicitly. See https://python-poetry.org/docs/plugins/#using-plugins for details on how to install a plugin. To disable this warning run 'poetry config warnings.export false'. The `--dev` option is deprecated, use the `--with dev` notation instead.
poetry exportによる確認
poetry export -f requirements.txt --output requirements.txt Warning: poetry-plugin-export will not be installed by default in a future version of Poetry. In order to avoid a breaking change and make your automation forward-compatible, please install poetry-plugin-export explicitly. See https://python-poetry.org/docs/plugins/#using-plugins for details on how to install a plugin. To disable this warning run 'poetry config warnings.export false'.
コマンドの実行結果から、poetry exportコマンドを実行しても警告メッセージは表示され続けます。プラグインはインストールされたことは確認しているので、poetry config warnings.export falseで警告表示を無効にします。
poetry config warnings.export false
警告メッセージ表示を無効にしているので、正しく設定できているが不安になりますが、これで警告表示は消えて引き続きpoetry exportフックが使用できるはずです。
以上です。