From 5217dff3e17252b1b3371300be3e5a3dc312ff13 Mon Sep 17 00:00:00 2001 From: Ben Steffensmeier Date: Wed, 8 Dec 2021 10:47:03 -0600 Subject: [PATCH] Virtual env improvements. --- commands/scripts.py | 17 ++++++++++++++--- src/main/scripts/jep | 10 ++-------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/commands/scripts.py b/commands/scripts.py index 0b398617..7af7e177 100644 --- a/commands/scripts.py +++ b/commands/scripts.py @@ -64,12 +64,24 @@ def copy_scripts(self): install_base=install.install_base, install_platbase=install.install_platbase, install_lib=install.install_lib, - virtual_env=os.environ.get('VIRTUAL_ENV') or '', + virtual_env='', ld_library_path='', ld_preload='', pythonhome='', + pythonexecutable='', ) + if os.environ.get('VIRTUAL_ENV'): + if is_windows(): + context['virtual_env'] = os.environ.get('VIRTUAL_ENV') + else: + context['virtual_env'] = '. %s/bin/activate' % os.environ.get('VIRTUAL_ENV') + if is_osx(): + # OS X is setting sys.executable to java which is preventing it from finding site-packages in a venv + # setting PYTHONEXECUTABLE overrides sys.executable and helps find site-packages + context['pythonexecutable'] = 'export PYTHONEXECUTABLE = %s' % sys.executable + + if not is_osx() and not is_windows(): context['ld_library_path'] = 'LD_LIBRARY_PATH="' + \ sysconfig.get_config_var('LIBDIR') + \ @@ -82,7 +94,7 @@ def copy_scripts(self): if lib_python: context['ld_preload'] = 'LD_PRELOAD="{0}"; export LD_PRELOAD'.format( lib_python) - if is_osx(): + if is_osx() and not os.environ.get('VIRTUAL_ENV'): prefix = sysconfig.get_config_var('prefix') exec_prefix = sysconfig.get_config_var('exec_prefix') if prefix == exec_prefix: @@ -92,7 +104,6 @@ def copy_scripts(self): context['pythonhome'] = 'PYTHONHOME="{0}"; export PYTHONHOME'.format( pythonhome) - for script in self.scripts: if is_windows(): script = '{0}.bat'.format(script) diff --git a/src/main/scripts/jep b/src/main/scripts/jep index e8adc0b5..be238303 100644 --- a/src/main/scripts/jep +++ b/src/main/scripts/jep @@ -1,17 +1,11 @@ #!/bin/sh -VIRTUAL_ENV={virtual_env} -export VIRTUAL_ENV - +{virtual_env} +{pythonexecutable} {pythonhome} {ld_library_path} {ld_preload} -if test "x$VIRTUAL_ENV" != "x"; then - PATH="$VIRTUAL_ENV/bin:$PATH" - export PATH -fi - cp="{install_lib}jep/jep-{version}.jar" if test "x$CLASSPATH" != "x"; then cp="$cp":"$CLASSPATH"