nat-n / poethepoet

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

Global task configuration? #233

Closed Ravencentric closed 2 months ago

Ravencentric commented 3 months ago

Several of my projects use the same development workflow which means they also share the same commands I wanna run. Is it possible for me to define some global tasks in something like ~/poe.toml?

# ~/poe.toml
[tasks]
fmt = "ruff format"
mypy = "mypy src"
test = "coverage run -m pytest -vv --maxfail=1"

Now if I run poe fmt in a project directory with pyproject.toml it should behave no different than it would have if fmt was defined in the project's pyproject.toml. If there's a name clash, then pyproject.toml should override the global one

nat-n commented 3 months ago

Hi @Ravencentric, thanks for sharing your use case. I've been thinking about something similar recently. In a sense this goes against what poethepoet was designed to do which is manage self contained tasks for a project in a way that all collaborators on that project can easily benefit from. However poe has some features that you could exploit to get what you want.

The include global option is primarily intended for organising and reusing tasks within a monorepo, but you could also use it to include tasks from a central location like so:

[tool.poe]
include = "/Users/nat/.poethepoet/common_tasks.toml"

I think this accomplishes almost exactly what you're asking for. This is fine if you're the only one working on these projects, but it's not so great for collaboration since the project is no-longer self contained. If this matters to you then you could also have common tasks in a dedicated repo that you reference as a git submodule other projects and target with the include global option.

Another approach which I've been thinking about improving support for would be to have essentially a normal poetry project with poe tasks somewhere like ~/.poethepoet/pyproject.toml, then create an alias to make those tasks globally accessible like:

alias po="poe -C ~/.poethepoet"

You can then use po as a global task runner for your user, so tasks you define in your home directory are accessible everywhere! This is ideal if you have tasks you want to user everywhere, though with less integration into projects.

There's another possible approach, which is closer to what you suggested which would be to support defining a user level tasks file that is automatically included into all projects, though I'm not sure this is a good idea. It adds some complexity which could lead to surprising behaviour.

What do you think?

Ravencentric commented 3 months ago

Thank you for the detailed answer! I think the aliasing to a config file that I can use globally gets the job done in my case. Using include to point to a file exclusive to my pc outside of version control doesn't make much sense if I'm committing it to git. This is mostly for small personal projects where I'm not expecting any contributions and trying to reduce friction in the initial setup.

nat-n commented 2 months ago

@Ravencentric FYI since version 0.28.0 the "global tasks" solution is supported with shell completion and is documented here.

Ravencentric commented 2 months ago

Awesome! Thanks alot!