From e656992ac4e17dc3e1c16e9175cae1e923fea6b0 Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Thu, 19 Sep 2019 23:19:27 -0300 Subject: [PATCH] fix: when global python libraries are not set in PATH --- bauh/commons/system.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/bauh/commons/system.py b/bauh/commons/system.py index 4750777a..ab199d5c 100644 --- a/bauh/commons/system.py +++ b/bauh/commons/system.py @@ -1,12 +1,22 @@ import os import subprocess +import sys from subprocess import PIPE from typing import List # default environment variables for subprocesses. from bauh.api.abstract.handler import ProcessWatcher -GLOBAL_INTERPRETER_PATH = ':'.join(os.getenv('PATH').split(':')[1:]) +PY_VERSION = "{}.{}".format(sys.version_info.major, sys.version_info.minor) +GLOBAL_PY_LIBS = '/usr/lib/python{}'.format(PY_VERSION) + +PATH = os.getenv('PATH') + +GLOBAL_INTERPRETER_PATH = ':'.join(PATH.split(':')[1:]) + +if GLOBAL_PY_LIBS not in PATH: + PATH = '{}:{}'.format(GLOBAL_PY_LIBS, PATH) + USE_GLOBAL_INTERPRETER = bool(os.getenv('VIRTUAL_ENV')) @@ -15,6 +25,8 @@ def gen_env(global_interpreter: bool) -> dict: if global_interpreter: # to avoid subprocess calls to the virtualenv python interpreter instead of the global one. res['PATH'] = GLOBAL_INTERPRETER_PATH + else: + res['PATH'] = PATH return res