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

Add --dry-run flag for pip install #1244

Closed
zanieb opened this issue Feb 3, 2024 · 1 comment · Fixed by #1436
Closed

Add --dry-run flag for pip install #1244

zanieb opened this issue Feb 3, 2024 · 1 comment · Fixed by #1436
Labels
compatibility Compatibility with a specification or another tool

Comments

@zanieb
Copy link
Member

zanieb commented Feb 3, 2024

For parity with pip but also useful.

Basically this let's you pip compile without creating requirements file. The install plan is displayed to the user, e.g.

❯ pip install flask --dry-run
Collecting flask
  Using cached flask-3.0.1-py3-none-any.whl (101 kB)
Requirement already satisfied: Werkzeug>=3.0.0 in /Users/mz/.pyenv/versions/3.11.4/lib/python3.11/site-packages (from flask) (3.0.1)
Requirement already satisfied: Jinja2>=3.1.2 in /Users/mz/.pyenv/versions/3.11.4/lib/python3.11/site-packages (from flask) (3.1.2)
Requirement already satisfied: itsdangerous>=2.1.2 in /Users/mz/.pyenv/versions/3.11.4/lib/python3.11/site-packages (from flask) (2.1.2)
Requirement already satisfied: click>=8.1.3 in /Users/mz/.pyenv/versions/3.11.4/lib/python3.11/site-packages (from flask) (8.1.7)
Requirement already satisfied: blinker>=1.6.2 in /Users/mz/.pyenv/versions/3.11.4/lib/python3.11/site-packages (from flask) (1.7.0)
Requirement already satisfied: MarkupSafe>=2.0 in /Users/mz/.pyenv/versions/3.11.4/lib/python3.11/site-packages (from Jinja2>=3.1.2->flask) (2.1.3)
Would install Flask-3.0.1
@zanieb zanieb added the compatibility Compatibility with a specification or another tool label Feb 3, 2024
@JacobCoffee
Copy link
Contributor

JacobCoffee commented Feb 16, 2024

May I try this? @zanieb
I have a basic thing done:

uv on  1431 [📝🤷✓] via 🐋 colima via 🎁 v0.1.1 via  pyenv via ⚙️ v1.75.0
➜ ./target/debug/uv pip install flask --dry-run
Resolved 7 packages in 1.15s
Would have installed:
  jinja2
  itsdangerous
  blinker
  markupsafe
  flask
  werkzeug
  click

Although I'm not yet sure how to pull versions to display..

zanieb added a commit that referenced this issue Mar 12, 2024
## What

Adds a `--dry-run` flag that ejects out of the installation process
early (but after resolution) and displays only what *would have*
installed

## Closes

Closes #1244 

## Out of Scope

I think it may be nice to include a `dry-run` flag for `uninstall` even
though `pip` doesn't implement this... thinking `Would uninstall X
packages: ...`

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
charliermarsh added a commit that referenced this issue Dec 2, 2024
## 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 <charlie.r.marsh@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility Compatibility with a specification or another tool
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants