-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 |
I started with Rye, and was really enjoying its built-in task runner. But it was missing some features, so I started a Python version to experiment with. Then I made the switch to uv and was missing that built-in task runner, so I continued working on, and just published, my Python task runner, pyproject-runner, and the related pyproject-runner-shim. pyproject-runner is similar to Rye's task runner, and should require few changes for those moving to uv from Rye. See the FAQ answering "why not use an existing tool?" I am open to using pyproject-runner as a playground to test features that might go into an official uv task runner. |
Man, I just switched from |
I might be missing a key detail which is why it's not working but even being able to run local modules in the project would be nice. # tests/runner.py
def hello():
print('Hello')
def world():
print('World') Being able to run this as |
* Similar to npm run, the attempt was to unify test commands * up to now, this is done using individual shell scripts on the devs' machines * this is the attempt to unify this * Note, the additional dependency on taskipy can hopefully be removed as soon as astral-sh/uv#5903 is resolved
As running tasks is an action was usually has to be done frequently it would be great if typing them can be done fast. Thus for example the widespread nodejs tool pnpm allows shortcuting the run command be omiting "run" if the task is not in conflict with any uv command. Thus instead of writing
I could write
In my opinion it would be really great if uv provides a similar DX. |
@mrh1997 This could lead to ambiguous behaviour. If you want to type less, you could just |
The downside of an alias is, that it is not available in every environment. I.e. if I support a collegue or created a new docker container I had to fall back to "uv run". How about providing this shortcut by uv? Like you did with uvx. Then one could run for example
|
@mrh1997 @d-k-bo The simplest way is to treat commands as tasks only if they're not conflicting with
|
This way it limits the design space for new uv commands is concerning. I don't see how it could be worth the cost. |
@neutrinoceros The shortcut is just an add-on. If a |
Multiply that experience by the number of users and you're guaranteed to generate friction, confusion and complaints every time a new command is introduced. I simply don't think it's worth it. |
You can choose not to use the shortcut feature then, you don't lose anything. The point is to provide an option that trades the benefit of having to type less often, at the expense of the (very small) chance that your shortcut will break. |
Would you assume that every user opting in would necessarily understand the risk around upgrades ? What happens when someone integrates such a command into a CI job with an unpinned |
A reasonable concern. All I can say is that no matter how much design you do, you can never completely prevent users from making mistakes. That will be a tradeoff for Astral to make. I will only express my desire for this feature. |
@neutrinoceros I got your arguement about the risk on breaking changes. But what do you think about my proposal of a standardized shortcut like |
I don't have a strong opinion there.
cons:
I would probably use it if it existed, though I'm also happy to live without it. |
I've recently started using bash scripts with
#!/usr/bin/env -S uv run --group test bash
# shellcheck shell=bash
set -xeuo pipefail
coverage run -pm pytest
coverage combine
coverage report
[dependency-groups]
test = [
"coverage",
"pytest",
] |
Not sure if this has been suggested before, but it would nice if it could also support chaining scripts such as: uv run script1,script2 This is similar to how tox -e env1,env2,env3 This would save having to write a separate entry under a
hatch run script1; hatch run script2 |
@OCopping interestingly enough, this use case would also be covered by a Assuming your [tool.uv.tasks]
default = "uvx --from=rust-just just"
lint = "uvx --from=rust-just just lint"
test = "uvx --from=rust-just test" you could then do: uv task test lint # internally, this would run: uvx -from=rust-just just test lint |
@mattmess1221 wrote:
This is great. I prefer to persist per-group environments, similar to Hatch. This can be achieved with a minor tweak: #!/usr/bin/env -S UV_PROJECT_ENVIRONMENT=.venv-test uv run --group=test bash |
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: