bootstrap.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. # coding:utf-8
  2. #!/usr/bin/python
  3. #
  4. # Copyright (c) Contributors to the Open 3D Engine Project.
  5. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  6. #
  7. # SPDX-License-Identifier: Apache-2.0 OR MIT
  8. #
  9. # -- This line is 75 characters -------------------------------------------
  10. """Empty Doc String""" # To Do: add documentation
  11. # -------------------------------------------------------------------------
  12. # built-ins
  13. import sys
  14. import os
  15. import site
  16. import importlib.util
  17. #import logging as _logging
  18. # if running in py2.7 we won't have access to pathlib yet until we boostrap
  19. # the DCCsi
  20. _MODULE_PATH = os.path.realpath(__file__) # To Do: what if frozen?
  21. _DCCSIG_PATH = os.path.normpath(os.path.join(_MODULE_PATH, '../../../..'))
  22. _DCCSIG_PATH = os.getenv('DCCSIG_PATH', _DCCSIG_PATH)
  23. site.addsitedir(_DCCSIG_PATH)
  24. # print(_DCCSIG_PATH)
  25. # Lumberyard DCCsi site extensions
  26. from pathlib import Path
  27. # set up global space, logging etc.
  28. import azpy
  29. from azpy.env_bool import env_bool
  30. from azpy.constants import ENVAR_DCCSI_GDEBUG
  31. from azpy.constants import ENVAR_DCCSI_DEV_MODE
  32. # these are for module debugging, set to false on submit
  33. _DCCSI_GDEBUG = env_bool(ENVAR_DCCSI_GDEBUG, False)
  34. _DCCSI_DEV_MODE = env_bool(ENVAR_DCCSI_DEV_MODE, False)
  35. _PACKAGENAME = 'DCCsi.SDK.substance.builder.bootstrap'
  36. _log_level = int(20)
  37. if _DCCSI_GDEBUG:
  38. _log_level = int(10)
  39. _LOGGER = azpy.initialize_logger(_PACKAGENAME,
  40. log_to_file=True,
  41. default_log_level=_log_level)
  42. _LOGGER.debug('Starting up: {0}.'.format({_PACKAGENAME}))
  43. _LOGGER.debug('_DCCSIG_PATH: {}'.format(_DCCSIG_PATH))
  44. _LOGGER.debug('_G_DEBUG: {}'.format(_DCCSI_GDEBUG))
  45. _LOGGER.debug('_DCCSI_DEV_MODE: {}'.format(_DCCSI_DEV_MODE))
  46. if _DCCSI_DEV_MODE:
  47. from azpy.test.entry_test import connect_wing
  48. foo = connect_wing()
  49. # To Do: now that we have figured out the pattern and this is working
  50. # we should consider initializing this earlier and reduce code lines?
  51. # we can go ahead and just make sure the the DCCsi env is set
  52. # config is SO generic this ensures we are importing a specific one
  53. _spec_dccsi_config = importlib.util.spec_from_file_location("dccsi.config",
  54. Path(_DCCSIG_PATH,
  55. "config.py"))
  56. _dccsi_config = importlib.util.module_from_spec(_spec_dccsi_config)
  57. _spec_dccsi_config.loader.exec_module(_dccsi_config)
  58. from dynaconf import settings
  59. try:
  60. from PySide2.QtWidgets import QApplication
  61. except:
  62. _dccsi_config.init_o3de_pyside(settings.O3DE_DEV) # init for standalone
  63. # running in the editor if the QtForPython Gem is enabled
  64. # you should already have access and shouldn't need to set up
  65. settings.setenv() # initialize the dynamic env and settings
  66. # -------------------------------------------------------------------------
  67. # -------------------------------------------------------------------------
  68. # substance automation toolkit (aka pysbs)
  69. # to do: move this into SDK\Substance using per-app dynaconf config extension
  70. from azpy.constants import PATH_PROGRAMFILES_X64
  71. # this could be moved into a constants file (where?)
  72. _PYSBS_DIR_PATH = Path(PATH_PROGRAMFILES_X64,
  73. 'Allegorithmic',
  74. 'Substance Automation Toolkit',
  75. 'Python API',
  76. 'install').resolve()
  77. os.environ["DYNACONF_QPYSBS_DIR_PATH"] = str(_PYSBS_DIR_PATH)
  78. os.environ["PYSBS_DIR_PATH"] = str(_PYSBS_DIR_PATH)
  79. # standard paths we may use downstream
  80. # To Do: move these into a dynaconf config extension specific to this tool?
  81. from azpy.constants import ENVAR_O3DE_DEV
  82. _O3DE_DEV = Path(os.getenv(ENVAR_O3DE_DEV,
  83. settings.O3DE_DEV)).resolve()
  84. from azpy.constants import ENVAR_O3DE_PROJECT_PATH
  85. _O3DE_PROJECT_PATH = Path(os.getenv(ENVAR_O3DE_PROJECT_PATH,
  86. settings.O3DE_PROJECT_PATH)).resolve()
  87. from azpy.constants import ENVAR_DCCSI_SDK_PATH
  88. _DCCSI_SDK_PATH = Path(os.getenv(ENVAR_DCCSI_SDK_PATH,
  89. settings.DCCSIG_SDK_PATH)).resolve()
  90. # build some reuseable path parts for the substance builder
  91. _PROJECT_ASSETS_PATH = Path(_O3DE_PROJECT_PATH, 'Assets').resolve()
  92. _PROJECT_MATERIALS_PATH = Path(_PROJECT_ASSETS_PATH, 'Materials').resolve()
  93. # -------------------------------------------------------------------------
  94. ###########################################################################
  95. # Main Code Block, runs this script as main (testing)
  96. # -------------------------------------------------------------------------
  97. if __name__ == "__main__":
  98. """Run this file as main"""
  99. _LOGGER.info('_O3DE_DEV: {}'.format(_O3DE_DEV))
  100. _LOGGER.info('_O3DE_PROJECT_PATH: {}'.format(_O3DE_PROJECT_PATH))
  101. _LOGGER.info('_DCCSI_SDK_PATH: {}'.format(_DCCSI_SDK_PATH))
  102. _LOGGER.info('_PYSBS_DIR_PATH: {}'.format(_PYSBS_DIR_PATH))
  103. _LOGGER.info('_PROJECT_ASSETS_PATH: {}'.format(_PROJECT_ASSETS_PATH))
  104. _LOGGER.info('_PROJECT_MATERIALS_PATH: {}'.format(_PROJECT_MATERIALS_PATH))
  105. if _DCCSI_GDEBUG:
  106. _dccsi_config.test_pyside2() # runs a small PySdie2 test
  107. # remove the logger
  108. del _LOGGER
  109. # ---- END ---------------------------------------------------------------