3 # Copyright (C) 2022-2024 CEA, EDF, OPEN CASCADE
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # See https://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 # File : runSalomeOnDemand.py
23 # Author : Konstantin Leontev, Open Cascade
25 ## @package runSalomeOnDemand
26 # \brief Module that provides services to launch SALOME with custom set of modules
29 """Run SALOME app in the context of adding modules as extensions.
34 from SalomeOnDemandTK.extension_utilities import logger, \
35 set_selext_env, get_app_root, find_file
36 from SalomeOnDemandTK.extension_query import ext_by_dependants, dependency_tree
39 def set_ext_env(app_name='', version=''):
41 Set an environment to start SALOME as a set of extensions.
44 app_name - an application's name.
45 version - a version of an application.
51 logger.debug('Set an env for app: %s, version: %s...', app_name, version)
53 # Get the root directory
54 app_root = get_app_root()
56 # Set the root dir as env variable
57 context = salomeContext.SalomeContext(None)
58 context.setVariable('SALOME_APPLICATION_DIR', app_root, overwrite=True)
60 # Find and source all _env.py files for installed extensions
61 tree = dependency_tree(app_root)
62 installed_ext = ext_by_dependants(tree)
63 logger.debug('Installed extensions: %s', installed_ext)
65 logger.debug('There are not any extensions in %s!', app_root)
68 # Execute env file as a module
69 for ext_name in installed_ext:
70 set_selext_env(app_root, ext_name, context)
71 for python_path in os.environ["PYTHONPATH"].split(':'):
72 sys.path[:0] = [python_path]
74 if __name__ == "__main__":
75 if len(sys.argv) == 3:
76 arg_1, arg_2 = sys.argv[1:]
77 set_ext_env(arg_1, arg_2)
79 logger.error('You must provide all the arguments!')
80 logger.info(set_ext_env.__doc__)