/ dotscripts / pip-update.py
pip-update.py
 1  #!/usr/bin/env python
 2  
 3  # Starting point for this script:
 4  # http://stackoverflow.com/a/5839291
 5  
 6  import os
 7  import pip
 8  import subprocess
 9  
10  homedir = os.getenv('HOME')
11  homepkg = []
12  
13  for dist in pip.get_installed_distributions():
14    if not dist.location.startswith(homedir):
15      continue
16    homepkg.append(dist.project_name)
17  
18  if len(homepkg) == 0:
19    print('No locally-installed packages, nothing to update.')
20    raise SystemExit
21  
22  # --no-deps is required because --upgrade by default is recursive and would try
23  # to update packages that are not from homedir (e.g. from /usr). 
24  
25  subprocess.call(['pip', 'install', '--user', '--upgrade', '--no-deps'] + homepkg)