Created
May 25, 2022 20:01
-
-
Save DonDebonair/ff9b63b8b3329ba09e2b0aec31fc2b58 to your computer and use it in GitHub Desktop.
Show available package updates for Poetry projects
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 | |
from typing import cast, Dict | |
import toml | |
import subprocess | |
def update_deps(name: str, version: str, t: Dict) -> Dict: | |
def update(deps: Dict) -> None: | |
for key in deps: | |
v = deps[key] | |
if type(v) is str and name.lower() == key.lower() and v[0] in ("~", "^"): | |
deps[key] = f"{v[0]}{version}" | |
update(t['tool']['poetry']['dependencies']) | |
update(t['tool']['poetry']['dev-dependencies']) | |
return t | |
with open('./pyproject.toml', 'r') as f: | |
t = cast(Dict, toml.loads(f.read())) | |
output = subprocess.run(["poetry", "show"], capture_output=True) | |
lines = cast(str, output.stdout.decode()).split('\n') | |
for line in filter(lambda l: bool(l), lines): | |
name, version, *_ = line.split() | |
t = update_deps(name, version, t) | |
print(toml.dumps(t)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment