Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poetry plugin #14

Closed
nat-n opened this issue Oct 21, 2020 · 12 comments
Closed

Poetry plugin #14

nat-n opened this issue Oct 21, 2020 · 12 comments

Comments

@nat-n
Copy link
Owner

nat-n commented Oct 21, 2020

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
@ThatXliner
Copy link
Contributor

Or maybe just poetry test! Can we do that?

@nat-n
Copy link
Owner Author

nat-n commented Mar 10, 2021

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

@MartinWallgren
Copy link

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

Looks exciting

@ThatXliner
Copy link
Contributor

ThatXliner commented Jun 25, 2021

@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
                ),
            )

@billsioros
Copy link

Any news on this ? 😄

@nat-n
Copy link
Owner Author

nat-n commented Jul 3, 2021

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.

@ThatXliner
Copy link
Contributor

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

@ThatXliner
Copy link
Contributor

Ok, just tested. My PR should work now.

@acalvino4
Copy link

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.

@acalvino4
Copy link

Well poetry 1.2 is now out along with plugin docs!

@nat-n
Copy link
Owner Author

nat-n commented Dec 30, 2021

@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.

@nat-n
Copy link
Owner Author

nat-n commented Jan 8, 2022

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.

@nat-n nat-n closed this as completed Jan 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants