check_package_version.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Copyright 2021-2024 Avaiga Private Limited
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  4. # the License. You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  9. # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  10. # specific language governing permissions and limitations under the License.
  11. # --------------------------------------------------------------------------------------------------
  12. # Checks that the version declared in <package_dir>/version.json matches a given version.
  13. # --------------------------------------------------------------------------------------------------
  14. import json
  15. import os
  16. import sys
  17. from common import Package, Version
  18. def usage() -> None:
  19. print(f"Usage: {sys.argv[0]} <package> <version>") # noqa: T201
  20. print(" Checks that the version defined in the <package>'s version.json file is <version>.") # noqa: T201
  21. if __name__ == "__main__":
  22. if len(sys.argv) < 3:
  23. usage()
  24. raise ValueError("Missing arguments.")
  25. package = Package(sys.argv[1])
  26. version = Version.from_string(sys.argv[2])
  27. # Check that build version matches package's version.json
  28. with open(os.path.join(package.package_dir, "version.json")) as version_file:
  29. package_version = Version(**json.load(version_file))
  30. if version != package_version:
  31. raise ValueError(
  32. f"Version mismatch for package {package}: "
  33. + f"building '{version}' but '{package_version}' is defined in 'version.json'."
  34. )
  35. # Check Taipy GUI and Taipy packages bundle versions
  36. package_json_path = None
  37. if package.name == "taipy":
  38. package_json_path = "frontend/taipy/package.json"
  39. elif package.short_name == "gui":
  40. package_json_path = "frontend/taipy-gui/package.json"
  41. if package_json_path:
  42. with open(package_json_path) as package_file:
  43. package_config = json.load(package_file)
  44. package_version = Version.from_string(package_config["version"])
  45. if version != package_version:
  46. raise ValueError(
  47. f"Version mismatch for frontend of package {package}: "
  48. + f"building '{version}' but '{package_version}' is defined in '{package_json_path}'."
  49. )