Open StripedMiha opened 10 months ago
Hi @StripedMiha,
However, I need the hook to be executed only when entering the poetry install command with the --with dev argument.
I'm afraid limiting poetry hooks to invocations including specific arguments is not currently supported. Your workaround using a switch task is interesting, and might even work.
I believe the error you're getting from the expr
task is because an expr task content is actually interpreted as subset of python, and as it happens with
is a keyword in python, so the validation fails.
You should be able to avoid this particular error by mapping the argument to a different name with something like:
control.expr = "deps_group"
args = [{ name = "deps_group", options = ["--with"] }]
Please let me know if you get it working :)
@nat-n Thanks for the advice.
But I'm afraid I don't quite understand how this should work, but this option does not catch the argument correctly and gives a default response.
[tool.poe.tasks.pre_commit_install]
help = "pre-commit pre install"
control.expr = "deps_group"
args = [{ name = "deps_group", options = ["--with"] }]
[[tool.poe.tasks.pre_commit_install.switch]]
case = "dev"
cmd = "pre-commit install"
[[tool.poe.tasks.pre_commit_install.switch]]
cmd = "echo abc"
The response from such a command now does not fall with an error, but the switcher does not catch the argument
Hi @StripedMiha ,
Thanks for getting back. In that case I think what you want is not possible today, because the poetry plugin only passes the task name to poe: https://github.com/nat-n/poethepoet/blob/71fcdc788372f2b00ca3d6642ee6a4fcb4965982/poethepoet/plugin.py#L226
However in principle I suspect it could be supported because that linked function in the plugin could inspect the arguments from the present ConsoleCommandEvent
and pass them to the poe task. It would also require a tweak to the logic around there to support templating in the poetry task's args if the user configures the hook with something like:
post_install = "_my_task --with=${POETRY_ARGS_WITH}"
.
Maybe this wouldn't too difficult to implement. I'll leave this issue open as an enhancement request.
Hi! I was very interested in your tool and decided to implement it into the project.
In my project, I want to add a hook with a pre-commit install setup along with executing the poetry install --with dev command. Here is my
puproject.toml
with dependencies divided into groups:I have a working solution for this purpose, which is always executed when entering the
poetry install
command.However, I need the hook to be executed only when entering the
poetry install
command with the--with dev
argument.Here is my vision of
pyproject.toml
, for such functionality:When I enter the command
poetry install --with dev
, I get the following error:Please help me figure out what went wrong.
Thanks!