]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
SALOME_VENV_DIRECTORY can be set to configure a venv to use
authorGilles DAVID <gilles-g.david@edf.fr>
Fri, 28 May 2021 09:54:44 +0000 (11:54 +0200)
committerGilles DAVID <gilles-g.david@edf.fr>
Fri, 28 May 2021 09:54:44 +0000 (11:54 +0200)
bin/salomeContext.py

index 3cfb3808274aa6137b80dcea4b69e1f676329896..87357903b7d009ac0fefce849f63bf8fc403ec71 100755 (executable)
@@ -118,6 +118,7 @@ class SalomeContext:
 
   def runSalome(self, args):
     import os
+    import sys
     # Run this module as a script, in order to use appropriate Python interpreter
     # according to current path (initialized from context files).
     env_modules_option = "--with-env-modules="
@@ -135,7 +136,19 @@ class SalomeContext:
     env_copy = os.environ.copy()
     selfBytes= pickle.dumps(self, protocol=0)
     argsBytes= pickle.dumps(args, protocol=0)
-    proc = subprocess.Popen(['python3', os.path.join(absoluteAppliPath,"bin","salome","salomeContext.py"), selfBytes.decode('latin1'), argsBytes.decode('latin1')], shell=False, close_fds=True, env=env_copy)
+    py_executable = sys.executable
+    salome_venv_directory = os.getenv('SALOME_VENV_DIRECTORY')
+    if salome_venv_directory and os.path.isdir(salome_venv_directory):
+        salome_venv_path = os.path.join(salome_venv_directory, 'bin')
+        venv_py_executable = os.path.join(salome_venv_path, 'python')
+        if os.path.exists(venv_py_executable):
+            py_executable = venv_py_executable
+            import sysconfig
+            python_site_packages = sysconfig.get_path('purelib').replace(os.path.join(sys.prefix, ''), '').lstrip(os.sep)
+            salome_venv_pythonpath = os.path.join(salome_venv_directory, python_site_packages)
+            env_copy['PATH'] = '%s:%s' % (salome_venv_path, env_copy['PATH'])
+            env_copy['PYTHONPATH'] = '%s:%s' % (salome_venv_pythonpath, env_copy['PYTHONPATH'])
+    proc = subprocess.Popen([py_executable, os.path.join(absoluteAppliPath,"bin","salome","salomeContext.py"), selfBytes.decode('latin1'), argsBytes.decode('latin1')], shell=False, close_fds=True, env=env_copy)
     out, err = proc.communicate()
     return out, err, proc.returncode
   #