Repository: conda/conda

Issue:
Conda(py2) Installation to a path (ascii characters only) with non-ascii characters in username
Create a user with non-ascii characters in name. And try to install Miniconda2 to a path with only ascii characters
```
C:\Users\AndrésGarcía\Downloads>start /wait "" Miniconda2-4.3.30.2-Windows-x86_64.exe 
/InstallationType=JustMe /AddToPath=0 /RegisterPython=0 /NoRegistry=1 /S /D=C:\AG\mc2
```
This will throw a menuinst traceback, ignore for now. See https://github.com/ContinuumIO/menuinst/issues/54

Then try to activate the base environment:
```
C:\Users\AndrésGarcía\Downloads>cd /d C:\AG\mc2

C:\AG\mc2>Scripts\activate
Traceback (most recent call last):
  File "C:\AG\mc2\Scripts\conda-script.py", line 10, in <module>
    sys.exit(main())
  File "C:\AG\mc2\lib\site-packages\conda\cli\main.py", line 178, in main
    init_loggers()
  File "C:\AG\mc2\lib\site-packages\conda\cli\main.py", line 84, in init_loggers
    from ..console import setup_verbose_handlers
  File "C:\AG\mc2\lib\site-packages\conda\console.py", line 9, in <module>
    from .base.context import context
  File "C:\AG\mc2\lib\site-packages\conda\base\context.py", line 771, in <module>
    context = Context(SEARCH_PATH, APP_NAME, None)
  File "C:\AG\mc2\lib\site-packages\conda\common\configuration.py", line 727, in __init__
    self._set_search_path(search_path)
  File "C:\AG\mc2\lib\site-packages\conda\common\configuration.py", line 745, in _set_search_path
    self._set_raw_data(load_file_configs(search_path))
  File "C:\AG\mc2\lib\site-packages\conda\common\configuration.py", line 364, in load_file_configs
    expanded_paths = tuple(expand(path) for path in search_path)
  File "C:\AG\mc2\lib\site-packages\conda\common\configuration.py", line 364, in <genexpr>
    expanded_paths = tuple(expand(path) for path in search_path)
  File "C:\AG\mc2\lib\site-packages\conda\common\path.py", line 247, in expand
    return abspath(expanduser(expandvars(path)))
  File "C:\AG\mc2\lib\ntpath.py", line 311, in expanduser
    return userhome + path[i:]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 13: ordinal not in range(128)

C:\AG\mc2>
```


Discussion:
`C:\AG\mc2\lib\ntpath.py` is a part of the CPython stdlib, I don't really see what we can do about this. You just cannot have any unicode in `PATH` or in `%UserProfile%` on Python 2 AFAICT. @zooba what do you recommend?
Probably best to detect Python 2 and pre-encode to `sys.getfilesystemencoding()` in `conda\common\path.py`. `expandvars` will do this automatically, but it looks like `expanduser` does not.

You can preempt some of the edge-case failures by decoding back to Unicode and seeing if the path has changed (which means a username outside of the active code page), but unfortunately there's no real way to handle this properly in Python 2.x. You're sure to have plenty of other issues in this case though, so as long as you're encoding with `getfilesystemencoding` and not `ascii`, it's about the best option.

Resolving patch:
diff --git a/conda/common/path.py b/conda/common/path.py
--- a/conda/common/path.py
+++ b/conda/common/path.py
@@ -8,7 +8,7 @@
 import re
 import subprocess
 
-from .compat import on_win, string_types
+from .compat import PY2, ensure_fs_path_encoding, on_win, string_types
 from .. import CondaError
 from .._vendor.auxlib.decorators import memoize
 
@@ -46,6 +46,8 @@ def is_path(value):
 
 
 def expand(path):
+    if on_win and PY2:
+        path = ensure_fs_path_encoding(path)
     return abspath(expanduser(expandvars(path)))
 
 


Test patch: