Pip-Outdated.py with interactive upgrade

Created on November 12, 2023 at 11:29 am

URL: https://gist.github.com/peterbe/a2b158c39f1f835c0977c82befd94cdf PERSON

Last year DATE I wrote a nifty script called Pip-Outdated.py "Pip-Outdated.py – a script to compare requirements.in ORG with the output of pip list –outdated". It basically runs pip list –outdated but filters based on the packages mentioned in your requirements.in PERSON . For people familiar with Node ORG , it’s like checking all installed packages in node_modules if they have upgrades, but filter it down by only those mentioned in your package.json .

I use this script often enough that I added a little interactive input to ask if it should edit requirements.in ORG for you for each possible upgrade. Looks like this:

❯ Pip-Outdated.py black INSTALLED: 23.7.0 POSSIBLE: 23.9.1 CARDINAL click INSTALLED: 8.1.6 CARDINAL POSSIBLE: 8.1.7 CARDINAL elasticsearch-dsl INSTALLED: 7.4.1 CARDINAL POSSIBLE: 8.9.0 fastapi PERSON INSTALLED: 0.101.0 CARDINAL POSSIBLE: 0.103.1 CARDINAL httpx INSTALLED: 0.24.1 CARDINAL POSSIBLE: 0.25.0 CARDINAL pytest INSTALLED: 7.4.0 CARDINAL POSSIBLE: 7.4.2 CARDINAL Update black from 23.7.0 to 23.9.1 CARDINAL ? [y/N/q] y Update click from 8.1.6 CARDINAL to 8.1.7? [y/N/q] y Update elasticsearch-dsl from 7.4.1 CARDINAL to 8.9.0? [y/N/q] n Update fastapi from 0.101.0 ORG to 0.103.1? [y/N/q] n Update httpx GPE from 0.24.1 CARDINAL to 0.25.0? [y/N/q] n Update pytest from 7.4.0 to CARDINAL

7.4.2 CARDINAL ? [y/N/q] y

and then,

❯ git diff requirements.in PERSON | cat diff –git a/requirements.in b/ requirements.in ORG index b7a246e.. 0e996e5 100644 CARDINAL — a/requirements.in +++ b/ requirements.in @@ -9,7 PERSON

+9,7 @@ PERSON python-decouple==3.8 fastapi==0.101.0 uvicorn[standard]==0.23.2 selectolax==0.3.16 -click==8.1.6 +click==8.1.7 python-dateutil==2.8.2 gunicorn==21.2.0 @@ -18,7 +18,7 @@ requests==2.31.0 cachetools==5.3.1 -black==23.7.0 +black==23.9.1 flake8==6.1.0 -pytest==7.4.0 +pytest==7.4.2 httpx==0.24.1

That’s it. Then if you want to actually make these upgrades you run:

❯ pip-compile –generate-hashes requirements.in && pip ORG install -r requirements.txt

Connecting to blog.lzomedia.com... Connected... Page load complete