-
Notifications
You must be signed in to change notification settings - Fork 790
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
Using uv run
as a task runner
#5903
Comments
Relevant comment from another issue: #5632 (comment) |
PDM supports this: https://pdm-project.org/latest/usage/scripts/ |
Yeah we plan to support something like this! We haven't spent time on the design yet. |
The pyproject standard already supports |
|
Perhaps naming this section |
Or maybe |
This is the main thing I missed coming from hatch: https://hatch.pypa.io/dev/config/environment/overview/#scripts |
+1 to @nikhilweee suggestions. I think “command” reflects the intent/concept. Hatch has an “environment” concept and supports running commands namespaced to an environment like so
where “test” is a user-defined environment (with a dependency group) and “cov” is a user-defined command for that environment. [tool.hatch.envs.test]
dependencies = [
"pytest",
"pytest-cov",
"pytest-mock",
"freezegun",
]
[tool.hatch.envs.test.scripts]
cov = 'pytest --cov-report=term-missing --cov-config=pyproject.toml --cov=src'
[[tool.hatch.envs.test.matrix]]
python = ["3.8", "3.9", "3.10", "3.11", "3.12"] I would be curious to hear the use cases of nesting dependency groups and commands into “environments” like this rather than defining them at the top-level (i.e. |
since it has not been mentioned yet, adding as a possible inspiration for design of tasks also pixi: https://pixi.sh/latest/features/advanced_tasks/ |
I happen to be writing a cross-project task runner that supports a bunch of formats (e.g. rye, pdm, package.json, Cargo.toml; even uv's workspace config). For what it's worth, almost all python runners use |
Also related to this thread, I wish uvx was
I know Regarding |
@inoa-jboliveira I opened a dedicated issue for that #7186 |
Putting together some thoughts about semantics. This issue is about adding support for running arbitrary instructions specified in What do we call these instructions?Lots of existing tools refer to them as "scripts".
It seems advantageous to just go with the term "scripts" because it is the de-facto standard. As noted by another user #5903 (comment), this would also reduce friction for users coming to Another option is to use the term "tasks"
Another option is to call them "executables". We could also use "commands", although I wasn't able to find existing tools which use this term. After settling on a name, an obvious thing to do is to let users define instructions in the How do we invoke these instructions?There are two options here.
How should these instructions be specified?PDM's documentation around user scripts is pretty evolved, with support for a bunch of features.
Rye has its own format, which is a subset of PDM features.
I hope this serves as a starter for discussing additional details for this feature. |
(Nice comment, thank you!) |
One nice thing about PDM is that if a command is not recognized as a built-in, it is treated as |
IMHO, Alas, one can argue that the |
I wonder if would be a good time to maybe standardise this? I don't know if a pep is required, but since we have some many package managers for python it would be nice if we can have one way to define these instructions |
Hi. I created a small, dependency-free tool to manage scripts directly from pyproject.toml: I came across this thread after implementing my own solution… Silly me. I hope the following example can provide some useful ideas for the discussion. Config Example[tool.tomlscript]
# Start dev server ==> this line is the documentation of the command
dev = "uv run uvicorn --port {port:5001} myapp:app --reload"
# Linter and test
test = """
uv run ruff check
uv run pytest --inline-snapshot=review
"""
# Generate pyi stubs (python function) ==> Execute python function
gen_pyi = "mypackage.typing:generate_pyi"
# Functions defined here can be reused across multiple commands
source = """
say_() {
echo $1
}
""" Usage
|
FWIW, I tried to capture some of my wish list here - https://notes.strangemonad.com/Some+thoughts+on+python+workspaces. It's a bit broader in scope than just the task runner aspect but touches on how I'd like to see task runner commands, multi-project workspaces and consistent lifecycle commands work nicely together |
First of all, I have to say that I appreciate the effort, and the terse config style. 👍🏻 The syntax is perhaps a little too magical for my tastes, but it does look nice. That said, I admire what I find to be a slightly terrifying YOLO implementation of |
I believe this is one of the most major features that Adding support for this would bridge a major part of the feature gap! |
Thanks! I was using poethepoet for a while with poetry, didn't know I could use it in any pyproject.toml. This is enough for now |
what's the downside of pure shell instead of task runners such as poe? |
Using pure shell might need to activate the Python environment each time. Like invoking And using task runners can also create shorthand for long commands. Like using Indeed these can all be done by some other approaches, but these tasks are often project-related and makes more sense to store as part of project config. This also allows them to be shared with other collaborators. |
Thank you for the comprehensive explanation! It does help understand the benefits of task runners. We've been pondering the choice between pure shell and task runners in my new Python template repo. Unfortunately, I chose pure shell in the end. I'd like to share my perspective to offer others additional insights:
So in my opinion, using a task runner feels redundant. |
@AtticusZeller Yes, that's true. There is always multiple approaches to make life easier. What I mind is that these methods require you to set up your environment separately (such as configuring IDE to recognize and automatically activate virtual environments, configuring shell auto-completion, etc.). Not everyone has the same configuration. Using a task runner can standardize it and make it independent of the environment. This way, when I or anyone else checked out the repository in any environment, they only need to have Because of these requirements of my use case, the task runner is more attractive to me. |
@Xdynix Thank you for sharing your perspective! I understand your point about standardization and ease of use. However, I'd like to offer a different views. I believe this might be asking too much from
The current solution feels like over-packaging - binding script execution tightly with |
@AtticusZeller (Just some off-topic chitchat)
I thought that one selling point of
I totally agree. But I don't really want to force other people's toolboxes, especially when it's an informal collaboration, such as an open source project, a lab course, etc. Some people like VS Code, some like PyCharm, not to mention vim users (and notepad users?). And I'm too lazy to maintain a set of documentation for each common tool. Therefore I prefer to provide only minimal but sufficient developer experience support. |
Here's the kicker for me -- Windows support. I'm in a mixed team with about half the people on Windows / Visual Studio (the old one, not VS Code), half on macOS with PyCharm or VS Code, and some funny people using Vim/Neovim on WSL or Linux proper. Sure, I can whip out some Makefiles and bash scripts, but they will not work reliably for all developers, on all environments. One way to tackle this is with policy and tooling. We could force our team to all use Unix. Or we could use Vagrant. But a better solution, in my opinion, is Python. It's already portable by design. The standard library |
uv offers a unified experience across all platforms, combining the aforementioned tools in a single binary, which is amazing. But IMHO, a task runner should be language-agnostic, allowing to join forces for its development and maintenance, having the same features in all projects no matter the language, and avoiding the need to learn a new tool (for essentially the same thing) for each language. A popular and powerful cross-platform task runner is Task, and it is also available as a Python package (merely shipping the compiled Go binary) to ease its installation in Python projects. Although it appears convenient to have yet another task runner integrated with uv, I'd vote against it for the mentioned reasons. |
I absolutely do not agree that scripts or tasks would be "over-packaging".
(See also the previous overview by @nikhilweee.) In other words -- scripts or task runner functionality is not over-packaging. It's standard and expected functionality in every other modern workflow packaging tool for Python. In fact, if uv could not offer user-definable tasks, or a plugin system, it would be worse than every other modern packaging tool in this regard. |
I respectfully disagree with this perspective for several key reasons:
The prevalence of task runners in existing tools doesn't automatically justify their inclusion in new ones. This appears to fall into the "appeal to popularity" fallacy. Just because Rye, Hatch, PDM, and others implement task runners doesn't mean it's the optimal design choice.and task runner absolutely not denote modern
The Unix philosophy advocates for tools that do one thing and do it well. When we examine the practical value of built-in task runners because most "tasks" are simply command aliases that can be handled by shell scripts and when it comes to complex workflows often require proper build tools anyway, Adding task running to uv would dilute its core responsibility of package and Project management while providing minimal practical benefit.
This comparison overlooks crucial differences Rust's ecosystem is built around a single, standardized toolchain,but Python's ecosystem is intentionally diverse, with different tools serving different needs, so forcing Cargo-like standardization onto Python goes against its philosophy of "we're all consenting adults here" |
People choose and judge tools based on practicality and applicability, rather than opinions. These opinions have no meaning, even if you vote, a very few people would refuse this feature |
I'm excited about I think running tasks is a common enough need that it would fit well into |
there are
also solves the problem of combinatorial explosion when N tools are used, but even more powerfully, as beyond just Python ecosystem |
To Be, Or Not To BeFirst, the uv team at Astral have already decided that they are going to add some kind of task runner: @charliermarsh commented on Aug 9
...So I do not think it's very helpful for anyone if we discuss our opinions for or against endlessly. I think the more constructive thing to do would be to help with the design. Target AudienceThere is indeed a diverse ecosystem of tools for Python, since it's an old language that predates modern workflow tools for other languages, such as cargo, npm, dotnet, et al. All of this will continue to exist whether uv has a basic task runner or not. Senior Python developers can continue to deploy fancy customized toolchains for their teams or CI/CD. However, for new Pythonistas, either students, or developers coming from newer language ecosystems such as .NET, Rust, or Javascript, it would be very helpful to have the mythical "Cargo for Python" or "One tool to rule them all". Read e.g. Rye's Philosophy and Vision for building "the one tool" that the majority of Pythonistas would use most of the time because it's the easy, obvious default. It won't solve every problem and corner case, perhaps, but it will cover most needs for mostly everyone most of the time. The Zen Of Python
Building "the one tool" or "Cargo for Python" would be the obvious way to develop in Python. Of course there will be a diverse ecosystem of specialized tools for every situation... But the should be one obvious way to start, lint, format, test, build, and publish a normal open source Python project. I think uv should become "the one tool", and I think that requires the same basic task running capabilities that all the other modern Python workflow tools have. |
The open question for me is whether or not we should be building a general purpose task runner, i.e., designing some sort of DSL, or investing specifically in |
(While I think @harkabeeparolus has a great point that moving the design forward is the best way to help move this issue forward, I do think discussion on the goals of and motivation for a task runner are reasonable as they will help inform the design) |
I want to build on this point from @chrisrodrigue earlier in the thread. With Hatch, we can tie scripts to specific sets of dependencies, installed into separate environments. This can be much more general than
I'm not at all opposed to expressing these sorts of things with plain old shell scripts. What we're still missing in uv however (unless I am just out of date here) is a way to tie scripts to a specific dependency group or union of dependency groups. |
One more vote that this should be implemented. I think there would be a lot of value for being able to define a default target that allows me to start a package without knowing anything about it. Most Node packages can be started with "npm run" and I do not have to know the name of the package or the main javascript file. With package managers likely being the default way how novice users will run python packages in the future, I think ease-of-use matters. |
Hi everyone, this discussion is veering off course. If you’re not interested in the task runner, please consider downvoting the issue and moving on. I’ve explored the workarounds, but unfortunately, each one falls short in some way. Let’s avoid introducing philosophical debates about open source maintenance and stay focused on resolving the issue at hand. Thanks! |
I have suggestions conditional on uv implementing a task runner. Poe the Poet sequencesI use Poe the Poet as my task runner with both Poetry and uv. Something I really like about Poe is how it handles sequence tasks. I haven't seen it in other Python task runners. You can have a failure in a sequence abort the sequence immediately, have no effect, or only change the exit code of Here is how I use it in my website project. (The Lua is for Pandoc.) [tool.poe.tasks.check]
sequence = ["format", "lint", "type", "format-lua", "lint-lua"]
help = "Format and run all static checks"
ignore_fail = "return_non_zero" Starting with PoeIf uv implements a task runner, I would like it to have a similar feature to Poe's sequences. More broadly, my impression is that Poe has well-designed features absent in other Python task runners. Poe also seems to be the go-to task runner for Poetry users. Because of this, I think reimplementing Poe the Poet would be a good starting point for uv. The existing design of Poe could be refined as needed in the process, like how it happened with the Ruff formatter. |
For those of us migrating over from Rye, one of its nice features is the built-in task runner using
rye run
and[tool.rye.scripts]
. For example:It could have some more features - here is a selection of feature requests from the community:
tool.rye.scripts
rye#930A lot of these requested features are things that other 3rd party tools currently offer. I thought it might be useful to highlight a few other tools here, in particular because they also integrate with the
pyproject.toml
ecosystem and can be used with uv today.Poe the Poet
https://github.com/nat-n/poethepoet
taskipy
https://github.com/taskipy/taskipy
Perhaps these can serve as some inspiration for a future
uv run
task runner and also in the meantime offer a solution for people coming over from Rye looking for a way to run tasks.The text was updated successfully, but these errors were encountered: