update_setup_requirements.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. import os
  12. import sys
  13. from typing import Dict
  14. BASE_PATH = "./tools/packages"
  15. def __build_taipy_package_line(line: str, version: str, publish_on_py_pi: bool) -> str:
  16. _line = line.strip()
  17. max_version = f'{version.split(".")[0]}.{int(version.split(".")[1]) + 1}.0'
  18. if publish_on_py_pi:
  19. return f"{_line}>={version}, <{max_version}\n"
  20. tag = f"{version}-{_line.split('-')[1]}"
  21. tar_name = f"{_line}-{version}"
  22. return f"{_line} @ https://github.com/Avaiga/taipy/releases/download/{tag}/{tar_name}.tar.gz\n"
  23. def update_setup_requirements(package: str, versions: Dict, publish_on_py_pi: bool) -> None:
  24. _path = os.path.join(BASE_PATH, package, "setup.requirements.txt")
  25. lines = []
  26. with open(_path, mode="r") as req:
  27. for line in req:
  28. if v := versions.get(line.strip()):
  29. line = __build_taipy_package_line(line, v, publish_on_py_pi)
  30. lines.append(line)
  31. with open(_path, "w") as file:
  32. file.writelines(lines)
  33. if __name__ == "__main__":
  34. _package = sys.argv[1]
  35. _versions = {
  36. "taipy-config": sys.argv[2],
  37. "taipy-core": sys.argv[3],
  38. "taipy-gui": sys.argv[4],
  39. "taipy-rest": sys.argv[5],
  40. "taipy-templates": sys.argv[6],
  41. }
  42. _publish_on_py_pi = True if sys.argv[7] == "true" else False
  43. update_setup_requirements(_package, _versions, _publish_on_py_pi)