Skip to content

Instantly share code, notes, and snippets.

@DonDebonair
Created May 25, 2022 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DonDebonair/ff9b63b8b3329ba09e2b0aec31fc2b58 to your computer and use it in GitHub Desktop.
Save DonDebonair/ff9b63b8b3329ba09e2b0aec31fc2b58 to your computer and use it in GitHub Desktop.
Show available package updates for Poetry projects
#!/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