Skip to content

poetry_hooks with switch tasks by named argument #193

@StripedMiha

Description

@StripedMiha

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:

[tool.poetry.dependencies]
python = "^3.10"
...
poethepoet = "^0.24.4"

[tool.poetry.group.dev.dependencies]
...
pre-commit = "^3.2.0"


[tool.poetry.group.test.dependencies]
...

I have a working solution for this purpose, which is always executed when entering the poetry install command.

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

[tool.poe.tasks.pre_commit_install]
help = "pre-commit pre install"
cmd = "pre-commit install"

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:

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

[tool.poe.tasks.pre_commit_install]
help = "pre-commit pre install"
default = "pass"
control.expr = "with"
args = ["with"]

    [[tool.poe.tasks.pre_commit_install.switch]]
    case = "dev"
    cmd = "pre-commit install"

When I enter the command poetry install --with dev, I get the following error:

image

Please help me figure out what went wrong.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions