validate_taipy_install.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # Copyright 2021-2025 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 logging
  12. import os
  13. import sys
  14. def test_import_taipy_packages() -> bool:
  15. """
  16. Import taipy package and call gui, Scenario and rest attributes.
  17. """
  18. import taipy as tp
  19. valid_install = True
  20. if not hasattr(tp, "gui"):
  21. logging.error("Taipy installation has no attribute gui")
  22. valid_install = False
  23. if not hasattr(tp, "Scenario"):
  24. logging.error("Taipy installation has no attribute Scenario")
  25. valid_install = False
  26. if not hasattr(tp, "rest"):
  27. logging.error("Taipy installation has no attribute rest")
  28. valid_install = False
  29. return valid_install
  30. def is_taipy_gui_install_valid() -> bool:
  31. from pathlib import Path
  32. import taipy
  33. taipy_gui_core_path = Path(taipy.__file__).absolute().parent / "gui_core" / "lib" / "taipy-gui-core.js"
  34. if not taipy_gui_core_path.exists():
  35. logging.error("File taipy-gui-core.js not found in taipy installation path")
  36. return False
  37. taipy_gui_webapp_path = Path(taipy.__file__).absolute().parent / "gui" / "webapp"
  38. if not os.path.exists(taipy_gui_webapp_path):
  39. return False
  40. if not any(fname.endswith(".js") for fname in os.listdir(taipy_gui_webapp_path)):
  41. logging.error("Missing js files inside taipy gui webapp folder")
  42. return False
  43. return True
  44. if __name__ == "__main__":
  45. logging.basicConfig(level=logging.INFO)
  46. logging.info("Trying to import taipy and verify it's main attributes")
  47. if not test_import_taipy_packages() or not is_taipy_gui_install_valid():
  48. sys.exit(1)
  49. logging.info("Taipy installation Validated")
  50. sys.exit(0)