patch_toml_versions.py 875 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import os
  2. import pathlib
  3. import sys
  4. import tomlkit
  5. if len(sys.argv) < 3:
  6. print("Specify toml file and version to patch")
  7. sys.exit(1)
  8. current_dir = pathlib.Path(os.getcwd())
  9. toml_path = current_dir.joinpath(current_dir, sys.argv[1])
  10. ver = sys.argv[2]
  11. print(f"Patching TOML file {toml_path} to {ver}")
  12. # read
  13. with open(toml_path, "r") as f:
  14. t = tomlkit.parse(f.read())
  15. # patch version
  16. t["tool"]["poetry"]["version"] = ver
  17. # patch dependencies
  18. deps = t["tool"]["poetry"]["dependencies"]
  19. def patch_dep(dep_name):
  20. if deps.get(dep_name):
  21. if isinstance(deps[dep_name], dict):
  22. deps[dep_name]["version"] = ver
  23. else:
  24. deps[dep_name] = ver
  25. patch_dep("flet-core")
  26. patch_dep("flet-cli")
  27. patch_dep("flet-desktop")
  28. patch_dep("flet-web")
  29. patch_dep("flet")
  30. # save
  31. with open(toml_path, "w") as f:
  32. f.write(tomlkit.dumps(t))