validate_taipy_install.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. # Tests that Taipy is properly installed.
  13. # - Importing the taipy package exposes crucial attributes.
  14. # - The taipy-gui package is built
  15. # - The gui_core extension library is built
  16. #
  17. # Exits with error code on failure.
  18. #
  19. # Invoked from the workflows in workflows/packaging.yml and workflows/publish.yml.
  20. # --------------------------------------------------------------------------------------------------
  21. import logging
  22. import os
  23. import sys
  24. def test_import_taipy_packages() -> bool:
  25. """
  26. Import taipy package and check some attributes.
  27. """
  28. import taipy as tp
  29. valid_install = True
  30. if not hasattr(tp, "gui"):
  31. logging.error("Taipy installation has no attribute gui")
  32. valid_install = False
  33. if not hasattr(tp, "Scenario"):
  34. logging.error("Taipy installation has no attribute Scenario")
  35. valid_install = False
  36. if not hasattr(tp, "rest"):
  37. logging.error("Taipy installation has no attribute rest")
  38. valid_install = False
  39. return valid_install
  40. def is_taipy_gui_install_valid() -> bool:
  41. """
  42. Check crucial Taipy GUI build outcomes.
  43. """
  44. from pathlib import Path
  45. import taipy
  46. taipy_gui_core_path = Path(taipy.__file__).absolute().parent / "gui_core" / "lib" / "taipy-gui-core.js"
  47. if not taipy_gui_core_path.exists():
  48. logging.error("File taipy-gui-core.js not found in taipy installation path")
  49. return False
  50. taipy_gui_webapp_path = Path(taipy.__file__).absolute().parent / "gui" / "webapp"
  51. if not os.path.exists(taipy_gui_webapp_path):
  52. return False
  53. if not any(fname.endswith(".js") for fname in os.listdir(taipy_gui_webapp_path)):
  54. logging.error("Missing js files inside taipy gui webapp folder")
  55. return False
  56. return True
  57. if __name__ == "__main__":
  58. logging.basicConfig(level=logging.INFO)
  59. logging.info("Trying to import taipy and verify it's main attributes")
  60. if not test_import_taipy_packages() or not is_taipy_gui_install_valid():
  61. sys.exit(1)
  62. logging.info("Taipy installation Validated")
  63. sys.exit(0)