Debian Codegraph @

update_dev_dependencies

raw
1 #!/usr/bin/env bash
2 #
3 # Copyright 2009-2026 Joshua Bronson. All rights reserved.
4 #
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
9 set -euo pipefail
10
11 log() {
12 >&2 printf "> %s\n" "$@"
13 }
14
15
16 # prek auto-update moves the ruff pin in .pre-commit-config.yaml but knows nothing about
17 # pyproject.toml's required-version, which exists to reject a local ruff older than that pin.
18 # Left to drift, the floor keeps passing versions that lint with fewer rules than CI uses.
19 check_ruff_required_version() {
20 local pinned required
21 pinned=$(grep -A1 'astral-sh/ruff-pre-commit' .pre-commit-config.yaml | sed -n 's/^ *rev: v//p')
22 required=$(sed -n 's/^required-version = ">=\(.*\)"$/\1/p' pyproject.toml)
23 if [[ -z $pinned || -z $required ]]; then
24 log "Warning: could not compare ruff's pinned version to pyproject.toml's required-version."
25 log " Check by hand that they agree, and fix this check if its parsing has gone stale."
26 return
27 fi
28 if [[ $pinned != "$required" ]]; then
29 log "Action needed: ruff is pinned to v$pinned, but required-version says >=$required."
30 log " Set required-version = \">=$pinned\" in pyproject.toml, so that a ruff"
31 log " older than the pinned one fails instead of linting with fewer rules."
32 log
33 fi
34 }
35
36
37 # Zero-pad a version into a fixed-width string, so that two of them compare correctly with the
38 # lexicographic [[ < ]], which is available everywhere `sort -V` is not (e.g. BSD/macOS sort).
39 version_key() {
40 local major minor patch
41 IFS=. read -r major minor patch <<<"$1"
42 printf '%05d%05d%05d' "${major:-0}" "${minor:-0}" "${patch:-0}"
43 }
44
45
46 # The wheel's RECORD is written by uv_build, whose version comes from pyproject.toml's
47 # [build-system] requires -- not from the uv on PATH, and not from uv.lock. Nothing else here
48 # touches that pin, and left to drift it is what shipped 0.24.0 with hex RECORD hashes (#406).
49 # The pin's floor guards correctness on its own; what needs watching is its ceiling, which
50 # should keep covering the uv in uv.lock, so that building a release goes on using that uv's
51 # built-in uv_build rather than quietly downloading a different version to build with.
52 check_uv_build_pin() {
53 local locked floor ceiling
54 locked=$(sed -n '/^name = "uv"$/{n;s/^version = "\(.*\)"$/\1/p;}' uv.lock)
55 floor=$(sed -n 's/^requires = \["uv_build>=\([^,"]*\),.*$/\1/p' pyproject.toml)
56 ceiling=$(sed -n 's/^requires = \["uv_build>=[^,]*,<\([^"]*\)"\].*$/\1/p' pyproject.toml)
57 if [[ -z $locked || -z $floor || -z $ceiling ]]; then
58 log "Warning: could not compare uv.lock's uv version to pyproject.toml's uv_build pin."
59 log " Check by hand that they agree, and fix this check if its parsing has gone stale."
60 return
61 fi
62 if [[ ! $(version_key "$locked") < $(version_key "$ceiling") ]]; then
63 log "Action needed: uv.lock has uv $locked, past uv_build>=$floor,<$ceiling's ceiling."
64 log " Raise that ceiling in pyproject.toml to cover $locked, so that building a"
65 log " release keeps using uv's own uv_build instead of downloading another."
66 log " Leave the floor alone: it is what keeps #406 from recurring."
67 log
68 elif [[ $(version_key "$locked") < $(version_key "$floor") ]]; then
69 log "Action needed: uv.lock has uv $locked, below uv_build>=$floor,<$ceiling's floor, so a"
70 log " release would be built by a downloaded uv_build rather than this uv's own."
71 log " Upgrade uv rather than lowering the floor, which guards against #406."
72 log
73 fi
74 }
75
76
77 main() {
78 declare -r hint="Hint: Use 'nix develop' to bootstrap a development environment"
79
80 for cmd in uv prek; do
81 if ! command -v "$cmd" >/dev/null 2>&1; then
82 log "Error: No '$cmd' on PATH. $hint"
83 exit 1
84 fi
85 done
86
87 log "Upgrading PyPI dependencies..."
88 uv lock --upgrade && uv sync
89 log "Upgrading PyPI dependencies: Done"
90 log
91 log "Upgrading pre-commit hooks..."
92 prek auto-update
93 log "Upgrading pre-commit hooks: Done"
94 log
95 check_ruff_required_version
96 check_uv_build_pin
97 log "Reminders:"
98 log " - Check release notes of upgraded packages for anything that affects bidict."
99 log " - Ensure tests pass for all supported Python versions."
100 log " - Check output for any new warnings, not just test failures."
101 log " - Ensure 'prek run --all-files' still succeeds."
102 }
103
104 main