From 35c77562edaa3afbba27505c7f792903bce0c5f2 Mon Sep 17 00:00:00 2001 From: parazyd Date: Thu, 28 Apr 2022 20:18:22 +0200 Subject: [PATCH] contrib: Add script to sync all toml package versions to the root lib. --- contrib/update_pkg_versions.py | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 contrib/update_pkg_versions.py diff --git a/contrib/update_pkg_versions.py b/contrib/update_pkg_versions.py new file mode 100755 index 000000000..a8529f45b --- /dev/null +++ b/contrib/update_pkg_versions.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +import subprocess + +from os import chdir +from subprocess import PIPE + +import tomlkit + + +def update_package_version(filename, version): + with open(filename) as f: + content = f.read() + + p = tomlkit.parse(content) + p["package"]["version"] = version + + with open(filename, "w") as f: + f.write(tomlkit.dumps(p)) + + +def main(): + toplevel = subprocess.run(["git", "rev-parse", "--show-toplevel"], + capture_output=True) + toplevel = toplevel.stdout.decode().strip() + chdir(toplevel) + + with open("Cargo.toml") as f: + content = f.read() + + p = tomlkit.parse(content) + version = p["package"]["version"] + + find_output = subprocess.run( + ["find", ".", "-type", "f", "-name", "Cargo.toml"], stdout=PIPE) + files = [i.strip() for i in find_output.stdout.decode().split("\n")][:-1] + + for filename in files: + update_package_version(filename, version) + + +if __name__ == "__main__": + main()