nat-n / poethepoet

A task runner that works well with poetry.
https://poethepoet.natn.io/
MIT License
1.39k stars 56 forks source link

Postinstall hook with tasks refering to package that's being installed #197

Closed mgzenitech closed 6 months ago

mgzenitech commented 6 months ago

So here's my problem:

Part of pyproject.toml:

...
[tool.poetry.group.core.dependencies]
lib = {git = "git@xxxx/python-lib.git", rev = "python-3.12"}

[tool.poe.poetry_hooks]
post_install = "install_node"

[tool.poe.tasks."install_node"]
control.script = "cli.__pyhelpers.is_nodejs_valid:is_nodejs_valid"
control.print_result = true
default = "pass"

[[tool.poe.tasks."install_node".switch]]
case = "False"
script = "cli.__pyhelpers.install_nodejs:install_nodejs"

Both cli.__pyhelpers.install_nodejs and cli.__pyhelpers.is_nodejs_valid depend on imported stuff from lib. Naturally, I expect Poetry to install dependencies and then successfully trigger postinstall hook. However I get this:

poetry install --no-root --with=core
...
ModuleNotFoundError: No module named 'lib'
Error: Switch task 'install_node' aborted after failed control task 
Cancelling command due to failed hook task

Looks like poe the poet tries to load cli.__pyhelpers.is_nodejs_valid immediately and not after Poetry package installation.

mgzenitech commented 6 months ago

Hm... looks like it is related to pyenv plugin as it throws error but poe the poet still triggers it's own postinstall hook