Skip to content

Commit

Permalink
Set CONDA_PREFIX on wrappers to make them compatible with conda>=4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
gqmelo committed Sep 29, 2016
1 parent 54c0f4f commit 5e264b0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
8 changes: 7 additions & 1 deletion exec_wrappers/create_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,18 @@ def create_conda_wrappers(files_to_wrap, destination_dir, inline, conda_env_dir)

run_in_template_filename = os.path.join(this_dir, 'templates', 'conda', 'run-in' +
get_wrapper_extension())

def template_function(content):
content = content.replace('__CONDA_PREFIX__', conda_env_dir)
content = content.replace('__CONDA_DEFAULT_ENV__', os.path.basename(conda_env_dir))
return content

_create_wrappers(
files_to_wrap,
destination_dir,
run_in_template_filename,
inline,
lambda content: content.replace('__CONDA_ENV_DIR__', conda_env_dir),
template_function,
)


Expand Down
9 changes: 5 additions & 4 deletions exec_wrappers/templates/conda/run-in
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ run_activate_scripts() {
fi
}

export CONDA_DEFAULT_ENV="__CONDA_ENV_DIR__"
export CONDA_ENV_PATH="$CONDA_DEFAULT_ENV"
export CONDA_PREFIX="__CONDA_PREFIX__"
export CONDA_DEFAULT_ENV="__CONDA_DEFAULT_ENV__"
export CONDA_ENV_PATH="$CONDA_PREFIX"

export PATH="$CONDA_DEFAULT_ENV/bin:$PATH"
run_activate_scripts "$CONDA_DEFAULT_ENV/etc/conda/activate.d" &&
export PATH="$CONDA_PREFIX/bin:$PATH"
run_activate_scripts "$CONDA_PREFIX/etc/conda/activate.d" &&
__COMMAND__"$@"
10 changes: 6 additions & 4 deletions exec_wrappers/templates/conda/run-in.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

@setlocal

@set "CONDA_DEFAULT_ENV=__CONDA_ENV_DIR__"
@set "PATH=%CONDA_DEFAULT_ENV%;%CONDA_DEFAULT_ENV%\Scripts;%CONDA_DEFAULT_ENV%\Library\bin;%PATH%"
@set "CONDA_PREFIX=__CONDA_PREFIX__"
@set "CONDA_DEFAULT_ENV=__CONDA_DEFAULT_ENV__"
@set "CONDA_ENV_PATH=%CONDA_PREFIX%"
@set "PATH=%CONDA_PREFIX%;%CONDA_PREFIX%\Scripts;%CONDA_PREFIX%\Library\bin;%PATH%"

@REM Run any activate scripts
@if exist "%CONDA_DEFAULT_ENV%\etc\conda\activate.d" (
@pushd "%CONDA_DEFAULT_ENV%\etc\conda\activate.d"
@if exist "%CONDA_PREFIX%\etc\conda\activate.d" (
@pushd "%CONDA_PREFIX%\etc\conda\activate.d"
@for %%g in (*.bat) do @call "%%g"
@popd
)
Expand Down
7 changes: 4 additions & 3 deletions tests/test_create_wrappers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import os
import pytest

import stat
import sys

import pytest

from exec_wrappers import create_wrappers
from exec_wrappers.create_wrappers import list_executable_files, create_conda_wrappers, \
create_schroot_wrappers, get_templates_dir, get_wrapper_extension
Expand Down Expand Up @@ -246,7 +246,8 @@ def test_dont_create_wrapper_when_file_has_same_name(tmpdir):

with open(os.path.join(get_templates_dir(), 'conda', 'run-in' + get_wrapper_extension())) as f:
expected_run_in_content = f.read() \
.replace('__CONDA_ENV_DIR__', 'miniconda/envs/test') \
.replace('__CONDA_PREFIX__', 'miniconda/envs/test') \
.replace('__CONDA_DEFAULT_ENV__', 'test') \
.replace('__COMMAND__', '')

assert wrappers_dir.join('run-in' + get_wrapper_extension()).read() == expected_run_in_content
Expand Down

0 comments on commit 5e264b0

Please sign in to comment.