Skip to content

Instantly share code, notes, and snippets.

@janhicken
Created January 21, 2025 10:26
Show Gist options
  • Save janhicken/2d0e8c17af2330c6b8812cfaa6789ba9 to your computer and use it in GitHub Desktop.
Save janhicken/2d0e8c17af2330c6b8812cfaa6789ba9 to your computer and use it in GitHub Desktop.
Update Python packages managed by uv one package at a time creating atomic commits
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
search_updates() {
if [[ $# -gt 0 ]]; then
for arg in "$@"; do
uv lock --dry-run --upgrade-package "$arg"
done
else
uv lock --dry-run --upgrade
fi
}
mapfile -t update_directives < <(search_updates "$@" |& grep '^Update')
num_updates="${#update_directives[@]}"
case "$num_updates" in
0)
printf 'Nothing to do.\n' >&2
exit
;;
1)
printf 'Found update:\t%s\n' "${update_directives[0]}" >&2
;;
*)
printf 'Found %s update(s):\n' "$num_updates" >&2
printf '\t%s\n' "${update_directives[@]}" >&2
;;
esac
printf '\n'
for directive in "${update_directives[@]}"; do
read -r _ package _ <<< "$directive"
printf '%s\n' "$directive"
uv lock --quiet --upgrade-package "$package"
if ! git diff --quiet uv.lock; then
git commit --message="$directive" uv.lock
fi
done
uv sync
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment