From 2afaff171388f3849f6ab9f47e68be5ce2d2a315 Mon Sep 17 00:00:00 2001 From: allegroai <> Date: Sun, 26 Jan 2020 15:05:59 +0200 Subject: [PATCH] Fix poetry support inside virtualenv with pyenv --- trains_agent/helper/package/poetry_api.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/trains_agent/helper/package/poetry_api.py b/trains_agent/helper/package/poetry_api.py index 5f59d11..11db8f3 100644 --- a/trains_agent/helper/package/poetry_api.py +++ b/trains_agent/helper/package/poetry_api.py @@ -59,8 +59,15 @@ class PoetryConfig: func = kwargs.pop("func", Argv.get_output) kwargs.setdefault("stdin", DEVNULL) kwargs['env'] = deepcopy(os.environ) - kwargs['env'].pop('VIRTUAL_ENV', None) - kwargs['env'].pop('CONDA_PREFIX', None) + if 'VIRTUAL_ENV' in kwargs['env'] or 'CONDA_PREFIX' in kwargs['env']: + kwargs['env'].pop('VIRTUAL_ENV', None) + kwargs['env'].pop('CONDA_PREFIX', None) + kwargs['env'].pop('PYTHONPATH', None) + if hasattr(sys, "real_prefix") and hasattr(sys, "base_prefix"): + path = ':'+kwargs['env']['PATH'] + path = path.replace(':'+sys.base_prefix, ':'+sys.real_prefix, 1) + kwargs['env']['PATH'] = path + if check_if_command_exists("poetry"): argv = Argv("poetry", *args) else: