Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make pip "dry-run"?

Tags:

python

pip

For developing a script that runs pip install it would be usefull to have a --dry-run function.

I came across the --no-install option. But this one is deprecated and on call references this. There are hints to unpack a package only, but I can't find a unpack option in the pip documentation.

like image 841
user2546460 Avatar asked Apr 09 '15 06:04

user2546460


People also ask

What is pip compile?

The pip-compile command lets you compile a requirements. txt file from your dependencies, specified in either setup.py or requirements.in. Run it with pip-compile or python -m piptools compile. If you use multiple Python versions, you can also run py -X.Y -m piptools compile on Windows and pythonX.

What is run pip?

It stands for “preferred installer program” or “Pip Installs Packages.” PIP for Python is a utility to manage PyPI package installations from the command line. If you are using an older version of Python on Windows, you may need to install PIP.

How do I search for pip packages?

pip search Looking for a package, pip is there to help you out. pip search allows you to search PyPI for any package using the pip search <package> command. The result of the command returns the name and description of all the matching packages.


2 Answers

Yes - pip should have a dry-run option, to indicate what would happen in a complex situation. It is dangerous when running pip install downgrades packages without asking you. We need some way to ask what would happen if we run pip install -r requirements.txt without laboriously searching thru all the requirements and comparing them to the currently installed ones.

It looks like setup.py used to have a dry-run. Folks are asking for it elsewhere.

Some progress in that direction can be found here:

  • Dry Run for Python Pip | BackSlasher
  • nvie/pip-tools: A set of tools to keep your pinned Python dependencies fresh.

Update: Activity continues on the official bug related to this: Add `pip install --dry-run` or similar, to get resolution result · Issue #53 · pypa/pip. It is blocked on the development of the dependency resolver, which is nearing completion

like image 90
nealmcb Avatar answered Sep 22 '22 03:09

nealmcb


It appears you are right, it has been deprecated (ref).

If by trial run you mean testing it out before actually installing a package in a certain place, presumably before a system wide install, then you can simply run it sandboxed using a virtual environment and then simply discard the environment.

virtualenv /tmp/venv; /tmp/venv/bin/pip install flask; rm -rf /tmp/venv  

Not as succinct as using a dry-run argument to pip, but it does the job. Also if you want to do a dry run of a series of package installations, omit the deletion at the end.

In a script you can distil it into a procedure:

#!/bin/bash  TMP_DIR='/tmp/venv'  function dry_run (){     if [ ! -d "$TMP_DIR" ]; then             virtualenv /tmp/venv     fi     /tmp/venv/bin/pip install $1 }  dry_run flask dry_run uwsgi rm -rf $TMP_DIR 

If you want to do a dry run that tests that the new install(s) play well with system wide deployed, then use virtualenv's system-site-packages option.

virtualenv --system-site-packages /tmp/venv; /tmp/venv/bin/pip install flask; rm -rf /tmp/venv 
like image 30
Angelos Avatar answered Sep 24 '22 03:09

Angelos