Repository: conda/conda

Issue:
AttributeError: 'NoneType' object has no attribute 'endswith'
```
error: AttributeError("'NoneType' object has no attribute 'endswith'",)
command: /home/wang/anaconda2/bin/conda shell.posix activate py2
user_agent: conda/4.4.4 requests/2.18.4 CPython/2.7.13 Linux/3.19.0-42-generic ubuntu/14.04 glibc/2.19
_messageid: -9223372036842325539
_messagetime: 1514696872936 / 2017-12-30 23:07:52

Traceback (most recent call last):
  File "/home/wang/anaconda2/lib/python2.7/site-packages/conda/cli/main.py", line 111, in main
    return activator_main()
  File "/home/wang/anaconda2/lib/python2.7/site-packages/conda/activate.py", line 529, in main
    sys.stdout.write(activator.execute())
  File "/home/wang/anaconda2/lib/python2.7/site-packages/conda/activate.py", line 149, in execute
    return getattr(self, self.command)()
  File "/home/wang/anaconda2/lib/python2.7/site-packages/conda/activate.py", line 135, in activate
    return self._finalize(self._yield_commands(self.build_activate(self.env_name_or_prefix)),
  File "/home/wang/anaconda2/lib/python2.7/site-packages/conda/activate.py", line 247, in build_activate
    new_path = self.pathsep_join(self._replace_prefix_in_path(old_conda_prefix, prefix))
  File "/home/wang/anaconda2/lib/python2.7/site-packages/conda/activate.py", line 411, in _replace_prefix_in_path
    idx = path_list.index(join(old_prefix, 'bin'))
  File "/home/wang/anaconda2/lib/python2.7/posixpath.py", line 70, in join
    elif path == '' or path.endswith('/'):
AttributeError: 'NoneType' object has no attribute 'endswith'
```


Discussion:

Resolving patch:
diff --git a/conda/activate.py b/conda/activate.py
--- a/conda/activate.py
+++ b/conda/activate.py
@@ -413,24 +413,30 @@ def _replace_prefix_in_path(self, old_prefix, new_prefix, starting_path_dirs=Non
         else:
             path_list = list(starting_path_dirs)
         if on_win:  # pragma: unix no cover
-            # windows has a nasty habit of adding extra Library\bin directories
-            prefix_dirs = tuple(self._get_path_dirs(old_prefix))
-            try:
-                first_idx = path_list.index(prefix_dirs[0])
-            except ValueError:
-                first_idx = 0
+            if old_prefix is not None:
+                # windows has a nasty habit of adding extra Library\bin directories
+                prefix_dirs = tuple(self._get_path_dirs(old_prefix))
+                try:
+                    first_idx = path_list.index(prefix_dirs[0])
+                except ValueError:
+                    first_idx = 0
+                else:
+                    last_idx = path_list.index(prefix_dirs[-1])
+                    del path_list[first_idx:last_idx+1]
             else:
-                last_idx = path_list.index(prefix_dirs[-1])
-                del path_list[first_idx:last_idx+1]
+                first_idx = 0
             if new_prefix is not None:
                 path_list[first_idx:first_idx] = list(self._get_path_dirs(new_prefix))
         else:
-            try:
-                idx = path_list.index(join(old_prefix, 'bin'))
-            except ValueError:
-                idx = 0
+            if old_prefix is not None:
+                try:
+                    idx = path_list.index(join(old_prefix, 'bin'))
+                except ValueError:
+                    idx = 0
+                else:
+                    del path_list[idx]
             else:
-                del path_list[idx]
+                idx = 0
             if new_prefix is not None:
                 path_list.insert(idx, join(new_prefix, 'bin'))
         return self.path_conversion(path_list)


Test patch: