nat-n / poethepoet

A task runner that works well with poetry.

Home Page:https://poethepoet.natn.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Poetry plugin

nat-n opened this issue · comments

The roadmap for poetry includes a plugin system python-poetry/poetry#1237 which should allow for poe to run inside the poetry CLI.

Creating a Poe the Poet plugin for poetry would ideally entail that the exact same config in the pyproject.toml could be used to the same effect either via the existing poe CLI, or via poe running as a poetry plugin and invoked via the the poetry CLI.

It'll probably look something like:

poetry poe test

which would be functionally equivalent to the following but with a shorter command a perhaps a minor performance boost:

poetry run poe test

Or maybe just poetry test! Can we do that?

@ThatXliner It'll depend on what the poetry plugin API supports in the end. Though I suspect that probably won't be possible :/

A plugin system was merged a while back python-poetry/poetry#3733

Looks exciting

@ThatXliner It'll depend on what the poetry plugin API supports in the end. Though I suspect that probably won't be possible :/

we can create arbitrary classes (with type and all) inside our factory function https://python-poetry.org/docs/master/plugins/#application-plugins

So something like

from cleo.commands.command import Command
from poetry.plugins.application_plugin import ApplicationPlugin


class PoePlugin(ApplicationPlugin):
    def activate(self, application):
        for task_name in get_poe_task_names():  # Assume this function exists somewhere
            application.command_loader.register_factory(
                task_name,
                lambda x: type(
                    task_name.capitalize() + "Command",
                    (Command),
                    {"name": task_name, "handle": lambda self: run_poe_task(self.name)},
                    # Also assume `run_poe_task` accepts task name as an argument, runs that poe task
                    # and returns the return code of the poe task
                ),
            )

Any news on this ? 😄

Hi @billsioros, I haven't had time to look into it much yet, though this feature probably required a bit of refactoring, so it's currently blocked on some other in progress features. Hard to give in ETA right now.

I have tried implementing this. Haven't tested it yet

Ok, just tested. My PR should work now.

Or maybe just poetry test! Can we do that?

As @nat-n pointed out, this obviously depends on what the plugin api supports, but I suppose this would basically involve being a fallback where if there isn't another poetry command that the poe command list is checked.

Anyway, I would love to see this plugin happen! though it still looks like we are waiting on poetry 1.2 for plugins to be possible.

Well poetry 1.2 is now out along with plugin docs!

@acalvino4 I've been working on this #46 . It's almost ready, but could use some help with testing from this branch if you're game? https://github.com/nat-n/poethepoet/tree/feature/14/poetry-plugin

By default tasks are invoked like poetry poe task-name, but can be configured to register tasks as top level commands (on a per project basis) as long as you're careful to avoid collisions with poetry commands or commands from other plugins.

Poetry 1.2 is still in alpha. The implementation requires some hacking around limitations of cleo the CLI framework that poetry uses, hopefully it's stable enough already that it won't break before 1.2 is released.

0.12.0 has just been released and supports using poe as a poetry plugin.

In addition to running poe tasks through poetry, it also uses poetry's events API to support registering tasks as hooks to be run before or after other poetry commands.