Add --dry-run flag to uv pip install#1436
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
|
Sorry if this is a bad way to get the version? It felt bad, anyway... |
|
Might be cool to have a |
|
On the failing CI, I had some failures do to order in stdout there... but I'm wondering how we keep it consistent? |
|
Hey @JacobCoffee, thanks for the pull request! I think we'll actually want to implement this a bit differently e.g. by passing the dry run flag into uv/crates/uv/src/commands/pip_install.rs Line 477 in 896ab1c then we can use our existing display which will also show which versions we would remove (and has a sorting implementation for deterministic output) uv/crates/uv/src/commands/pip_install.rs Line 642 in 896ab1c We'll just need to tweak the |
This comment was marked as outdated.
This comment was marked as outdated.
|
I'll give this a try tomorrow! |
|
Hey! I got a chance to play with this today. I'm thinking we should match our normal output much more closely.
I put up a commit for you to build off of at #1890 We still need more test coverage i.e. install a dependency of a package first then dry run install what do we show? or install an old version then dry run install with |
b71ae74 to
5cd1473
Compare
|
Just for my notes, i am running into an issue where in testing it passes with 2 But removing the |
|
@JacobCoffee I'm on vacation this week but let me know when this is ready for review again |
|
sorry ive not wrapped this - i think my remaining issue is the 4 ====, but ive just had surgery so im down for a bit on my hard thinking 😅 |
|
I can give it a look! Get better :) |
|
The issue is that |
# Conflicts: # crates/uv/tests/pip_install.rs
# Conflicts: # crates/uv/src/commands/mod.rs # crates/uv/tests/pip_install.rs
|
I think this is vaguely ready for review |
| // Nothing to do. | ||
| if remote.is_empty() && local.is_empty() && reinstalls.is_empty() { | ||
| let s = if resolution.len() == 1 { "" } else { "s" }; | ||
| writeln!( | ||
| printer, | ||
| "{}", | ||
| format!( | ||
| "Audited {} in {}", | ||
| format!("{} package{}", resolution.len(), s).bold(), | ||
| elapsed(start.elapsed()) | ||
| ) | ||
| .dimmed() | ||
| )?; | ||
| writeln!(printer, "Would make no changes")?; | ||
| return Ok(()); | ||
| } |
There was a problem hiding this comment.
I believe this is redundant as it is handled before this function is called
# Conflicts: # crates/uv/src/commands/pip_install.rs
# Conflicts: # crates/uv/tests/pip_install.rs
# Conflicts: # crates/uv/tests/pip_install.rs
--dry-run flag--dry-run flag to uv pip install
## Summary This proposes adding the command line option `uv pip uninstall --dry-run ...`, complementing the existing `uv pip install --dry-run ...` added for #1244 in #1436. This option does not exist in PyPA's `pip uninstall`, if adopted it would be unique to `uv pip`. The code should be considered PoC, it is baby's first Rust. The initial motivation was while investigating moreati/ansible-uv#2 - to allow Ansible module `moreati.uv.pip` to work with`state: absent` in "check_mode" (Ansible's equivalent of a dry run), without requiring `packaging` or `setuptools`. ## Test Plan One new unit test has been added. I pedge to add more if the feature is desired/accepted Example usage ```console ➜ uv git:(pip-uninstall--dry-run) rm -rf .venv ➜ uv git:(pip-uninstall--dry-run) ./target/debug/uv venv Using CPython 3.13.0 Creating virtual environment at: .venv Activate with: source .venv/bin/activate ➜ uv git:(pip-uninstall--dry-run) ./target/debug/uv pip install httpx Resolved 7 packages in 178ms Prepared 5 packages in 60ms Installed 7 packages in 15ms + anyio==4.6.2.post1 + certifi==2024.8.30 + h11==0.14.0 + httpcore==1.0.7 + httpx==0.28.0 + idna==3.10 + sniffio==1.3.1 ➜ uv git:(pip-uninstall--dry-run) ./target/debug/uv pip uninstall --dry-run httpx Would uninstall 1 package - httpx==0.28.0 ➜ uv git:(pip-uninstall--dry-run) ./target/debug/uv pip list Package Version -------- ----------- anyio 4.6.2.post1 certifi 2024.8.30 h11 0.14.0 httpcore 1.0.7 httpx 0.28.0 idna 3.10 sniffio 1.3.1 ``` --------- Co-authored-by: Charlie Marsh <[email protected]>

What
Adds a
--dry-runflag that ejects out of the installation process early (but after resolution) and displays only what would have installedCloses
Closes #1244
Out of Scope
I think it may be nice to include a
dry-runflag foruninstalleven thoughpipdoesn't implement this... thinkingWould uninstall X packages: ...