From e95194cf8d0d93c6976695398bdbb5a80145bebf Mon Sep 17 00:00:00 2001 From: Gilles DAVID Date: Fri, 28 May 2021 11:54:44 +0200 Subject: [PATCH] SALOME_VENV_DIRECTORY can be set to configure a venv to use --- bin/salomeContext.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/bin/salomeContext.py b/bin/salomeContext.py index 3cfb38082..87357903b 100755 --- a/bin/salomeContext.py +++ b/bin/salomeContext.py @@ -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 # -- 2.39.2