patch_pubspec.py 719 B

1234567891011121314151617181920212223242526272829303132
  1. import os
  2. import pathlib
  3. import sys
  4. import yaml
  5. if len(sys.argv) < 3:
  6. print("Specify pubspec.yaml file and version to patch")
  7. sys.exit(1)
  8. current_dir = pathlib.Path(os.getcwd())
  9. pubspec_path = current_dir.joinpath(current_dir, sys.argv[1])
  10. ver = sys.argv[2]
  11. print(f"Patching pubspec.yaml file {pubspec_path} with {ver}")
  12. dependencies = [
  13. "flet",
  14. ]
  15. with open(pubspec_path, "r") as f:
  16. data = yaml.safe_load(f)
  17. # patch version
  18. data["version"] = ver
  19. # patch dependencies
  20. for dep in data["dependencies"]:
  21. if dep in dependencies:
  22. data["dependencies"][dep] = f"^{ver}"
  23. # print(dep)
  24. with open(pubspec_path, "w") as file:
  25. yaml.dump(data, file, sort_keys=False)