update_pkg_versions.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env python3
  2. # Update the version in the toplevel Cargo.toml for DarkFi, and then run this
  3. # script to update all the other Cargo.toml files.
  4. import subprocess
  5. from os import chdir
  6. from subprocess import PIPE
  7. import tomlkit
  8. def update_package_version(filename, version):
  9. with open(filename) as f:
  10. content = f.read()
  11. p = tomlkit.parse(content)
  12. p["package"]["version"] = version
  13. with open(filename, "w") as f:
  14. f.write(tomlkit.dumps(p))
  15. def main():
  16. toplevel = subprocess.run(["git", "rev-parse", "--show-toplevel"],
  17. capture_output=True)
  18. toplevel = toplevel.stdout.decode().strip()
  19. chdir(toplevel)
  20. with open("Cargo.toml") as f:
  21. content = f.read()
  22. p = tomlkit.parse(content)
  23. version = p["package"]["version"]
  24. find_output = subprocess.run(
  25. ["find", ".", "-type", "f", "-name", "Cargo.toml"], stdout=PIPE)
  26. files = [i.strip() for i in find_output.stdout.decode().split("\n")][:-1]
  27. for filename in files:
  28. update_package_version(filename, version)
  29. if __name__ == "__main__":
  30. main()