update_setup.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 sys
  12. def update_setup() -> None:
  13. with open("setup.taipy.py", mode="r") as setup_r, open("setup.py", mode="w") as setup_w:
  14. in_requirements = False
  15. looking = True
  16. for line in setup_r:
  17. if looking:
  18. if line.lstrip().startswith("requirements") and line.rstrip().endswith("["):
  19. in_requirements = True
  20. elif in_requirements:
  21. if line.strip() == "]":
  22. looking = False
  23. else:
  24. if line.lstrip().startswith('"taipy-gui@git+https'):
  25. start = line.find('"taipy-gui')
  26. end = line.rstrip().find(",")
  27. line = f'{line[:start]}"taipy-gui=={sys.argv[1]}"{line[end:]}'
  28. elif line.lstrip().startswith('"taipy-rest@git+https'):
  29. start = line.find('"taipy-rest')
  30. end = line.rstrip().find(",")
  31. line = f'{line[:start]}"taipy-rest=={sys.argv[2]}"{line[end:]}'
  32. elif line.lstrip().startswith('"taipy-templates@git+https'):
  33. start = line.find('"taipy-templates')
  34. end = line.rstrip().find(",")
  35. line = f'{line[:start]}"taipy-templates=={sys.argv[3]}"{line[end:]}'
  36. setup_w.write(line)
  37. if __name__ == "__main__":
  38. update_setup()