diff --git a/bin/activate b/bin/activate index b88933b8011..294bd5da2b6 100755 --- a/bin/activate +++ b/bin/activate @@ -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 "$@") diff --git a/conda/cli/activate.py b/conda/cli/activate.py index 4f5f28e6c36..56f80d964b3 100644 --- a/conda/cli/activate.py +++ b/conda/cli/activate.py @@ -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 @@ -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] diff --git a/tests/test_activate.py b/tests/test_activate.py index 93bcd840433..5a4856be925 100644 --- a/tests/test_activate.py +++ b/tests/test_activate.py @@ -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