From: DUC ANH HOANG Date: Tue, 28 Mar 2023 12:17:03 +0000 (+0200) Subject: Some updates for salome_on_demand: X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=fc1af6c30b7313c598afc384f328a1809af326c6;p=modules%2Fkernel.git Some updates for salome_on_demand: minimize environment variable of base modules at the start: we need only the pythonpath to the python script who launche salome Install all external binaries in salome_common_dir "__SALOME_EXT__/SALOME" update Salome_Common_env.py for salome tools and prerequisites remove the SALOME sub-directory from SALOME_EXT remove subdirectory SALOME from SALOME_EXT Base_env.py:update for common directory of extensions Create 3dparty package including all of prerequisites of salome update to minimize salome launcher dependencies --- diff --git a/bin/SalomeOnDemandTK/3dparty.salomexb b/bin/SalomeOnDemandTK/3dparty.salomexb new file mode 100644 index 000000000..7525e5de7 --- /dev/null +++ b/bin/SalomeOnDemandTK/3dparty.salomexb @@ -0,0 +1,85 @@ +Python/bin +Python/lib +Python/share +gcc/bin +gcc/lib +gcc/lib64 +gcc/libexec +gcc/share +lapack/lib +openmpi/bin +openmpi/lib +hdf5/bin +hdf5/lib +cgns/bin +cgns/lib +tbb/lib +nlopt/lib +libxml2/bin +libxml2/lib +netcdf/bin +netcdf/lib +gdal/bin +gdal/lib +gdal/share +boost/lib +omniORB/bin +omniORB/lib +cppunit/bin +cppunit/lib +LIBBATCH/lib +freetype/bin +freetype/lib +qt/plugins +qt/bin +qt/lib +sip/bin +sip/lib +PyQt/bin +PyQt/lib +PyQt/sip +freeimage/bin +freeimage/lib +CAS/bin +CAS/lib +CAS/share +qwt/lib +matplotlib/lib +embree/lib +rkCommon/lib +openVKL/lib +ospray/lib +cminpack/bin +cminpack/lib +cminpack/share +FMILibrary/bin +FMILibrary/lib +PyFMI/lib +openturns/bin +openturns/lib +catalyst/lib +ParaView/bin +ParaView/lib +graphviz/bin +graphviz/lib +pmml/bin +pmml/lib +opencv/bin +opencv/lib +tcl/bin +tcl/lib +planegcs/lib +medfile/bin +medfile/lib +metis/bin +metis/lib +metis/bin +petsc/lib +TTK/bin +TTK/lib +C3PO/bin +C3PO/lib +root/bin +root/lib +zeromq/bin +zeromq/lib \ No newline at end of file diff --git a/bin/SalomeOnDemandTK/3dparty.salomexd b/bin/SalomeOnDemandTK/3dparty.salomexd new file mode 100644 index 000000000..d5ede7b49 --- /dev/null +++ b/bin/SalomeOnDemandTK/3dparty.salomexd @@ -0,0 +1,8 @@ +{ + "name": "3dparty", + "descr": "SALOME extension", + "depends_on": [], + "author": "SALOME Team", + "components": [ "Python", "gcc", "lapack", "openmpi", "hdf5", "cgns", "tbb", "nlopt", "libxml2", "netcdf", "gdal", "boost", "omniORB", "cppunit", "LIBBATCH", "freetype", "qt", "sip", "PyQt", "freeimage", "CAS", "qwt", "matplotlib", "embree", "rkCommon", "openVKL", "ospray", "cminpack", "FMILibrary", "PyFMI", "openturns", "catalyst", "ParaView", "graphviz", "pmml", "opencv", "tcl", "planegcs", "medfile", "metis", "petsc", "TTK", "C3PO", "root", "zeromq" ] +} + diff --git a/bin/SalomeOnDemandTK/3dparty_env.py b/bin/SalomeOnDemandTK/3dparty_env.py new file mode 100644 index 000000000..161fc9bcc --- /dev/null +++ b/bin/SalomeOnDemandTK/3dparty_env.py @@ -0,0 +1,92 @@ + +#!/usr/bin/env python3 +# -*- coding:utf-8 -*- + +""" +SALOME application environment. +""" + +import os +import sys +from SalomeOnDemandTK.extension_query import ext_info_dict + + +def init(context, ext_root_dir): + """ + Set an environment for SALOME app. + + Args: + context - an SalomeContext object. + ext_root_dir - a path to __SALOME_EXT__ directory. + + Returns: + None. + """ + + BINDIR = os.path.join(ext_root_dir, 'bin') + LIBDIR = os.path.join(ext_root_dir, 'lib') + python_version = '{}.{}'.format(sys.version_info[0], sys.version_info[1]) + python_libdir = os.path.join('lib', 'python' + python_version, 'site-packages') + + reinitialise_paths = True + + #[SALOME_COMMON] + + out_dir_Path=os.path.dirname(os.path.realpath(__file__)) + + # Seting SALOME modules environment + modules = ext_info_dict(out_dir_Path) + for module in modules: + print + for component in modules[module][2].split(', '): + context.setVariable('%s_ROOT_DIR'%component, ext_root_dir, overwrite=True) + # Seting SALOME prerequis and tools environment + context.addToPath(BINDIR) + context.addToLdLibraryPath(LIBDIR) + context.addToPythonPath(BINDIR) + context.addToPythonPath(LIBDIR) + context.addToPythonPath(os.path.join(ext_root_dir, python_libdir)) + context.addToPythonPath(os.path.join(ext_root_dir, 'lib', 'python' + python_version)) + + #[Python] + context.setVariable(r"PYTHON_VERSION", python_version, overwrite=True) + context.addToPath(ext_root_dir) + context.setVariable(r"PYTHONBIN", os.path.join(BINDIR,'python3'), overwrite=True) + + #[gcc] + context.addToLdLibraryPath(os.path.join(ext_root_dir, 'lib64')) + + #[openmpi] + context.setVariable(r"MPIEXEC_EXECUTABLE", os.path.join(BINDIR, 'mpiexec'), overwrite=True) + context.addToPath(os.path.join(ext_root_dir,'include')) + + #[qt] + context.setVariable(r"QTDIR", ext_root_dir, overwrite=True) + context.setVariable(r"QT5_ROOT_DIR", ext_root_dir, overwrite=True) + context.setVariable(r"QT_PLUGIN_PATH", os.path.join(ext_root_dir,'plugins'), overwrite=True) + context.setVariable(r"QT_QPA_PLATFORM_PLUGIN_PATH", os.path.join(ext_root_dir,'plugins'), overwrite=True) + + #[PyQt] + context.addToPythonPath(os.path.join(ext_root_dir, 'sip',python_libdir)) + + #[CAS] + context.setVariable(r"CSF_ShadersDirectory", os.path.join( ext_root_dir, 'share/opencascade/resources/Shaders'), overwrite=True) + context.setVariable(r"CSF_UnitsLexicon", os.path.join( ext_root_dir, 'share/opencascade/resources/UnitsAPI/Lexi_Expr.dat'), overwrite=True) + context.setVariable(r"CSF_UnitsDefinition", os.path.join( ext_root_dir, 'share/opencascade/resources/UnitsAPI/Units.dat'), overwrite=True) + context.setVariable(r"CSF_SHMessage", os.path.join( ext_root_dir, 'share/opencascade/resources/SHMessage'), overwrite=True) + context.setVariable(r"CSF_XSMessage", os.path.join( ext_root_dir, 'share/opencascade/resources/XSMessage'), overwrite=True) + context.setVariable(r"CSF_MDTVTexturesDirectory", os.path.join( ext_root_dir, 'share/opencascade/resources/Textures'), overwrite=True) + context.setVariable(r"MMGT_REENTRANT", r"1", overwrite=True) + context.setVariable(r"CSF_StandardDefaults", os.path.join( ext_root_dir, 'share/opencascade/resources/StdResource'), overwrite=True) + context.setVariable(r"CSF_PluginDefaults", os.path.join( ext_root_dir, 'share/opencascade/resources/StdResource'), overwrite=True) + context.addToPath(ext_root_dir) + + #[ParaView] + context.setVariable(r"PV_PLUGIN_PATH", os.path.join(LIBDIR,'paraview-5.11'), overwrite=True) + context.addToVariable(r"PV_PLUGIN_PATH", os.path.join(LIBDIR,'paraview-5.11','plugins'),separator=":") + context.addToPythonPath(os.path.join(LIBDIR,'paraview-5.11', 'site-packages')) + context.addToPythonPath(os.path.join(LIBDIR,'paraview-5.11', 'site-packages', 'vtk')) + context.addToPath(os.path.join(ext_root_dir,'include', 'paraview-5.11')) + context.addToLdLibraryPath(os.path.join(LIBDIR,'paraview-5.11')) + context.addToPythonPath(os.path.join(LIBDIR,'paraview-5.11')) + context.addToPythonPath(python_libdir) \ No newline at end of file diff --git a/bin/SalomeOnDemandTK/Base_env.py b/bin/SalomeOnDemandTK/Base_env.py index ea4a6559e..dda72b73b 100644 --- a/bin/SalomeOnDemandTK/Base_env.py +++ b/bin/SalomeOnDemandTK/Base_env.py @@ -1,21 +1,23 @@ + #!/usr/bin/env python3 # -*- coding:utf-8 -*- """ -Add a custom environment to the SALOME extension. +SALOME application environment. """ import os import sys +from SalomeOnDemandTK.extension_query import ext_info_dict -def init(context, root_dir): +def init(context, ext_root_dir): """ - Set an environment for an extension on start of SALOME app. + Set an environment for SALOME app. Args: context - an SalomeContext object. - root_dir - a path to __SALOME_EXT__ directory. + ext_root_dir - a path to __SALOME_EXT__ directory. Returns: None. @@ -26,26 +28,31 @@ def init(context, root_dir): reinitialise_paths = True - #[KERNEL] - kernel_root_dir = os.path.join(root_dir, 'KERNEL') - context.setVariable('KERNEL_ROOT_DIR', kernel_root_dir, overwrite=True) - context.addToPath(os.path.join(kernel_root_dir, 'bin', 'salome')) - context.addToLdLibraryPath(os.path.join(kernel_root_dir, 'lib', 'salome')) - context.addToPythonPath(os.path.join(kernel_root_dir, 'bin', 'salome')) - context.addToPythonPath(os.path.join(kernel_root_dir, 'lib', 'salome')) - context.addToPythonPath(os.path.join(kernel_root_dir, python_libdir, 'salome')) - - #[GUI] - gui_root_dir = os.path.join(root_dir, 'GUI') - context.setVariable('GUI_ROOT_DIR', gui_root_dir, overwrite=True) - context.addToPath(os.path.join(gui_root_dir, 'bin', 'salome')) - context.addToLdLibraryPath(os.path.join(gui_root_dir, 'lib', 'salome')) - context.addToPythonPath(os.path.join(gui_root_dir, 'bin', 'salome')) - context.addToPythonPath(os.path.join(gui_root_dir, 'lib', 'salome')) - context.addToPythonPath(os.path.join(gui_root_dir, python_libdir, 'salome')) - - gui_res_dir = os.path.join(gui_root_dir, 'share', 'salome', 'resources', 'gui') + #[SALOME_COMMON] + + out_dir_Path=os.path.dirname(os.path.realpath(__file__)) + + # Seting SALOME modules environment + modules = ext_info_dict(out_dir_Path) + for module in modules: + print + for component in modules[module][2].split(', '): + context.setVariable('%s_ROOT_DIR'%component, ext_root_dir, overwrite=True) + context.addToPath(os.path.join(ext_root_dir, 'bin', 'salome')) + context.addToLdLibraryPath(os.path.join(ext_root_dir, 'lib', 'salome')) + context.addToPythonPath(os.path.join(ext_root_dir, 'bin', 'salome')) + context.addToPythonPath(os.path.join(ext_root_dir, 'lib', 'salome')) + context.addToPythonPath(os.path.join(ext_root_dir, python_libdir, 'salome')) + + # Seting SALOME prerequis and tools environment + context.addToPath(os.path.join(ext_root_dir, 'bin')) + context.addToLdLibraryPath(os.path.join(ext_root_dir, 'lib')) + context.addToPythonPath(os.path.join(ext_root_dir, 'bin')) + context.addToPythonPath(os.path.join(ext_root_dir, 'lib')) + context.addToPythonPath(os.path.join(ext_root_dir, python_libdir)) + + res_dir = os.path.join(ext_root_dir, 'share', 'salome', 'resources', 'gui') if reinitialise_paths: - context.setVariable('SalomeAppConfig', gui_res_dir, overwrite=True) + context.setVariable('SalomeAppConfig', res_dir, overwrite=True) else: - context.addToVariable('SalomeAppConfig', gui_res_dir, separator=os.pathsep) + context.addToVariable('SalomeAppConfig', res_dir, separator=os.pathsep) diff --git a/bin/SalomeOnDemandTK/extension_builder.py b/bin/SalomeOnDemandTK/extension_builder.py index c2a70b0a8..cb62a87f8 100644 --- a/bin/SalomeOnDemandTK/extension_builder.py +++ b/bin/SalomeOnDemandTK/extension_builder.py @@ -128,6 +128,12 @@ def create_salomex(salomexb, salomexd, env_py, top_repository): # List of the files those actually written to the archive. # It goes to the salomexc file then. files_abs, files_rel = list_files_filter(top_repository, included_files_patterns) + id = 0 + for f in files_rel: + fsplit = f.split('/') + del fsplit[0] + files_rel[id] = '/'.join(fsplit) + id +=1 add_files(ext, files_abs, files_rel) # Write the control file - list of the files inside extension's dir diff --git a/bin/SalomeOnDemandTK/extension_unpacker.py b/bin/SalomeOnDemandTK/extension_unpacker.py index 08b45d40f..0f7f1d1a2 100644 --- a/bin/SalomeOnDemandTK/extension_unpacker.py +++ b/bin/SalomeOnDemandTK/extension_unpacker.py @@ -42,7 +42,6 @@ from .extension_utilities import logger, \ isvalid_filename, isvalid_dirname, ext_info_bykey, set_selext_env, get_app_root, \ check_if_installed - def unpack_salomex(salome_root, salomex): """ Unpack a given salome extension archive into SALOME install root. diff --git a/bin/launchConfigureParser.py b/bin/launchConfigureParser.py index fde036288..2d754a396 100644 --- a/bin/launchConfigureParser.py +++ b/bin/launchConfigureParser.py @@ -880,21 +880,21 @@ def get_env(appname=salomeappname, cfgname=salomecfgname, exeName=None, keepEnvi global args config_var = appname+'Config' + ############################ + # parse command line options + pars = CreateOptionParser(exeName=exeName) + cmd_opts = pars.parse_args(sys.argv[1:]) + ############################ + # check KERNEL_ROOT_DIR kernel_root_dir = os.environ.get("KERNEL_ROOT_DIR", None) - if kernel_root_dir is None: + if kernel_root_dir is None and not cmd_opts.on_demand: print(""" For each SALOME module, the environment variable _ROOT_DIR must be set. KERNEL_ROOT_DIR is mandatory. """) sys.exit(1) - ############################ - # parse command line options - pars = CreateOptionParser(exeName=exeName) - cmd_opts = pars.parse_args(sys.argv[1:]) - ############################ - # Process --print-port option if cmd_opts.print_port: from searchFreePort import searchFreePort @@ -918,7 +918,7 @@ def get_env(appname=salomeappname, cfgname=salomecfgname, exeName=None, keepEnvi else: dirs += re.split('[;|:]', os.getenv(config_var)) - if not keepEnvironment: + if not keepEnvironment and not cmd_opts.on_demand: if os.getenv("GUI_ROOT_DIR") and os.path.isdir(os.getenv("GUI_ROOT_DIR")): gui_resources_dir = os.path.join(os.getenv("GUI_ROOT_DIR"),'share','salome','resources','gui') if os.path.isdir(gui_resources_dir): @@ -1014,7 +1014,7 @@ def get_env(appname=salomeappname, cfgname=salomecfgname, exeName=None, keepEnvi if cmd_opts.batch is not None: args[batch_nam] = True - if not os.getenv("GUI_ROOT_DIR") or not os.path.isdir(os.getenv("GUI_ROOT_DIR")): + if ( not os.getenv("GUI_ROOT_DIR") or not os.path.isdir(os.getenv("GUI_ROOT_DIR")) ) and not cmd_opts.on_demand: args[gui_nam] = False if args[gui_nam]: @@ -1158,23 +1158,24 @@ def get_env(appname=salomeappname, cfgname=salomecfgname, exeName=None, keepEnvi # now modify SalomeAppConfig environment variable # to take into account the SALOME modules - if os.sys.platform == 'win32': - dirs = re.split('[;]', os.environ[config_var] ) - else: - dirs = re.split('[;|:]', os.environ[config_var] ) - for module in args[modules_nam]: - if module not in ["KERNEL", "GUI", ""] and os.getenv("{0}_ROOT_DIR".format(module)): - d1 = os.path.join(os.getenv("{0}_ROOT_DIR".format(module)),"share","salome","resources",module.lower()) - d2 = os.path.join(os.getenv("{0}_ROOT_DIR".format(module)),"share","salome","resources") - #if os.path.exists( "%s/%s.xml"%(d1, appname) ): - if os.path.exists( os.path.join(d1,"{0}.xml".format(salomeappname)) ): - dirs.append( d1 ) - #elif os.path.exists( "%s/%s.xml"%(d2, appname) ): - elif os.path.exists( os.path.join(d2,"{0}.xml".format(salomeappname)) ): - dirs.append( d2 ) + if not args[on_demand_nam]: + if os.sys.platform == 'win32': + dirs = re.split('[;]', os.environ[config_var] ) else: - # print("* '"+m+"' should be deleted from ",args[modules_nam]) - pass + dirs = re.split('[;|:]', os.environ[config_var] ) + for module in args[modules_nam]: + if module not in ["KERNEL", "GUI", ""] and os.getenv("{0}_ROOT_DIR".format(module)): + d1 = os.path.join(os.getenv("{0}_ROOT_DIR".format(module)),"share","salome","resources",module.lower()) + d2 = os.path.join(os.getenv("{0}_ROOT_DIR".format(module)),"share","salome","resources") + #if os.path.exists( "%s/%s.xml"%(d1, appname) ): + if os.path.exists( os.path.join(d1,"{0}.xml".format(salomeappname)) ): + dirs.append( d1 ) + #elif os.path.exists( "%s/%s.xml"%(d2, appname) ): + elif os.path.exists( os.path.join(d2,"{0}.xml".format(salomeappname)) ): + dirs.append( d2 ) + else: + # print("* '"+m+"' should be deleted from ",args[modules_nam]) + pass # Test if cmd_opts.test_script_file is not None: diff --git a/bin/runSalome.py b/bin/runSalome.py index 6094707b4..1a0e1134b 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -24,7 +24,6 @@ # import sys, os, string, glob, time, pickle, re -import orbmodule import setenv from server import process_id, Server import json @@ -185,6 +184,9 @@ def main(exeName=None): # Setup extension's env in salome on demand case if args[on_demand_nam]: runSalomeOnDemand.set_ext_env() + # Reset up module_list and modules_root_dir, if we dont want to define SalomeAppConfig on salome.py. + # We must remove the "else" on "if os.sys.platform == 'win32':" in launcheConfigureParser.py too. + args, _, __ = setenv.get_config(exeName=exeName, keepEnvironment=keep_env) setenv.set_env(args, modules_list, modules_root_dir, keepEnvironment=keep_env) ior_fakens_filename = useSalome(args, modules_list, modules_root_dir) @@ -227,8 +229,8 @@ def foreGround(args, ior_fakens_filename): logger.warn("No file {} set to host IOR of the fake naming server does not exit !") return import CORBA - import Engines - import SALOME + #import Engines + #import SALOME from time import sleep orb = CORBA.ORB_init([''], CORBA.ORB_ID) ior_fakens = None @@ -305,6 +307,7 @@ def runSalome(): args, ior_fakens_filename = main() # -- test = args['gui'] and args['session_gui'] + test = test and not args[on_demand_nam] test = test or args['wake_up_session'] # -- # The next test covers the --pinter option or if var PYTHONINSPECT is set diff --git a/bin/runSalomeOnDemand.py b/bin/runSalomeOnDemand.py index 1326dd827..3047b209c 100755 --- a/bin/runSalomeOnDemand.py +++ b/bin/runSalomeOnDemand.py @@ -29,10 +29,10 @@ """Run SALOME app in the context of adding modules as extensions. """ -import sys +import os,sys import salomeContext from SalomeOnDemandTK.extension_utilities import logger, \ - set_selext_env, get_app_root + set_selext_env, get_app_root, find_file from SalomeOnDemandTK.extension_query import ext_by_dependants, dependency_tree @@ -53,6 +53,10 @@ def set_ext_env(app_name='', version=''): # Get the root directory app_root = get_app_root() + # Set the root dir as env variable + context = salomeContext.SalomeContext(None) + context.setVariable('SALOME_APPLICATION_DIR', app_root, overwrite=True) + # Find and source all _env.py files for installed extensions tree = dependency_tree(app_root) installed_ext = ext_by_dependants(tree) @@ -61,14 +65,11 @@ def set_ext_env(app_name='', version=''): logger.debug('There are not any extensions in %s!', app_root) return - # Set the root dir as env variable - context = salomeContext.SalomeContext(None) - context.setVariable('SALOME_APPLICATION_DIR', app_root, overwrite=True) - # Execute env file as a module for ext_name in installed_ext: set_selext_env(app_root, ext_name, context) - + for python_path in os.environ["PYTHONPATH"].split(':'): + sys.path[:0] = [python_path] if __name__ == "__main__": if len(sys.argv) == 3: diff --git a/bin/setenv.py b/bin/setenv.py index 824e6a962..2e5474be4 100755 --- a/bin/setenv.py +++ b/bin/setenv.py @@ -23,7 +23,6 @@ # import sys, os, string, glob, time, pickle -import orbmodule from launchConfigureParser import verbose # this file is extraction of set_env from runSalome.py