gnome.updateScript: More Python

This was prompted by the need to capture exit status of `find-latest-version.py` in the next commit.
I had to drop `errexit` (if I did not want to result to even worse hacks) but that concealed errors like the following,
when I accidentally used an incorrect equals operator in numeric comparison:

line 24: ((: 1 = 1 : attempted assignment to non-variable (error token is "= 1 ")

Converting the plumbing in `gnome/update.nix` to Python also makes it slightly easier to read.

For now, `find-latest-version.py` is still invoked as a separate process (rather than being imported as a Python module),
as `update.nix` might be replaced by `genericUpdater` in the future.

+46 -16
+46 -16
pkgs/desktops/gnome/update.nix
··· 1 - { stdenv, bash, pkgs, lib, writeScript, python3, common-updater-scripts }: 1 + { stdenv, pkgs, lib, writeScript, python3, common-updater-scripts }: 2 2 { packageName, attrPath ? packageName, versionPolicy ? "tagged", freeze ? false }: 3 3 4 4 let ··· 20 20 else 21 21 throw "“freeze” argument needs to be either a boolean, or a version string."; 22 22 updateScript = writeScript "gnome-update-script" '' 23 - #!${bash}/bin/bash 24 - set -o errexit 25 - attr_path="$1" 26 - package_name="$2" 27 - package_version="$3" 28 - version_policy="$4" 23 + #!${python}/bin/python 24 + import json 25 + import os 26 + import subprocess 27 + import sys 29 28 30 - flvFlags=("$package_name" "$version_policy" "''${GNOME_UPDATE_STABILITY:-stable}") 29 + _, attr_path, package_name, package_version, version_policy, *remaining_args = sys.argv 31 30 32 - if (( $# >= 5 )); then 33 - upper_bound="$5" 34 - flvFlags+=("--upper-bound=$upper_bound") 35 - fi 31 + flv_args = [ 32 + package_name, 33 + version_policy, 34 + os.environ.get("GNOME_UPDATE_STABILITY", "stable"), 35 + ] 36 36 37 - PATH=${lib.makeBinPath [ common-updater-scripts python ]} 38 - latest_tag=$(python "${./find-latest-version.py}" "''${flvFlags[@]}") 39 - update-source-version "$attr_path" "$latest_tag" 40 - echo '[ { "commitBody": "https://gitlab.gnome.org/GNOME/'$package_name'/-/compare/'$package_version'...'$latest_tag'" } ]' 37 + match remaining_args: 38 + case []: 39 + pass 40 + case [upper_bound]: 41 + flv_args.append(f"--upper-bound={upper_bound}") 42 + case other: 43 + print("gnome-update-script: Received too many arguments.", file=sys.stderr) 44 + sys.exit(1) 45 + 46 + latest_tag = subprocess.check_output( 47 + [ 48 + "${python}/bin/python", 49 + "${./find-latest-version.py}", 50 + *flv_args, 51 + ], 52 + encoding="utf-8", 53 + ) 54 + latest_tag = latest_tag.strip() 55 + subprocess.run( 56 + [ 57 + "${common-updater-scripts}/bin/update-source-version", 58 + attr_path, 59 + latest_tag, 60 + ], 61 + check=True, 62 + ) 63 + 64 + report = [ 65 + { 66 + "commitBody": f"https://gitlab.gnome.org/GNOME/{package_name}/-/compare/{package_version}...{latest_tag}", 67 + }, 68 + ] 69 + 70 + print(json.dumps(report)) 41 71 ''; 42 72 in { 43 73 name = "gnome-update-script";