Last active
July 17, 2018 14:57
-
-
Save jcmgray/2c91ea6aa1f6e27114e52ca332dd4e79 to your computer and use it in GitHub Desktop.
Find the set of python packages, not managed by conda, which are out of date according to pip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import subprocess | |
# find the names of packages conda says are managed by pip | |
conda_raw = subprocess.run(['conda', 'list'], stdout=subprocess.PIPE).stdout.decode('utf-8') | |
pip_only_pkgs = {ln.split(' ')[0] for ln in conda_raw.split('\n') if '<pip>' in ln} | |
# find the names of packages pip says are outdated (assumes column pip output) | |
pip_raw = subprocess.run(['pip', 'list', '--outdated'], stdout=subprocess.PIPE).stdout.decode('utf-8') | |
pip_outdated_pkgs = {ln.split(' ')[0] for ln in pip_raw.split('\n')[2:-1]} | |
# find the intersection | |
outdated_pip_only_packages = pip_only_pkgs & pip_outdated_pkgs | |
if outdated_pip_only_packages: | |
print("Outdated pip-only packages:", outdated_pip_only_packages) | |
else: | |
print("All pip-only packages are up-to-date!") | |
# OPTIONALLY: update all those packages | |
# for pkg in outdated_pip_only_packages: | |
# subprocess.run('pip', 'install', '-U', pkg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment