fix: when global python libraries are not set in PATH

This commit is contained in:
Vinicius Moreira
2019-09-19 23:19:27 -03:00
parent 589f8e3bc8
commit e656992ac4

View File

@@ -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