Sfoglia il codice sorgente

contrib: Add script to sync all toml package versions to the root lib.

parazyd 4 anni fa
parent
commit
35c77562ed
1 ha cambiato i file con 42 aggiunte e 0 eliminazioni
  1. 42 0
      contrib/update_pkg_versions.py

+ 42 - 0
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()