Created
December 22, 2022 14:30
-
-
Save peterbe/099ad364657b70a04b1d65aa29087df7 to your computer and use it in GitHub Desktop.
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 | |
def main(*args): | |
if not args: | |
requirements_in = "requirements.in" | |
else: | |
requirements_in = args[0] | |
required = {} | |
with open(requirements_in) as f: | |
for line in f: | |
if "==" in line: | |
package, version = line.strip().split("==") | |
package = package.split("[")[0] | |
required[package] = version | |
res = subprocess.run(["pip", "list", "--outdated"], capture_output=True) | |
if res.returncode: | |
raise Exception(res.stderr) | |
lines = res.stdout.decode("utf-8").splitlines() | |
relevant = [line for line in lines if line.split()[0] in required] | |
longest_package_name = max([len(x.split()[0]) for x in relevant]) if relevant else 0 | |
for line in relevant: | |
p, installed, possible, *_ = line.split() | |
if p in required: | |
print( | |
p.ljust(longest_package_name + 2), | |
"INSTALLED:", | |
installed.ljust(9), | |
"POSSIBLE:", | |
possible, | |
) | |
if __name__ == "__main__": | |
import sys | |
sys.exit(main(*sys.argv[1:])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment