Last active
July 13, 2020 20:18
-
-
Save nanonyme/6f05ea914122ac785d8ac93c678e5b9c to your computer and use it in GitHub Desktop.
Update obsolete installed packages
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 python3 | |
import json | |
import subprocess | |
import sys | |
def grab_packages(): | |
process = subprocess.run([sys.executable, "-mpip", "list", "-o", | |
"--format=json"] + sys.argv[1:], | |
capture_output=True) | |
return [package["name"] for package in json.loads(process.stdout)] | |
def update_packages(packages): | |
if not packages: | |
print ("Everything is up to date") | |
else: | |
subprocess.run([sys.executable, "-mpip", "install", "--upgrade"] + | |
sys.argv[1:] + packages) | |
if __name__ == "__main__": | |
# Invoke with --user to update user packages | |
update_packages(grab_packages()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment