Skip to content

Commit

Permalink
Work on getting activate to drop the root environment
Browse files Browse the repository at this point in the history
  • Loading branch information
asmeurer committed Mar 12, 2014
1 parent bd7a92e commit b7e5d8f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
18 changes: 8 additions & 10 deletions bin/activate
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,15 @@ get_abs_filename() {
echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
}

if [[ -n $CONDA_DEFAULT_ENV ]]; then
if $_THIS_DIR/conda ..checkenv "$@"; then
_NEW_PATH=$($_THIS_DIR/conda ..deactivate)
export PATH=$_NEW_PATH
if (( $($_THIS_DIR/conda ..changeps1) )); then
PS1=$CONDA_OLD_PS1
unset CONDA_OLD_PS1
fi
else
return 1
if $_THIS_DIR/conda ..checkenv "$@"; then
_NEW_PATH=$($_THIS_DIR/conda ..deactivate)
export PATH=$_NEW_PATH
if (( $($_THIS_DIR/conda ..changeps1) )); then
PS1=$CONDA_OLD_PS1
unset CONDA_OLD_PS1
fi
else
return 1
fi

_NEW_PATH=$($_THIS_DIR/conda ..activate "$@")
Expand Down
6 changes: 2 additions & 4 deletions conda/cli/activate.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@ def main():
if len(sys.argv) != 2:
sys.exit("Error: too many arguments.")

if 'CONDA_DEFAULT_ENV' not in os.environ:
sys.exit("Error: No environment to deactivate")
try:
binpath = binpath_from_arg(os.getenv('CONDA_DEFAULT_ENV'))
binpath = binpath_from_arg(os.getenv('CONDA_DEFAULT_ENV', 'root'))
except SystemExit:
print(os.environ['PATH'])
raise
Expand All @@ -80,7 +78,7 @@ def main():
print(os.environ['PATH'])
raise
# deactivate is the same as activate root (except without setting
# CONDA_DEFAULT_ENV or PS1. XXX: The user might want to put the root
# CONDA_DEFAULT_ENV or PS1). XXX: The user might want to put the root
# env back somewhere in the middle of the PATH, not at the beginning.
if rootpath not in os.getenv('PATH').split(os.pathsep):
paths = [rootpath]
Expand Down
9 changes: 9 additions & 0 deletions tests/test_activate.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ def test_wrong_args():
assert stdout == PATH
assert stderr == 'Error: no environment provided.\n'

commands = (setup + """
source {activate} two args
printf $PATH
""").format(envs=envs, deactivate=deactivate, activate=activate)

stdout, stderr = run_in(commands, shell)
assert stdout == PATH
assert stderr == 'Error: did not expect more than one argument.\n'

commands = (setup + """
source {deactivate} test
printf $PATH
Expand Down

0 comments on commit b7e5d8f

Please sign in to comment.