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

uv: move all uv commands to uv.rs #869

Merged
merged 14 commits into from
Mar 19, 2024
Merged

uv: move all uv commands to uv.rs #869

merged 14 commits into from
Mar 19, 2024

Conversation

dsp
Copy link
Contributor

@dsp dsp commented Mar 11, 2024

The pull requests moves all invocations of uv to src/uv.rs. The invokations are now structured into three main structures:

  • UvBuilder, which can be used to create a new instance of a uv binary that ensures uv exists on disk.
  • Uv, which provides operations using uv outside of the virtual environment, for example creating a venv, compiling lockfiles ,etc.
  • UvWithVenv, which must be obtained using Uv::venv() to guarantee a venv is available, which encapsulates operations on the venv.

This opens the door to implement the same patterns for pip-tools and intorduce a trait to use dynamic dispatching instead of the existing if/else structure. If we continue down this path, we can hopefully in the future just do:

// Create either PipTools or Uv instance, returns `Box<PipLikeTool>`
PipBuilder::use_uv(Config::use_uv())
   .build()
   .with_output(output)
   .venv(...);

Important Note:

Note that the changes are not 100% equivalent to the previous code. Most notable, in order to operate on a venv, all codepaths must go through Uv::venv, which will always check if the existing venv is compatbile. This is a safer, but more expensive path (since we at least always read the marker). If we are worried about this, we can introduce an assume_venv which will return UvWithVenv without checks.

dsp added 14 commits March 11, 2024 14:52
We are creating an empty ExpandedSources, as we will use them later to
implement a default struct of Uv.
We are marking ensure_exists deprecated. In the follow up commits we will
introduce UvBuilder as an alternative way to construct a Uv struct. We
will then replace uses of `Uv::ensure_exists` in the codebase with `UvBuilder`,
before finally removing `ensure_exists`.
We are using a builder pattern now to create an instance of Uv. The
builder pattern will allow us to create an instance of `Uv` with sources,
working directory and an command output mode set already.
In some instances we want to re-use the uv object when we have a venv. In that
case, we need to have the ability to reset the command output mode.
@mitsuhiko
Copy link
Collaborator

I really like this. Something similar for toolchains is pending in #839. Definitely feels like a good direction.

@mitsuhiko mitsuhiko merged commit 913e8a6 into astral-sh:main Mar 19, 2024
8 checks passed
@dsp dsp deleted the uvbuilder branch March 19, 2024 12:18
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

Successfully merging this pull request may close these issues.

2 participants