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

Global task configuration? #233

Closed
Ravencentric opened this issue Jul 30, 2024 · 4 comments
Closed

Global task configuration? #233

Ravencentric opened this issue Jul 30, 2024 · 4 comments

Comments

@Ravencentric
Copy link

Ravencentric commented Jul 30, 2024

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
Copy link
Owner

nat-n commented Aug 4, 2024

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
Copy link
Author

Ravencentric commented Aug 5, 2024

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 added a commit that referenced this issue Aug 18, 2024
Completion scripts and list_tasks are not configurable to specify the executable name and respect the -C/--directory option.

fish and zsh completion scripts now understand when the -C/--directory option has been specified and will suggest tasks from the correct project.

The zsh completion script also generally handles passing multiple arguments.

Addresses #233
@nat-n
Copy link
Owner

nat-n commented Aug 31, 2024

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

@nat-n nat-n closed this as completed Aug 31, 2024
@Ravencentric
Copy link
Author

Awesome! Thanks alot!

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

No branches or pull requests

2 participants