config.py 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. #
  10. # -------------------------------------------------------------------------
  11. """! This module manages the dynamic config and settings for bootstrapping
  12. Wing Pro 8 IDE integration with o3de inter-op, scripts, extensions, etc.
  13. :file: DccScriptingInterfac\\Tools\\IDE\\Wing\\config.py
  14. :Status: Prototype
  15. :Version: 0.0.1
  16. :Future: is unknown
  17. :Notice:
  18. """
  19. # -------------------------------------------------------------------------
  20. import timeit
  21. _MODULE_START = timeit.default_timer() # start tracking
  22. # standard imports
  23. from pathlib import Path
  24. import logging as _logging
  25. # -------------------------------------------------------------------------
  26. # global scope
  27. from DccScriptingInterface.Tools.IDE.Wing import _PACKAGENAME
  28. _MODULENAME = f'{_PACKAGENAME}.config'
  29. _LOGGER = _logging.getLogger(_MODULENAME)
  30. _LOGGER.debug('Initializing: {0}.'.format({_MODULENAME}))
  31. _MODULE_PATH = Path(__file__)
  32. _LOGGER.debug(f'_MODULE_PATH: {_MODULE_PATH.as_posix()}')
  33. # dynaconf boilerplate
  34. from dynaconf import Dynaconf
  35. settings = Dynaconf(envar_prefix='DYNACONF',
  36. # the following will also load settings.local.json
  37. settings_files=['settings.json', '.secrets.json'])
  38. settings.setenv() # ensure default file based settings are in the env
  39. # ensure dccsi and o3de core access
  40. # in a future iteration it is suggested that the core config
  41. # be rewritten from ConfigClass, then WingConfig inherits core
  42. import DccScriptingInterface.config as dccsi_core_config
  43. # this will initialize the core dynamic config, settings and env
  44. # if the Qt/PySide envars are set, it can cause some Qt based apps to fail
  45. # wing happens to be one of them, this is disabled for wing\start.py to perform
  46. # we also don't want o3de python to mesh with wings python?
  47. # any module, or tool, the need them can reinit the config
  48. # the problem with not doing it, is then we are not passing o3de python
  49. # info to wing, such as launch interpretter DCCSI_PY_IDE
  50. # wing's default interpretter won't have access to o3de packages, etc.
  51. # but maybe they could be installed into wing with foundation.py?
  52. _settings_core = dccsi_core_config.get_config_settings(enable_o3de_python=True,
  53. enable_o3de_pyside2=False,
  54. set_env=True)
  55. # from within wing, setting the Qt/PySide2 envars before running
  56. # another script/tool performs fine, as the interpreter is a subprocess
  57. # local dccsi imports
  58. # this accesses common global state, e.g. DCCSI_GDEBUG (is True or False)
  59. from DccScriptingInterface.globals import *
  60. # this will auto-attach ide debugging at the earliest possible point in module
  61. from azpy.config_utils import attach_debugger
  62. if DCCSI_DEV_MODE: # from DccScriptingInterface.globals
  63. attach_debugger(debugger_type=DCCSI_GDEBUGGER)
  64. # if the dccsi core config and it's settings are loaded this should pass
  65. try:
  66. _settings_core.DCCSI_CONFIG_CORE
  67. except EnvironmentError as e:
  68. _LOGGER.error('Setting does not exist: DCCSI_CONFIG_CORE')
  69. _LOGGER.warning(f'EnvironmentError: {e}')
  70. # can run local tests
  71. if DCCSI_TESTS: # from DccScriptingInterface.globals
  72. # this will validate pyside bootstrapping
  73. foo = dccsi_core_config.test_pyside2(exit = False)
  74. pass
  75. # this is the root path for the wing pkg
  76. from DccScriptingInterface.Tools.IDE.Wing import ENVAR_PATH_DCCSI_TOOLS_IDE_WING
  77. from DccScriptingInterface.Tools.IDE.Wing import PATH_DCCSI_TOOLS_IDE_WING
  78. from DccScriptingInterface.Tools.IDE.Wing import PATH_DCCSI_TOOLS_IDE_WING_SETTINGS
  79. from DccScriptingInterface.Tools.IDE.Wing import PATH_DCCSI_TOOLS_IDE_WING_LOCAL_SETTINGS
  80. # -------------------------------------------------------------------------
  81. # -------------------------------------------------------------------------
  82. # now we build the wing config class
  83. from DccScriptingInterface.azpy.config_class import ConfigClass
  84. # For a DCC tool like Maya, where we may have additional tools that need
  85. # their own config/settings, the MayaConfig could inherit from the
  86. # CoreConfig (which is a ConfigClass), then the tool could have it's own
  87. # MyMayaToolConfig that inherits from MayaConfig and extends it further.
  88. # wing does have an API, theoretically we could create tools built on top
  89. # of wing like we do with DCC tools ... but we do not yet have the need
  90. # so the more simple approach is taken here for now, a ConfigClass object
  91. # but it is suggested that when the core <dccsi>\config.py is re-written
  92. # as a ConfigClass, that the WingConfig inherits from that instead
  93. # wing_config is a class object of WingConfig
  94. # WingConfig is a child class of ConfigClass
  95. class WingConfig(ConfigClass):
  96. """Extend ConfigClass with new wing functionality"""
  97. def __init__(self, *args, **kwargs):
  98. super().__init__(*args, **kwargs)
  99. _LOGGER.info(f'Initializing: {self.get_classname()}')
  100. # build config object
  101. wing_config = WingConfig(config_name='dccsi_ide_wing',
  102. settings_filepath = PATH_DCCSI_TOOLS_IDE_WING_SETTINGS,
  103. settings_local_filepath = PATH_DCCSI_TOOLS_IDE_WING_LOCAL_SETTINGS,
  104. auto_set=True)
  105. # in another module someone could work this way
  106. # from DccScriptingInterface.Tools.IDE.Wing.config import wing_config
  107. # settings = wing_config.get_settings(set_env=True)
  108. # a managed setting to track the wing config is enabled
  109. from Tools.IDE.Wing.constants import ENVAR_DCCSI_CONFIG_IDE_WING
  110. wing_config.add_setting(ENVAR_DCCSI_CONFIG_IDE_WING, True)
  111. # path to the Tools\IDE\Wing location
  112. wing_config.add_setting(ENVAR_PATH_DCCSI_TOOLS_IDE_WING,
  113. PATH_DCCSI_TOOLS_IDE_WING)
  114. # a managed envar for wing version
  115. from Tools.IDE.Wing.constants import ENVAR_DCCSI_WING_VERSION_MAJOR
  116. from Tools.IDE.Wing.constants import SLUG_DCCSI_WING_VERSION_MAJOR
  117. wing_config.add_setting(ENVAR_DCCSI_WING_VERSION_MAJOR,
  118. SLUG_DCCSI_WING_VERSION_MAJOR)
  119. # a managed envar setting for WINGHOME (install location)
  120. from Tools.IDE.Wing.constants import ENVAR_WINGHOME
  121. from Tools.IDE.Wing.constants import PATH_WINGHOME
  122. PATH_WINGHOME = Path(PATH_WINGHOME).resolve()
  123. wing_config.add_setting(ENVAR_WINGHOME,
  124. PATH_WINGHOME.as_posix(),
  125. set_sys_path=True)
  126. # a managed envar for the wing bin folder
  127. from Tools.IDE.Wing.constants import ENVAR_WINGHOME_BIN
  128. from Tools.IDE.Wing.constants import PATH_WINGHOME_BIN
  129. PATH_WINGHOME_BIN = Path(PATH_WINGHOME_BIN).resolve()
  130. wing_config.add_setting(ENVAR_WINGHOME_BIN,
  131. PATH_WINGHOME_BIN.as_posix(),
  132. set_sys_path=True)
  133. # a managed envar to the wing exe
  134. from Tools.IDE.Wing.constants import ENVAR_WING_EXE
  135. from Tools.IDE.Wing.constants import PATH_WINGHOME_BIN_EXE
  136. PATH_WINGHOME_BIN_EXE = Path(PATH_WINGHOME_BIN_EXE).resolve()
  137. wing_config.add_setting(ENVAR_WING_EXE,
  138. PATH_WINGHOME_BIN_EXE.as_posix())
  139. # a managed envar setting for the wing project file
  140. from Tools.IDE.Wing.constants import ENVAR_WING_PROJ
  141. from Tools.IDE.Wing.constants import PATH_DCCSI_TOOLS_IDE_WING_PROJ
  142. PATH_DCCSI_TOOLS_IDE_WING_PROJ = Path(PATH_DCCSI_TOOLS_IDE_WING_PROJ).resolve()
  143. wing_config.add_setting(ENVAR_WING_PROJ,
  144. PATH_DCCSI_TOOLS_IDE_WING_PROJ.as_posix())
  145. # a managed envar setting for the userhome wing appdata folder
  146. from Tools.IDE.Wing.constants import ENVAR_WING_APPDATA
  147. from Tools.IDE.Wing.constants import PATH_WING_APPDATA
  148. PATH_WING_APPDATA = Path(PATH_WING_APPDATA).resolve()
  149. wing_config.add_setting(ENVAR_WING_APPDATA,
  150. PATH_WING_APPDATA.as_posix())
  151. # -------------------------------------------------------------------------
  152. _MODULE_END = timeit.default_timer() - _MODULE_START
  153. _LOGGER.debug(f'{_MODULENAME} took: {_MODULE_END} sec')
  154. # -------------------------------------------------------------------------
  155. ###########################################################################
  156. # Main Code Block, runs this script as main (testing)
  157. # -------------------------------------------------------------------------
  158. if __name__ == '__main__':
  159. """Run this file as a standalone cli script for testing/debugging"""
  160. # this should hit this modules location and load wing settings
  161. settings = wing_config.get_settings(set_env=True)
  162. # initialize configs for DCC tools we want to develop with
  163. # so we get access to their python interpreter, etc.
  164. # it is suggested the in the future, there be a project setreg for wing
  165. # whose settings describe which DCC tools to activate on start
  166. # # Bolt On blender config
  167. # from DccScriptingInterface.Tools.DCC.Blender.config import blender_config
  168. #
  169. # # prefix for defining IDE interpreters 'DCCSI_PY_'
  170. # wing_config.add_setting('DCCSI_PY_BLENDER',
  171. # blender_config.settings.DCCSI_BLENDER_PY_EXE,
  172. # set_envar=True)
  173. # Bolt On maya config
  174. # not implemented yet
  175. # Bolt On other DCC tools
  176. # also not yet implemented
  177. # -------------------------------------------------------------------------
  178. try:
  179. settings.DCCSI_CONFIG_IDE_WING
  180. _LOGGER.info('Wing IDE config is enabled')
  181. except:
  182. _LOGGER.error('Setting does not exist')
  183. _LOGGER.info(f'Exporting local settings: {PATH_DCCSI_TOOLS_IDE_WING_LOCAL_SETTINGS}')
  184. try:
  185. wing_config.export_settings(set_env=True,
  186. log_settings=True)
  187. except Exception as e:
  188. _LOGGER.error(f'{e}')
  189. # --- END -----------------------------------------------------------------