-
-
Save yhoiseth/c80c1e44a7036307e424fce616eed25e to your computer and use it in GitHub Desktop.
#!/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() |
Great!!
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
Thank you @gbaian10, your script worked perfectly for me.
Perhaps you can consider adding the requirements at the top to make it possible to run without a venv with uv:
#! /usr/bin/env -S uv run --script
#
# Source:
# https://gist.github.com/yhoiseth/c80c1e44a7036307e424fce616eed25e?permalink_comment_id=5387642#gistcomment-5387642
#
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "typer>=0.15.3",
# "tomlkit>=0.13.2",
# ]
# ///
Thank you @gbaian10, your script worked perfectly for me.
Perhaps you can consider adding the requirements at the top to make it possible to run without a venv with uv:
#! /usr/bin/env -S uv run --script # # Source: # https://gist.github.com/yhoiseth/c80c1e44a7036307e424fce616eed25e?permalink_comment_id=5387642#gistcomment-5387642 # # /// script # requires-python = ">=3.12" # dependencies = [ # "typer>=0.15.3", # "tomlkit>=0.13.2", # ] # ///
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.
I wrote a command-line program using
typer
.It can update the version in
pyproject.toml
while preserving the original order.