Repository: conda/conda

Issue:
Path exploding on Windows due to conda init
## Current Behavior


Every time I issue a conda command in powershell, the windows path gets extended with duplicate entries... eventutually becoming too long to set.

**BUG FIX**
Note the line below:

```
Write-Output Env:PATH is $Env:PATH;
```
It's a debug output that was never removed that's being added to the PATH and thus the system keeps adding to the PATH over and over and over...

### Steps to Reproduce
Do conda init powershell and then using commmands the path keeps growing. It appears to be happening in Conda.psm1:

```
<#
    .SYNOPSIS
        Adds the entries of sys.prefix to PATH and returns the old PATH.

    .EXAMPLE
        $OldPath = Add-Sys-Prefix-To-Path
#>
function Add-Sys-Prefix-To-Path() {
    $OldPath = $Env:PATH;
    if ($Env:_CE_CONDA -ne '' -And $Env:OS -eq 'Windows_NT') {
        # Windows has a different layout for the python exe than other platforms.
        $sysp = Split-Path $Env:CONDA_EXE -Parent;
    } else {
        $sysp = Split-Path $Env:CONDA_EXE -Parent;
        $sysp = Split-Path $sysp -Parent;
    }
    if ($Env:OS -eq 'Windows_NT') {
        $Env:PATH = $sysp + ';' +
                    $sysp + '\Library\mingw-w64\bin;' +
                    $sysp + '\Library\usr\bin;' +
                    $sysp + '\Library\bin;' +
                    $sysp + '\Scripts;' +
                    $sysp + '\bin;' + $Env:PATH;
    } else {
        $Env:PATH = $sysp + '/bin:' + $Env:PATH;
    }
    Write-Output Env:PATH is $Env:PATH;
    return $OldPath;
}

```
## Expected Behavior
Path should not lengthen with duplicates


## Environment Information



Discussion:

Resolving patch:
diff --git a/conda/activate.py b/conda/activate.py
--- a/conda/activate.py
+++ b/conda/activate.py
@@ -479,22 +479,21 @@ def _get_starting_path_list(self):
                                 clean_paths[sys.platform] if sys.platform in clean_paths else
                                 '/usr/bin')
         path_split = path.split(os.pathsep)
-        if on_win:
-            # We used to prepend sys.prefix\Library\bin to PATH on startup but not anymore.
-            # Instead, in conda 4.6 we add the full suite of entries. This is performed in
-            # condabin\conda.bat and condabin\ _conda_activate.bat. However, we
-            # need to ignore the stuff we add there, and only consider actual PATH entries.
-            prefix_dirs = tuple(self._get_path_dirs(sys.prefix))
-            start_index = 0
-            while (start_index < len(prefix_dirs) and
-                   start_index < len(path_split) and
-                   paths_equal(path_split[start_index], prefix_dirs[start_index])):
-                start_index += 1
-            path_split = path_split[start_index:]
-            library_bin_dir = self.path_conversion(
-                    self.sep.join((sys.prefix, 'Library', 'bin')))
-            if paths_equal(path_split[0], library_bin_dir):
-                path_split = path_split[1:]
+        # We used to prepend sys.prefix\Library\bin to PATH on startup but not anymore.
+        # Instead, in conda 4.6 we add the full suite of entries. This is performed in
+        # condabin\conda.bat and condabin\ _conda_activate.bat. However, we
+        # need to ignore the stuff we add there, and only consider actual PATH entries.
+        prefix_dirs = tuple(self._get_path_dirs(sys.prefix))
+        start_index = 0
+        while (start_index < len(prefix_dirs) and
+               start_index < len(path_split) and
+               paths_equal(path_split[start_index], prefix_dirs[start_index])):
+            start_index += 1
+        path_split = path_split[start_index:]
+        library_bin_dir = self.path_conversion(
+                self.sep.join((sys.prefix, 'Library', 'bin')))
+        if paths_equal(path_split[0], library_bin_dir):
+            path_split = path_split[1:]
         return path_split
 
     def _get_path_dirs(self, prefix, extra_library_bin=False):
@@ -682,11 +681,11 @@ def _translation(found_path):  # NOQA
 
 def path_identity(paths):
     if isinstance(paths, string_types):
-        return paths
+        return os.path.normpath(paths)
     elif paths is None:
         return None
     else:
-        return tuple(paths)
+        return tuple(os.path.normpath(_) for _ in paths)
 
 
 class PosixActivator(_Activator):


Test patch:
diff --git a/conda.recipe/run_test.bat b/conda.recipe/run_test.bat
new file mode 100644
--- /dev/null
+++ b/conda.recipe/run_test.bat
@@ -0,0 +1,30 @@
+@echo on
+SET CONDA_SHLVL=
+REM don't inherit these from the build env setup
+SET _CE_CONDA=
+SET _CE_M=
+SET _CONDA_EXE=
+SET
+REM CALL stuff is necessary because conda in condabin is a bat script
+REM    running bat files within other bat files requires CALL or else
+REM    the outer script (our test script) exits when the inner completes
+CALL %PREFIX%\condabin\conda_hook.bat
+CALL conda.bat activate base
+FOR /F "delims=" %%i IN ('python -c "import sys; print(sys.version_info[0])"') DO set "PYTHON_MAJOR_VERSION=%%i"
+SET TEST_PLATFORM=win
+FOR /F "delims=" %%i IN ('python -c "import random as r; print(r.randint(0,4294967296))"') DO set "PYTHONHASHSEED=%%i"
+where conda
+CALL conda info
+CALL conda create -y -p .\built-conda-test-env python=3.5
+CALL conda.bat activate .\built-conda-test-env
+ECHO %CONDA_PREFIX%
+IF NOT "%CONDA_PREFIX%"=="%CD%\built-conda-test-env" EXIT /B 1
+FOR /F "delims=" %%i IN ('python -c "import sys; print(sys.version_info[1])"') DO set "ENV_PYTHON_MINOR_VERSION=%%i"
+IF NOT "%ENV_PYTHON_MINOR_VERSION%" == "5" EXIT /B 1
+CALL conda deactivate
+SET MSYSTEM=MINGW%ARCH%
+SET MSYS2_PATH_TYPE=inherit
+SET CHERE_INVOKING=1
+FOR /F "delims=" %%i IN ('cygpath.exe -u "%PREFIX%"') DO set "PREFIXP=%%i"
+bash -lc "source %PREFIXP%/Scripts/activate"
+py.test tests -m "not integration and not installed" -vv
\ No newline at end of file
diff --git a/conda.recipe/run_test.sh b/conda.recipe/run_test.sh
new file mode 100644
--- /dev/null
+++ b/conda.recipe/run_test.sh
@@ -0,0 +1,21 @@
+#!/usr/bin/env bash
+set -x
+
+unset CONDA_SHLVL
+unset _CE_CONDA
+unset _CE_M
+unset CONDA_EXE
+eval "$(python -m conda shell.bash hook)"
+conda activate base
+export PYTHON_MAJOR_VERSION=$(python -c "import sys; print(sys.version_info[0])")
+export TEST_PLATFORM=$(python -c "import sys; print('win' if sys.platform.startswith('win') else 'unix')")
+export PYTHONHASHSEED=$(python -c "import random as r; print(r.randint(0,4294967296))") && echo "PYTHONHASHSEED=$PYTHONHASHSEED"
+env | sort
+conda info
+conda create -y -p ./built-conda-test-env python=3.5
+conda activate ./built-conda-test-env
+echo $CONDA_PREFIX
+[ "$CONDA_PREFIX" = "$PWD/built-conda-test-env" ] || exit 1
+[ $(python -c "import sys; print(sys.version_info[1])") = 5 ] || exit 1
+conda deactivate
+py.test tests -m "not integration and not installed" -vv
diff --git a/tests/test_activate.py b/tests/test_activate.py
--- a/tests/test_activate.py
+++ b/tests/test_activate.py
@@ -1238,8 +1238,9 @@ class InteractiveShell(object):
             # 'init_command': 'env | sort && mount && which {0} && {0} -V && echo "$({0} -m conda shell.posix hook)" && eval "$({0} -m conda shell.posix hook)"'.format('/c/Users/rdonnelly/mc/python.exe'), # sys.executable.replace('\\', '/')),
             # 'init_command': 'env | sort && echo "$({0} -m conda shell.posix hook)" && eval "$({0} -m conda shell.posix hook)"'.format(self.
             #    '/c/Users/rdonnelly/mc/python.exe'),  # sys.executable.replace('\\', '/')),
-            'init_command': 'env | sort && echo "$({0} -m conda shell.posix hook {1})" && eval "$({0} -m conda shell.posix hook {1})" && env | sort'\
-                .format(exe_quoted, dev_arg),
+            'init_command': ('env | sort && echo "$({0} -m conda shell.posix hook {1})" && '
+                             'eval "$({0} -m conda shell.posix hook {1})" && env | sort'
+                             .format(exe_quoted, dev_arg)),
 
             'print_env_var': 'echo "$%s"',
         },
@@ -1253,7 +1254,8 @@ class InteractiveShell(object):
         },
         'zsh': {
             'base_shell': 'posix',  # inheritance implemented in __init__
-            'init_command': 'env | sort && eval "$(python -m conda shell.zsh hook {0})"'.format(dev_arg),
+            'init_command': ('env | sort && eval "$({0} -m conda shell.zsh hook {1})"'
+                             .format(exe_quoted, dev_arg)),
         },
         # It should be noted here that we use the latest hook with whatever conda.exe is installed
         # in sys.prefix (and we will activate all of those PATH entries).  We will set PYTHONPATH
@@ -1296,7 +1298,7 @@ class InteractiveShell(object):
         },
         'fish': {
             'activator': 'fish',
-            'init_command': 'eval (python -m conda shell.fish hook {0})'.format(dev_arg),
+            'init_command': 'eval ({0} -m conda shell.fish hook {1})'.format(exe_quoted, dev_arg),
             'print_env_var': 'echo $%s',
         },
         # We don't know if the PowerShell executable is called
@@ -1729,6 +1731,7 @@ def test_csh_basic_integration(self):
             self.basic_csh(shell)
 
     @pytest.mark.skipif(not which('tcsh'), reason='tcsh not installed')
+    @pytest.mark.xfail(reason="punting until we officially enable support for tcsh")
     def test_tcsh_basic_integration(self):
         with InteractiveShell('tcsh') as shell:
             self.basic_csh(shell)
diff --git a/tests/test_create.py b/tests/test_create.py
--- a/tests/test_create.py
+++ b/tests/test_create.py
@@ -1210,7 +1210,7 @@ def test_install_freeze_installed_flag(self):
             assert package_is_installed(prefix, "bleach=2")
             with pytest.raises(UnsatisfiableError):
                 run_command(Commands.INSTALL, prefix,
-                            "conda-forge::tensorflow>=1.4", "--dry-run", "--freeze-installed")
+                            "conda-forge::tensorflow>=1.4,<1.12", "--dry-run", "--freeze-installed")
 
     @pytest.mark.xfail(on_win, reason="nomkl not present on windows",
                        strict=True)