Last active
May 11, 2025 18:26
-
-
Save yhoiseth/c80c1e44a7036307e424fce616eed25e to your computer and use it in GitHub Desktop.
Upgrade all dependencies to their latest version using uv
This file contains hidden or 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 | |
# 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks. I think this script is still quite rough — it mostly just handles cases where your package uses >= or ==.
Later, I realized it doesn't account for situations without any symbol (with use
[tool.uv.sources]
), and maybe such cases should also be skipped.