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

Implement uv run --directory #5566

Merged
merged 3 commits into from
Jul 29, 2024
Merged

Implement uv run --directory #5566

merged 3 commits into from
Jul 29, 2024

Conversation

bluss
Copy link
Contributor

@bluss bluss commented Jul 29, 2024

Summary

uv run --directory means that one doesn't have to change to a
project's directory to run programs from it. It makes it possible to use
projects as if they are tool installations.

To support this, first the code reading .python-version was updated so that
it can read such markers outside the current directory. Note the minor
change this causes (if I'm right), described in the commit.

Test Plan

One test has been added.

--directory

Not sure what the name of the argument should be, but it's following uv
sync's directory for now.

Other alternatives could be "--project". Uv run and uv tool run should
probably find common agreement on this (relevant for project-locked tools).

I've implemented this same change in Rye, some time ago, and then we went
with --pyproject <path to pyproject.toml file>. I think using
pyproject.toml file path and not directory was probably a mistake, an
overgeneralization one doesn't need.

Preparing for supporting this in uv run, update the .python-version
reading functions so that they can read from more than just the current
directory.

Minor behaviour change(!). In some cases previously it could
end up with different python versions depending on from which directory
inside a wider workspace an operation was called from (if there were
different .python-version files). I think this is clear from
get_or_init_environment's use of discover.
Allow running scripts and binaries from a project without changing
directory to that project.

Allow running scripts or binaries in a project without having to change
directory into the project using uv run.
@bluss
Copy link
Contributor Author

bluss commented Jul 29, 2024

A test had to be fixed for windows but is now done.

Edit - oh, needs preview label probably.

@charliermarsh charliermarsh added enhancement New feature or request preview Experimental behavior labels Jul 29, 2024
@charliermarsh charliermarsh changed the title Implement uv run --directory Implement uv run --directory Jul 29, 2024
@charliermarsh charliermarsh merged commit e46c24d into astral-sh:main Jul 29, 2024
56 of 57 checks passed
@bluss bluss deleted the run branch July 29, 2024 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request preview Experimental behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants