Skip to content

Instantly share code, notes, and snippets.

@yhoiseth
Last active April 23, 2025 13:50
Show Gist options
  • Save yhoiseth/c80c1e44a7036307e424fce616eed25e to your computer and use it in GitHub Desktop.
Save yhoiseth/c80c1e44a7036307e424fce616eed25e to your computer and use it in GitHub Desktop.
Upgrade all dependencies to their latest version using uv
#!/usr/bin/env python
# https://gist.github.com/yhoiseth/c80c1e44a7036307e424fce616eed25e
from typing import Any
from re import match, Match
import toml
import subprocess
def main() -> None:
with open("pyproject.toml", "r") as file:
pyproject: dict[str, Any] = toml.load(file)
dependencies: list[str] = pyproject["project"]["dependencies"]
package_name_pattern = r"^[a-zA-Z0-9\-]+"
for dependency in dependencies:
package_match = match(package_name_pattern, dependency)
assert isinstance(package_match, Match)
package = package_match.group(0)
uv("remove", package)
uv("add", package)
def uv(command: str, package: str) -> None:
subprocess.run(["uv", command, package])
if __name__ == "__main__":
main()
@rosmur
Copy link

rosmur commented Jan 21, 2025

Great!!

@eirnym
Copy link

eirnym commented Apr 23, 2025

After trying these and similar commands, I've returned to Renovate Bot to upgrade my packages. Bot does it in more configurable way, even if I run it locally

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment