We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Amalgamate build on Anaconda.org fails
It builds fine on my machine so I am not really sure what is going on here: 

https://anaconda.org/xonsh/xonsh/builds/403/0

``` bash
+ python setup.py install --single-version-externally-managed --record=record.txt
Traceback (most recent call last):
  File "setup.py", line 210, in <module>
    main()
  File "setup.py", line 206, in main
    setup(**skw)
  File "/opt/miniconda/envs/_build/lib/python3.4/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/opt/miniconda/envs/_build/lib/python3.4/distutils/dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "/opt/miniconda/envs/_build/lib/python3.4/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "setup.py", line 99, in run
    build_tables()
  File "setup.py", line 59, in build_tables
    amalgamate.main(['amalgamate', '--debug=XONSH_DEBUG', 'xonsh'])
  File "/opt/miniconda/conda-bld/work/amalgamate.py", line 369, in main
    graph = make_graph(pkg, exclude=exclude)
  File "/opt/miniconda/conda-bld/work/amalgamate.py", line 94, in make_graph
    graph[base] = make_node(base, pkg, allowed)
  File "/opt/miniconda/conda-bld/work/amalgamate.py", line 54, in make_node
    raw = SOURCES[pkg, name]
  File "/opt/miniconda/conda-bld/work/amalgamate.py", line 39, in __getitem__
    raw = f.read()
  File "/opt/miniconda/envs/_build/lib/python3.4/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc7 in position 2102: ordinal not in range(128)
Command failed: /bin/bash -x -e /opt/miniconda/conda-bld/work/conda_build.sh
discarding /home/dev/env/bin from PATH

```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `xonsh/platform.py`
Content:
```
1 """Module for platform-specific constants and implementations, as well as
2 compatibility layers to make use of the 'best' implementation available
3 on a platform.
4 """
5 import os
6 import sys
7 import pathlib
8 import platform
9 import functools
10 import subprocess
11 import importlib.util
12 
13 from xonsh.lazyasd import LazyObject, LazyBool
14 
15 def _distro():
16     try:
17         import distro as d
18     except ImportError:
19         d = None
20     except:
21         raise
22     return d
23 
24 
25 distro = LazyObject(_distro, globals(), 'distro')
26 del _distro
27 
28 # do not import any xonsh-modules here to avoid circular dependencies
29 
30 
31 #
32 # OS
33 #
34 ON_DARWIN = LazyBool(lambda: platform.system() == 'Darwin',
35                      globals(), 'ON_DARWIN')
36 """ ``True`` if executed on a Darwin platform, else ``False``. """
37 ON_LINUX = LazyBool(lambda: platform.system() == 'Linux',
38                     globals(), 'ON_LINUX')
39 """ ``True`` if executed on a Linux platform, else ``False``. """
40 ON_WINDOWS = LazyBool(lambda: platform.system() == 'Windows',
41                       globals(), 'ON_WINDOWS')
42 """ ``True`` if executed on a native Windows platform, else ``False``. """
43 ON_CYGWIN = LazyBool(lambda: sys.platform == 'cygwin', globals(), 'ON_CYGWIN')
44 """ ``True`` if executed on a Cygwin Windows platform, else ``False``. """
45 ON_POSIX = LazyBool(lambda: (os.name == 'posix'), globals(), 'ON_POSIX')
46 """ ``True`` if executed on a POSIX-compliant platform, else ``False``. """
47 
48 
49 #
50 # Python & packages
51 #
52 
53 PYTHON_VERSION_INFO = sys.version_info[:3]
54 """ Version of Python interpreter as three-value tuple. """
55 ON_ANACONDA = LazyBool(
56     lambda: any(s in sys.version for s in {'Anaconda', 'Continuum'}),
57     globals(), 'ON_ANACONDA')
58 """ ``True`` if executed in an Anaconda instance, else ``False``. """
59 
60 def _has_pygments():
61     spec = importlib.util.find_spec('pygments')
62     return (spec is not None)
63 
64 
65 HAS_PYGMENTS = LazyBool(_has_pygments, globals(), 'HAS_PYGMENTS')
66 """ ``True`` if `pygments` is available, else ``False``. """
67 del _has_pygments
68 
69 
70 @functools.lru_cache(1)
71 def pygments_version():
72     """pygments.__version__ version if available, else Ǹone."""
73     if HAS_PYGMENTS:
74         import pygments
75         v = pygments.__version__
76     else:
77         v = None
78     return v
79 
80 
81 @functools.lru_cache(1)
82 def has_prompt_toolkit():
83     """ Tests if the `prompt_toolkit` is available. """
84     spec = importlib.util.find_spec('pygments')
85     return (spec is not None)
86 
87 
88 @functools.lru_cache(1)
89 def ptk_version():
90     """ Returns `prompt_toolkit.__version__` if available, else ``None``. """
91     if has_prompt_toolkit():
92         import prompt_toolkit
93         return getattr(prompt_toolkit, '__version__', '<0.57')
94     else:
95         return None
96 
97 
98 @functools.lru_cache(1)
99 def ptk_version_info():
100     """ Returns `prompt_toolkit`'s version as tuple of integers. """
101     if has_prompt_toolkit():
102         return tuple(int(x) for x in ptk_version().strip('<>+-=.').split('.'))
103     else:
104         return None
105 
106 
107 @functools.lru_cache(1)
108 def best_shell_type():
109     if ON_WINDOWS or has_prompt_toolkit():
110         return 'prompt_toolkit'
111     else:
112         return 'readline'
113 
114 
115 @functools.lru_cache(1)
116 def is_readline_available():
117     """Checks if readline is available to import."""
118     spec = importlib.util.find_spec('readline')
119     return (spec is not None)
120 
121 
122 #
123 # Encoding
124 #
125 
126 DEFAULT_ENCODING = sys.getdefaultencoding()
127 """ Default string encoding. """
128 
129 
130 if PYTHON_VERSION_INFO < (3, 5, 0):
131     class DirEntry:
132         def __init__(self, directory, name):
133             self.__path__ = pathlib.Path(directory) / name
134             self.name = name
135             self.path = str(self.__path__)
136             self.is_symlink = self.__path__.is_symlink
137 
138         def inode(self):
139             return os.stat(self.path, follow_symlinks=False).st_ino
140 
141         def is_dir(self, *, follow_symlinks=True):
142             if follow_symlinks:
143                 return self.__path__.is_dir()
144             else:
145                 return not self.__path__.is_symlink() \
146                        and self.__path__.is_dir()
147 
148         def is_file(self, *, follow_symlinks=True):
149             if follow_symlinks:
150                 return self.__path__.is_file()
151             else:
152                 return not self.__path__.is_symlink() \
153                        and self.__path__.is_file()
154 
155         def stat(self, *, follow_symlinks=True):
156             return os.stat(self.path, follow_symlinks=follow_symlinks)
157 
158     def scandir(path):
159         """ Compatibility layer for  `os.scandir` from Python 3.5+. """
160         return (DirEntry(path, x) for x in os.listdir(path))
161 else:
162     scandir = os.scandir
163 
164 
165 #
166 # Linux distro
167 #
168 
169 @functools.lru_cache(1)
170 def linux_distro():
171     """The id of the Linux distribution running on, possibly 'unknown'.
172     None on non-Linux platforms.
173     """
174     if ON_LINUX:
175         if distro:
176             ld = distro.id()
177         elif PYTHON_VERSION_INFO < (3, 7, 0):
178             ld = platform.linux_distribution()[0] or 'unknown'
179         elif '-ARCH-' in platform.platform():
180             ld = 'arch'  # that's the only one we need to know for now
181         else:
182             ld = 'unknown'
183     else:
184         ld = None
185     return ld
186 
187 
188 #
189 # Windows
190 #
191 
192 @functools.lru_cache(1)
193 def git_for_windows_path():
194     """Returns the path to git for windows, if available and None otherwise."""
195     import winreg
196     try:
197         key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
198                              'SOFTWARE\\GitForWindows')
199         gfwp, _ = winreg.QueryValueEx(key, "InstallPath")
200     except FileNotFoundError:
201         gfwp = None
202     return gfwp
203 
204 
205 @functools.lru_cache(1)
206 def windows_bash_command():
207     """Determines teh command for Bash on windows."""
208     import winreg
209     # Check that bash is on path otherwise try the default directory
210     # used by Git for windows
211     wbc = 'bash'
212     try:
213         subprocess.check_call([wbc, '--version'],
214                               stdout=subprocess.PIPE,
215                               stderr=subprocess.PIPE)
216     except (FileNotFoundError, subprocess.CalledProcessError):
217         gfwp = git_for_windows_path()
218         if gfwp:
219             bashcmd = os.path.join(gfwp, 'bin\\bash.exe')
220             if os.path.isfile(bashcmd):
221                 wbc = bashcmd
222     return wbc
223 
224 #
225 # Environment variables defaults
226 #
227 
228 def _bcd():
229     """A possibly empty tuple with default paths to Bash completions known for
230     the current platform.
231     """
232     if ON_LINUX or ON_CYGWIN:
233         if linux_distro() == 'arch':
234             bcd = (
235                 '/usr/share/bash-completion/bash_completion',
236                 '/usr/share/bash-completion/completions')
237         else:
238             bcd = ('/usr/share/bash-completion',
239                    '/usr/share/bash-completion/completions')
240     elif ON_DARWIN:
241         bcd = ('/usr/local/etc/bash_completion',
242                '/opt/local/etc/profile.d/bash_completion.sh')
243     elif ON_WINDOWS and git_for_windows_path():
244         bcd = (os.path.join(git_for_windows_path(),
245                     'usr\\share\\bash-completion'),
246                os.path.join(git_for_windows_path(),
247                     'usr\\share\\bash-completion\\completions'),
248                os.path.join(git_for_windows_path(),
249                      'mingw64\\share\\git\\completion\\git-completion.bash'))
250     else:
251         bcd = ()
252     return bcd
253 
254 
255 BASH_COMPLETIONS_DEFAULT = LazyObject(_bcd, globals(),
256                                       'BASH_COMPLETIONS_DEFAULT')
257 del _bcd
258 
259 
260 def _pd():
261     if ON_LINUX or ON_CYGWIN:
262         if linux_distro() == 'arch':
263             pd = ('/usr/local/sbin',
264                   '/usr/local/bin', '/usr/bin', '/usr/bin/site_perl',
265                   '/usr/bin/vendor_perl', '/usr/bin/core_perl')
266         else:
267             pd = (os.path.expanduser('~/bin'), '/usr/local/sbin',
268                   '/usr/local/bin', '/usr/sbin', '/usr/bin', '/sbin', '/bin',
269                   '/usr/games', '/usr/local/games')
270     elif ON_DARWIN:
271         pd = ('/usr/local/bin', '/usr/bin', '/bin', '/usr/sbin', '/sbin')
272     elif ON_WINDOWS:
273         import winreg
274         key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
275                 r'SYSTEM\CurrentControlSet\Control\Session Manager\Environment')
276         pd = tuple(winreg.QueryValueEx(key, 'Path')[0].split(os.pathsep))
277     else:
278         pd = ()
279     return pd
280 
281 PATH_DEFAULT = LazyObject(_pd, globals(), 'PATH_DEFAULT')
282 del _pd
283
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/xonsh/platform.py b/xonsh/platform.py
--- a/xonsh/platform.py
+++ b/xonsh/platform.py
@@ -69,7 +69,7 @@
 
 @functools.lru_cache(1)
 def pygments_version():
-    """pygments.__version__ version if available, else Ǹone."""
+    """pygments.__version__ version if available, else None."""
     if HAS_PYGMENTS:
         import pygments
         v = pygments.__version__

{"golden_diff": "diff --git a/xonsh/platform.py b/xonsh/platform.py\n--- a/xonsh/platform.py\n+++ b/xonsh/platform.py\n@@ -69,7 +69,7 @@\n \n @functools.lru_cache(1)\n def pygments_version():\n-    \"\"\"pygments.__version__ version if available, else \u01f8one.\"\"\"\n+    \"\"\"pygments.__version__ version if available, else None.\"\"\"\n     if HAS_PYGMENTS:\n         import pygments\n         v = pygments.__version__\n", "issue": "Amalgamate build on Anaconda.org fails\nIt builds fine on my machine so I am not really sure what is going on here: \n\nhttps://anaconda.org/xonsh/xonsh/builds/403/0\n\n``` bash\n+ python setup.py install --single-version-externally-managed --record=record.txt\nTraceback (most recent call last):\n  File \"setup.py\", line 210, in <module>\n    main()\n  File \"setup.py\", line 206, in main\n    setup(**skw)\n  File \"/opt/miniconda/envs/_build/lib/python3.4/distutils/core.py\", line 148, in setup\n    dist.run_commands()\n  File \"/opt/miniconda/envs/_build/lib/python3.4/distutils/dist.py\", line 955, in run_commands\n    self.run_command(cmd)\n  File \"/opt/miniconda/envs/_build/lib/python3.4/distutils/dist.py\", line 974, in run_command\n    cmd_obj.run()\n  File \"setup.py\", line 99, in run\n    build_tables()\n  File \"setup.py\", line 59, in build_tables\n    amalgamate.main(['amalgamate', '--debug=XONSH_DEBUG', 'xonsh'])\n  File \"/opt/miniconda/conda-bld/work/amalgamate.py\", line 369, in main\n    graph = make_graph(pkg, exclude=exclude)\n  File \"/opt/miniconda/conda-bld/work/amalgamate.py\", line 94, in make_graph\n    graph[base] = make_node(base, pkg, allowed)\n  File \"/opt/miniconda/conda-bld/work/amalgamate.py\", line 54, in make_node\n    raw = SOURCES[pkg, name]\n  File \"/opt/miniconda/conda-bld/work/amalgamate.py\", line 39, in __getitem__\n    raw = f.read()\n  File \"/opt/miniconda/envs/_build/lib/python3.4/encodings/ascii.py\", line 26, in decode\n    return codecs.ascii_decode(input, self.errors)[0]\nUnicodeDecodeError: 'ascii' codec can't decode byte 0xc7 in position 2102: ordinal not in range(128)\nCommand failed: /bin/bash -x -e /opt/miniconda/conda-bld/work/conda_build.sh\ndiscarding /home/dev/env/bin from PATH\n\n```\n\n", "before_files": [{"content": "\"\"\"Module for platform-specific constants and implementations, as well as\ncompatibility layers to make use of the 'best' implementation available\non a platform.\n\"\"\"\nimport os\nimport sys\nimport pathlib\nimport platform\nimport functools\nimport subprocess\nimport importlib.util\n\nfrom xonsh.lazyasd import LazyObject, LazyBool\n\ndef _distro():\n    try:\n        import distro as d\n    except ImportError:\n        d = None\n    except:\n        raise\n    return d\n\n\ndistro = LazyObject(_distro, globals(), 'distro')\ndel _distro\n\n# do not import any xonsh-modules here to avoid circular dependencies\n\n\n#\n# OS\n#\nON_DARWIN = LazyBool(lambda: platform.system() == 'Darwin',\n                     globals(), 'ON_DARWIN')\n\"\"\" ``True`` if executed on a Darwin platform, else ``False``. \"\"\"\nON_LINUX = LazyBool(lambda: platform.system() == 'Linux',\n                    globals(), 'ON_LINUX')\n\"\"\" ``True`` if executed on a Linux platform, else ``False``. \"\"\"\nON_WINDOWS = LazyBool(lambda: platform.system() == 'Windows',\n                      globals(), 'ON_WINDOWS')\n\"\"\" ``True`` if executed on a native Windows platform, else ``False``. \"\"\"\nON_CYGWIN = LazyBool(lambda: sys.platform == 'cygwin', globals(), 'ON_CYGWIN')\n\"\"\" ``True`` if executed on a Cygwin Windows platform, else ``False``. \"\"\"\nON_POSIX = LazyBool(lambda: (os.name == 'posix'), globals(), 'ON_POSIX')\n\"\"\" ``True`` if executed on a POSIX-compliant platform, else ``False``. \"\"\"\n\n\n#\n# Python & packages\n#\n\nPYTHON_VERSION_INFO = sys.version_info[:3]\n\"\"\" Version of Python interpreter as three-value tuple. \"\"\"\nON_ANACONDA = LazyBool(\n    lambda: any(s in sys.version for s in {'Anaconda', 'Continuum'}),\n    globals(), 'ON_ANACONDA')\n\"\"\" ``True`` if executed in an Anaconda instance, else ``False``. \"\"\"\n\ndef _has_pygments():\n    spec = importlib.util.find_spec('pygments')\n    return (spec is not None)\n\n\nHAS_PYGMENTS = LazyBool(_has_pygments, globals(), 'HAS_PYGMENTS')\n\"\"\" ``True`` if `pygments` is available, else ``False``. \"\"\"\ndel _has_pygments\n\n\n@functools.lru_cache(1)\ndef pygments_version():\n    \"\"\"pygments.__version__ version if available, else \u01f8one.\"\"\"\n    if HAS_PYGMENTS:\n        import pygments\n        v = pygments.__version__\n    else:\n        v = None\n    return v\n\n\n@functools.lru_cache(1)\ndef has_prompt_toolkit():\n    \"\"\" Tests if the `prompt_toolkit` is available. \"\"\"\n    spec = importlib.util.find_spec('pygments')\n    return (spec is not None)\n\n\n@functools.lru_cache(1)\ndef ptk_version():\n    \"\"\" Returns `prompt_toolkit.__version__` if available, else ``None``. \"\"\"\n    if has_prompt_toolkit():\n        import prompt_toolkit\n        return getattr(prompt_toolkit, '__version__', '<0.57')\n    else:\n        return None\n\n\n@functools.lru_cache(1)\ndef ptk_version_info():\n    \"\"\" Returns `prompt_toolkit`'s version as tuple of integers. \"\"\"\n    if has_prompt_toolkit():\n        return tuple(int(x) for x in ptk_version().strip('<>+-=.').split('.'))\n    else:\n        return None\n\n\n@functools.lru_cache(1)\ndef best_shell_type():\n    if ON_WINDOWS or has_prompt_toolkit():\n        return 'prompt_toolkit'\n    else:\n        return 'readline'\n\n\n@functools.lru_cache(1)\ndef is_readline_available():\n    \"\"\"Checks if readline is available to import.\"\"\"\n    spec = importlib.util.find_spec('readline')\n    return (spec is not None)\n\n\n#\n# Encoding\n#\n\nDEFAULT_ENCODING = sys.getdefaultencoding()\n\"\"\" Default string encoding. \"\"\"\n\n\nif PYTHON_VERSION_INFO < (3, 5, 0):\n    class DirEntry:\n        def __init__(self, directory, name):\n            self.__path__ = pathlib.Path(directory) / name\n            self.name = name\n            self.path = str(self.__path__)\n            self.is_symlink = self.__path__.is_symlink\n\n        def inode(self):\n            return os.stat(self.path, follow_symlinks=False).st_ino\n\n        def is_dir(self, *, follow_symlinks=True):\n            if follow_symlinks:\n                return self.__path__.is_dir()\n            else:\n                return not self.__path__.is_symlink() \\\n                       and self.__path__.is_dir()\n\n        def is_file(self, *, follow_symlinks=True):\n            if follow_symlinks:\n                return self.__path__.is_file()\n            else:\n                return not self.__path__.is_symlink() \\\n                       and self.__path__.is_file()\n\n        def stat(self, *, follow_symlinks=True):\n            return os.stat(self.path, follow_symlinks=follow_symlinks)\n\n    def scandir(path):\n        \"\"\" Compatibility layer for  `os.scandir` from Python 3.5+. \"\"\"\n        return (DirEntry(path, x) for x in os.listdir(path))\nelse:\n    scandir = os.scandir\n\n\n#\n# Linux distro\n#\n\n@functools.lru_cache(1)\ndef linux_distro():\n    \"\"\"The id of the Linux distribution running on, possibly 'unknown'.\n    None on non-Linux platforms.\n    \"\"\"\n    if ON_LINUX:\n        if distro:\n            ld = distro.id()\n        elif PYTHON_VERSION_INFO < (3, 7, 0):\n            ld = platform.linux_distribution()[0] or 'unknown'\n        elif '-ARCH-' in platform.platform():\n            ld = 'arch'  # that's the only one we need to know for now\n        else:\n            ld = 'unknown'\n    else:\n        ld = None\n    return ld\n\n\n#\n# Windows\n#\n\n@functools.lru_cache(1)\ndef git_for_windows_path():\n    \"\"\"Returns the path to git for windows, if available and None otherwise.\"\"\"\n    import winreg\n    try:\n        key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,\n                             'SOFTWARE\\\\GitForWindows')\n        gfwp, _ = winreg.QueryValueEx(key, \"InstallPath\")\n    except FileNotFoundError:\n        gfwp = None\n    return gfwp\n\n\n@functools.lru_cache(1)\ndef windows_bash_command():\n    \"\"\"Determines teh command for Bash on windows.\"\"\"\n    import winreg\n    # Check that bash is on path otherwise try the default directory\n    # used by Git for windows\n    wbc = 'bash'\n    try:\n        subprocess.check_call([wbc, '--version'],\n                              stdout=subprocess.PIPE,\n                              stderr=subprocess.PIPE)\n    except (FileNotFoundError, subprocess.CalledProcessError):\n        gfwp = git_for_windows_path()\n        if gfwp:\n            bashcmd = os.path.join(gfwp, 'bin\\\\bash.exe')\n            if os.path.isfile(bashcmd):\n                wbc = bashcmd\n    return wbc\n\n#\n# Environment variables defaults\n#\n\ndef _bcd():\n    \"\"\"A possibly empty tuple with default paths to Bash completions known for\n    the current platform.\n    \"\"\"\n    if ON_LINUX or ON_CYGWIN:\n        if linux_distro() == 'arch':\n            bcd = (\n                '/usr/share/bash-completion/bash_completion',\n                '/usr/share/bash-completion/completions')\n        else:\n            bcd = ('/usr/share/bash-completion',\n                   '/usr/share/bash-completion/completions')\n    elif ON_DARWIN:\n        bcd = ('/usr/local/etc/bash_completion',\n               '/opt/local/etc/profile.d/bash_completion.sh')\n    elif ON_WINDOWS and git_for_windows_path():\n        bcd = (os.path.join(git_for_windows_path(),\n                    'usr\\\\share\\\\bash-completion'),\n               os.path.join(git_for_windows_path(),\n                    'usr\\\\share\\\\bash-completion\\\\completions'),\n               os.path.join(git_for_windows_path(),\n                     'mingw64\\\\share\\\\git\\\\completion\\\\git-completion.bash'))\n    else:\n        bcd = ()\n    return bcd\n\n\nBASH_COMPLETIONS_DEFAULT = LazyObject(_bcd, globals(),\n                                      'BASH_COMPLETIONS_DEFAULT')\ndel _bcd\n\n\ndef _pd():\n    if ON_LINUX or ON_CYGWIN:\n        if linux_distro() == 'arch':\n            pd = ('/usr/local/sbin',\n                  '/usr/local/bin', '/usr/bin', '/usr/bin/site_perl',\n                  '/usr/bin/vendor_perl', '/usr/bin/core_perl')\n        else:\n            pd = (os.path.expanduser('~/bin'), '/usr/local/sbin',\n                  '/usr/local/bin', '/usr/sbin', '/usr/bin', '/sbin', '/bin',\n                  '/usr/games', '/usr/local/games')\n    elif ON_DARWIN:\n        pd = ('/usr/local/bin', '/usr/bin', '/bin', '/usr/sbin', '/sbin')\n    elif ON_WINDOWS:\n        import winreg\n        key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,\n                r'SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment')\n        pd = tuple(winreg.QueryValueEx(key, 'Path')[0].split(os.pathsep))\n    else:\n        pd = ()\n    return pd\n\nPATH_DEFAULT = LazyObject(_pd, globals(), 'PATH_DEFAULT')\ndel _pd\n", "path": "xonsh/platform.py"}], "after_files": [{"content": "\"\"\"Module for platform-specific constants and implementations, as well as\ncompatibility layers to make use of the 'best' implementation available\non a platform.\n\"\"\"\nimport os\nimport sys\nimport pathlib\nimport platform\nimport functools\nimport subprocess\nimport importlib.util\n\nfrom xonsh.lazyasd import LazyObject, LazyBool\n\ndef _distro():\n    try:\n        import distro as d\n    except ImportError:\n        d = None\n    except:\n        raise\n    return d\n\n\ndistro = LazyObject(_distro, globals(), 'distro')\ndel _distro\n\n# do not import any xonsh-modules here to avoid circular dependencies\n\n\n#\n# OS\n#\nON_DARWIN = LazyBool(lambda: platform.system() == 'Darwin',\n                     globals(), 'ON_DARWIN')\n\"\"\" ``True`` if executed on a Darwin platform, else ``False``. \"\"\"\nON_LINUX = LazyBool(lambda: platform.system() == 'Linux',\n                    globals(), 'ON_LINUX')\n\"\"\" ``True`` if executed on a Linux platform, else ``False``. \"\"\"\nON_WINDOWS = LazyBool(lambda: platform.system() == 'Windows',\n                      globals(), 'ON_WINDOWS')\n\"\"\" ``True`` if executed on a native Windows platform, else ``False``. \"\"\"\nON_CYGWIN = LazyBool(lambda: sys.platform == 'cygwin', globals(), 'ON_CYGWIN')\n\"\"\" ``True`` if executed on a Cygwin Windows platform, else ``False``. \"\"\"\nON_POSIX = LazyBool(lambda: (os.name == 'posix'), globals(), 'ON_POSIX')\n\"\"\" ``True`` if executed on a POSIX-compliant platform, else ``False``. \"\"\"\n\n\n#\n# Python & packages\n#\n\nPYTHON_VERSION_INFO = sys.version_info[:3]\n\"\"\" Version of Python interpreter as three-value tuple. \"\"\"\nON_ANACONDA = LazyBool(\n    lambda: any(s in sys.version for s in {'Anaconda', 'Continuum'}),\n    globals(), 'ON_ANACONDA')\n\"\"\" ``True`` if executed in an Anaconda instance, else ``False``. \"\"\"\n\ndef _has_pygments():\n    spec = importlib.util.find_spec('pygments')\n    return (spec is not None)\n\n\nHAS_PYGMENTS = LazyBool(_has_pygments, globals(), 'HAS_PYGMENTS')\n\"\"\" ``True`` if `pygments` is available, else ``False``. \"\"\"\ndel _has_pygments\n\n\n@functools.lru_cache(1)\ndef pygments_version():\n    \"\"\"pygments.__version__ version if available, else None.\"\"\"\n    if HAS_PYGMENTS:\n        import pygments\n        v = pygments.__version__\n    else:\n        v = None\n    return v\n\n\n@functools.lru_cache(1)\ndef has_prompt_toolkit():\n    \"\"\" Tests if the `prompt_toolkit` is available. \"\"\"\n    spec = importlib.util.find_spec('pygments')\n    return (spec is not None)\n\n\n@functools.lru_cache(1)\ndef ptk_version():\n    \"\"\" Returns `prompt_toolkit.__version__` if available, else ``None``. \"\"\"\n    if has_prompt_toolkit():\n        import prompt_toolkit\n        return getattr(prompt_toolkit, '__version__', '<0.57')\n    else:\n        return None\n\n\n@functools.lru_cache(1)\ndef ptk_version_info():\n    \"\"\" Returns `prompt_toolkit`'s version as tuple of integers. \"\"\"\n    if has_prompt_toolkit():\n        return tuple(int(x) for x in ptk_version().strip('<>+-=.').split('.'))\n    else:\n        return None\n\n\n@functools.lru_cache(1)\ndef best_shell_type():\n    if ON_WINDOWS or has_prompt_toolkit():\n        return 'prompt_toolkit'\n    else:\n        return 'readline'\n\n\n@functools.lru_cache(1)\ndef is_readline_available():\n    \"\"\"Checks if readline is available to import.\"\"\"\n    spec = importlib.util.find_spec('readline')\n    return (spec is not None)\n\n\n#\n# Encoding\n#\n\nDEFAULT_ENCODING = sys.getdefaultencoding()\n\"\"\" Default string encoding. \"\"\"\n\n\nif PYTHON_VERSION_INFO < (3, 5, 0):\n    class DirEntry:\n        def __init__(self, directory, name):\n            self.__path__ = pathlib.Path(directory) / name\n            self.name = name\n            self.path = str(self.__path__)\n            self.is_symlink = self.__path__.is_symlink\n\n        def inode(self):\n            return os.stat(self.path, follow_symlinks=False).st_ino\n\n        def is_dir(self, *, follow_symlinks=True):\n            if follow_symlinks:\n                return self.__path__.is_dir()\n            else:\n                return not self.__path__.is_symlink() \\\n                       and self.__path__.is_dir()\n\n        def is_file(self, *, follow_symlinks=True):\n            if follow_symlinks:\n                return self.__path__.is_file()\n            else:\n                return not self.__path__.is_symlink() \\\n                       and self.__path__.is_file()\n\n        def stat(self, *, follow_symlinks=True):\n            return os.stat(self.path, follow_symlinks=follow_symlinks)\n\n    def scandir(path):\n        \"\"\" Compatibility layer for  `os.scandir` from Python 3.5+. \"\"\"\n        return (DirEntry(path, x) for x in os.listdir(path))\nelse:\n    scandir = os.scandir\n\n\n#\n# Linux distro\n#\n\n@functools.lru_cache(1)\ndef linux_distro():\n    \"\"\"The id of the Linux distribution running on, possibly 'unknown'.\n    None on non-Linux platforms.\n    \"\"\"\n    if ON_LINUX:\n        if distro:\n            ld = distro.id()\n        elif PYTHON_VERSION_INFO < (3, 7, 0):\n            ld = platform.linux_distribution()[0] or 'unknown'\n        elif '-ARCH-' in platform.platform():\n            ld = 'arch'  # that's the only one we need to know for now\n        else:\n            ld = 'unknown'\n    else:\n        ld = None\n    return ld\n\n\n#\n# Windows\n#\n\n@functools.lru_cache(1)\ndef git_for_windows_path():\n    \"\"\"Returns the path to git for windows, if available and None otherwise.\"\"\"\n    import winreg\n    try:\n        key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,\n                             'SOFTWARE\\\\GitForWindows')\n        gfwp, _ = winreg.QueryValueEx(key, \"InstallPath\")\n    except FileNotFoundError:\n        gfwp = None\n    return gfwp\n\n\n@functools.lru_cache(1)\ndef windows_bash_command():\n    \"\"\"Determines teh command for Bash on windows.\"\"\"\n    import winreg\n    # Check that bash is on path otherwise try the default directory\n    # used by Git for windows\n    wbc = 'bash'\n    try:\n        subprocess.check_call([wbc, '--version'],\n                              stdout=subprocess.PIPE,\n                              stderr=subprocess.PIPE)\n    except (FileNotFoundError, subprocess.CalledProcessError):\n        gfwp = git_for_windows_path()\n        if gfwp:\n            bashcmd = os.path.join(gfwp, 'bin\\\\bash.exe')\n            if os.path.isfile(bashcmd):\n                wbc = bashcmd\n    return wbc\n\n#\n# Environment variables defaults\n#\n\ndef _bcd():\n    \"\"\"A possibly empty tuple with default paths to Bash completions known for\n    the current platform.\n    \"\"\"\n    if ON_LINUX or ON_CYGWIN:\n        if linux_distro() == 'arch':\n            bcd = (\n                '/usr/share/bash-completion/bash_completion',\n                '/usr/share/bash-completion/completions')\n        else:\n            bcd = ('/usr/share/bash-completion',\n                   '/usr/share/bash-completion/completions')\n    elif ON_DARWIN:\n        bcd = ('/usr/local/etc/bash_completion',\n               '/opt/local/etc/profile.d/bash_completion.sh')\n    elif ON_WINDOWS and git_for_windows_path():\n        bcd = (os.path.join(git_for_windows_path(),\n                    'usr\\\\share\\\\bash-completion'),\n               os.path.join(git_for_windows_path(),\n                    'usr\\\\share\\\\bash-completion\\\\completions'),\n               os.path.join(git_for_windows_path(),\n                     'mingw64\\\\share\\\\git\\\\completion\\\\git-completion.bash'))\n    else:\n        bcd = ()\n    return bcd\n\n\nBASH_COMPLETIONS_DEFAULT = LazyObject(_bcd, globals(),\n                                      'BASH_COMPLETIONS_DEFAULT')\ndel _bcd\n\n\ndef _pd():\n    if ON_LINUX or ON_CYGWIN:\n        if linux_distro() == 'arch':\n            pd = ('/usr/local/sbin',\n                  '/usr/local/bin', '/usr/bin', '/usr/bin/site_perl',\n                  '/usr/bin/vendor_perl', '/usr/bin/core_perl')\n        else:\n            pd = (os.path.expanduser('~/bin'), '/usr/local/sbin',\n                  '/usr/local/bin', '/usr/sbin', '/usr/bin', '/sbin', '/bin',\n                  '/usr/games', '/usr/local/games')\n    elif ON_DARWIN:\n        pd = ('/usr/local/bin', '/usr/bin', '/bin', '/usr/sbin', '/sbin')\n    elif ON_WINDOWS:\n        import winreg\n        key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,\n                r'SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment')\n        pd = tuple(winreg.QueryValueEx(key, 'Path')[0].split(os.pathsep))\n    else:\n        pd = ()\n    return pd\n\nPATH_DEFAULT = LazyObject(_pd, globals(), 'PATH_DEFAULT')\ndel _pd\n", "path": "xonsh/platform.py"}]}