We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
git completion on windows broken
Git completions on windows has stopped working:
```
snail@sea ~\Documents\xonsh master $ $BASH_COMPLETIONS
['C:\\Program Files\\Git\\usr\\share\\bash-completion\\bash_completion', 
'C:\\Program Files\\Git\\mingw64\\share\\git\\completion\\git-completion.bash']
```

I guess it could be some of the recent fixes to bash completion scripts. Do we require bash completion 2.0? 

On windows we use the git bash completions that come bundled with 'Git for Windows'. I don't think that 2.0


--- 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 signal
8 import pathlib
9 import platform
10 import functools
11 import subprocess
12 import importlib.util
13 
14 from xonsh.lazyasd import LazyBool, lazyobject, lazybool
15 
16 
17 @lazyobject
18 def distro():
19     try:
20         import distro as d
21     except ImportError:
22         d = None
23     except Exception:
24         raise
25     return d
26 
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 ON_FREEBSD = LazyBool(lambda: (sys.platform.startswith('freebsd')),
48                       globals(), 'ON_FREEBSD')
49 """``True`` if on a FreeBSD operating system, else ``False``."""
50 ON_NETBSD = LazyBool(lambda: (sys.platform.startswith('netbsd')),
51                      globals(), 'ON_NETBSD')
52 """``True`` if on a NetBSD operating system, else ``False``."""
53 ON_BSD = LazyBool(lambda: ON_FREEBSD or ON_NETBSD,
54                   globals(), 'ON_BSD')
55 """``True`` if on a BSD operating system, else ``False``."""
56 
57 
58 #
59 # Python & packages
60 #
61 
62 PYTHON_VERSION_INFO = sys.version_info[:3]
63 """ Version of Python interpreter as three-value tuple. """
64 ON_ANACONDA = LazyBool(
65     lambda: any(s in sys.version for s in {'Anaconda', 'Continuum', 'conda-forge'}),
66     globals(), 'ON_ANACONDA')
67 """ ``True`` if executed in an Anaconda instance, else ``False``. """
68 CAN_RESIZE_WINDOW = LazyBool(lambda: hasattr(signal, 'SIGWINCH'),
69                              globals(), 'CAN_RESIZE_WINDOW')
70 """``True`` if we can resize terminal window, as provided by the presense of
71 signal.SIGWINCH, else ``False``.
72 """
73 
74 
75 @lazybool
76 def HAS_PYGMENTS():
77     """``True`` if `pygments` is available, else ``False``."""
78     spec = importlib.util.find_spec('pygments')
79     return (spec is not None)
80 
81 
82 @functools.lru_cache(1)
83 def pygments_version():
84     """pygments.__version__ version if available, else None."""
85     if HAS_PYGMENTS:
86         import pygments
87         v = pygments.__version__
88     else:
89         v = None
90     return v
91 
92 
93 @functools.lru_cache(1)
94 def has_prompt_toolkit():
95     """ Tests if the `prompt_toolkit` is available. """
96     spec = importlib.util.find_spec('prompt_toolkit')
97     return (spec is not None)
98 
99 
100 @functools.lru_cache(1)
101 def ptk_version():
102     """ Returns `prompt_toolkit.__version__` if available, else ``None``. """
103     if has_prompt_toolkit():
104         import prompt_toolkit
105         return getattr(prompt_toolkit, '__version__', '<0.57')
106     else:
107         return None
108 
109 
110 @functools.lru_cache(1)
111 def ptk_version_info():
112     """ Returns `prompt_toolkit`'s version as tuple of integers. """
113     if has_prompt_toolkit():
114         return tuple(int(x) for x in ptk_version().strip('<>+-=.').split('.'))
115     else:
116         return None
117 
118 
119 @functools.lru_cache(1)
120 def ptk_version_is_supported():
121     minimum_required_ptk_version = (1, 0)
122     return ptk_version_info()[:2] >= minimum_required_ptk_version
123 
124 
125 @functools.lru_cache(1)
126 def best_shell_type():
127     if ON_WINDOWS or has_prompt_toolkit():
128         return 'prompt_toolkit'
129     else:
130         return 'readline'
131 
132 
133 @functools.lru_cache(1)
134 def is_readline_available():
135     """Checks if readline is available to import."""
136     spec = importlib.util.find_spec('readline')
137     return (spec is not None)
138 
139 
140 @lazyobject
141 def seps():
142     """String of all path separators."""
143     s = os.path.sep
144     if os.path.altsep is not None:
145         s += os.path.altsep
146     return s
147 
148 
149 def pathsplit(p):
150     """This is a safe version of os.path.split(), which does not work on input
151     without a drive.
152     """
153     n = len(p)
154     while n and p[n-1] not in seps:
155         n -= 1
156     pre = p[:n]
157     pre = pre.rstrip(seps) or pre
158     post = p[n:]
159     return pre, post
160 
161 
162 def pathbasename(p):
163     """This is a safe version of os.path.basename(), which does not work on
164     input without a drive.  This version does.
165     """
166     return pathsplit(p)[-1]
167 
168 # termios tc(get|set)attr indexes.
169 IFLAG = 0
170 OFLAG = 1
171 CFLAG = 2
172 LFLAG = 3
173 ISPEED = 4
174 OSPEED = 5
175 CC = 6
176 
177 
178 #
179 # Dev release info
180 #
181 
182 @functools.lru_cache(1)
183 def githash():
184     """Returns a tuple contains two strings: the hash and the date."""
185     install_base = os.path.dirname(__file__)
186     githash_file = '{}/dev.githash'.format(install_base)
187     if not os.path.exists(githash_file):
188         return None, None
189     sha = None
190     date_ = None
191     try:
192         with open(githash_file) as f:
193             sha, date_ = f.read().strip().split('|')
194     except ValueError:
195         pass
196     return sha, date_
197 
198 
199 #
200 # Encoding
201 #
202 
203 DEFAULT_ENCODING = sys.getdefaultencoding()
204 """ Default string encoding. """
205 
206 
207 if PYTHON_VERSION_INFO < (3, 5, 0):
208     class DirEntry:
209         def __init__(self, directory, name):
210             self.__path__ = pathlib.Path(directory) / name
211             self.name = name
212             self.path = str(self.__path__)
213             self.is_symlink = self.__path__.is_symlink
214 
215         def inode(self):
216             return os.stat(self.path, follow_symlinks=False).st_ino
217 
218         def is_dir(self, *, follow_symlinks=True):
219             if follow_symlinks:
220                 return self.__path__.is_dir()
221             else:
222                 return not self.__path__.is_symlink() \
223                        and self.__path__.is_dir()
224 
225         def is_file(self, *, follow_symlinks=True):
226             if follow_symlinks:
227                 return self.__path__.is_file()
228             else:
229                 return not self.__path__.is_symlink() \
230                        and self.__path__.is_file()
231 
232         def stat(self, *, follow_symlinks=True):
233             return os.stat(self.path, follow_symlinks=follow_symlinks)
234 
235     def scandir(path):
236         """ Compatibility layer for  `os.scandir` from Python 3.5+. """
237         return (DirEntry(path, x) for x in os.listdir(path))
238 else:
239     scandir = os.scandir
240 
241 
242 #
243 # Linux distro
244 #
245 
246 @functools.lru_cache(1)
247 def linux_distro():
248     """The id of the Linux distribution running on, possibly 'unknown'.
249     None on non-Linux platforms.
250     """
251     if ON_LINUX:
252         if distro:
253             ld = distro.id()
254         elif PYTHON_VERSION_INFO < (3, 7, 0):
255             ld = platform.linux_distribution()[0] or 'unknown'
256         elif '-ARCH-' in platform.platform():
257             ld = 'arch'  # that's the only one we need to know for now
258         else:
259             ld = 'unknown'
260     else:
261         ld = None
262     return ld
263 
264 
265 #
266 # Windows
267 #
268 
269 @functools.lru_cache(1)
270 def git_for_windows_path():
271     """Returns the path to git for windows, if available and None otherwise."""
272     import winreg
273     try:
274         key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
275                              'SOFTWARE\\GitForWindows')
276         gfwp, _ = winreg.QueryValueEx(key, "InstallPath")
277     except FileNotFoundError:
278         gfwp = None
279     return gfwp
280 
281 
282 @functools.lru_cache(1)
283 def windows_bash_command():
284     """Determines the command for Bash on windows."""
285     # Check that bash is on path otherwise try the default directory
286     # used by Git for windows
287     wbc = 'bash'
288     try:
289         subprocess.check_call([wbc, '--version'],
290                               stdout=subprocess.PIPE,
291                               stderr=subprocess.PIPE)
292     except (FileNotFoundError, subprocess.CalledProcessError):
293         gfwp = git_for_windows_path()
294         if gfwp:
295             bashcmd = os.path.join(gfwp, 'bin\\bash.exe')
296             if os.path.isfile(bashcmd):
297                 wbc = bashcmd
298     return wbc
299 
300 #
301 # Environment variables defaults
302 #
303 
304 
305 @functools.lru_cache(1)
306 def bash_command():
307     """Determines the command for Bash on the current plaform."""
308     if ON_WINDOWS:
309         bc = windows_bash_command()
310     else:
311         bc = 'bash'
312     return bc
313 
314 
315 @lazyobject
316 def BASH_COMPLETIONS_DEFAULT():
317     """A possibly empty tuple with default paths to Bash completions known for
318     the current platform.
319     """
320     if ON_LINUX or ON_CYGWIN:
321         bcd = ('/usr/share/bash-completion/bash_completion', )
322     elif ON_DARWIN:
323         bcd = ('/usr/local/share/bash-completion/bash_completion',  # v2.x
324                '/usr/local/etc/bash_completion')  # v1.x
325     elif ON_WINDOWS and git_for_windows_path():
326         bcd = (os.path.join(git_for_windows_path(),
327                             'usr\\share\\bash-completion\\bash_completion'),
328                os.path.join(git_for_windows_path(),
329                             'mingw64\\share\\git\\completion\\'
330                             'git-completion.bash'))
331     else:
332         bcd = ()
333     return bcd
334 
335 
336 @lazyobject
337 def PATH_DEFAULT():
338     if ON_LINUX or ON_CYGWIN:
339         if linux_distro() == 'arch':
340             pd = ('/usr/local/sbin',
341                   '/usr/local/bin', '/usr/bin', '/usr/bin/site_perl',
342                   '/usr/bin/vendor_perl', '/usr/bin/core_perl')
343         else:
344             pd = (os.path.expanduser('~/bin'), '/usr/local/sbin',
345                   '/usr/local/bin', '/usr/sbin', '/usr/bin', '/sbin', '/bin',
346                   '/usr/games', '/usr/local/games')
347     elif ON_DARWIN:
348         pd = ('/usr/local/bin', '/usr/bin', '/bin', '/usr/sbin', '/sbin')
349     elif ON_WINDOWS:
350         import winreg
351         key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
352                              r'SYSTEM\CurrentControlSet\Control\Session Manager\Environment')
353         pd = tuple(winreg.QueryValueEx(key, 'Path')[0].split(os.pathsep))
354     else:
355         pd = ()
356     return pd
357
```
--- 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
@@ -6,6 +6,7 @@
 import sys
 import signal
 import pathlib
+import builtins
 import platform
 import functools
 import subprocess
@@ -285,16 +286,22 @@
     # Check that bash is on path otherwise try the default directory
     # used by Git for windows
     wbc = 'bash'
-    try:
-        subprocess.check_call([wbc, '--version'],
-                              stdout=subprocess.PIPE,
-                              stderr=subprocess.PIPE)
-    except (FileNotFoundError, subprocess.CalledProcessError):
-        gfwp = git_for_windows_path()
-        if gfwp:
-            bashcmd = os.path.join(gfwp, 'bin\\bash.exe')
-            if os.path.isfile(bashcmd):
-                wbc = bashcmd
+    bash_on_path = builtins.__xonsh_commands_cache__.lazy_locate_binary('bash',
+                                                                        ignore_alias=True)
+    if bash_on_path:
+        # Check if Bash is from the "Windows Subsystem for Linux" (WSL)
+        # which can't be used by xonsh foreign-shell/completer
+        out = subprocess.check_output([bash_on_path, '--version'],
+                                      stderr=subprocess.PIPE,
+                                      universal_newlines=True)
+        if 'pc-linux-gnu' in out.splitlines()[0]:
+            gfwp = git_for_windows_path()
+            if gfwp:
+                bashcmd = os.path.join(gfwp, 'bin\\bash.exe')
+                if os.path.isfile(bashcmd):
+                    wbc = bashcmd
+        else:
+            wbc = bash_on_path
     return wbc
 
 #

{"golden_diff": "diff --git a/xonsh/platform.py b/xonsh/platform.py\n--- a/xonsh/platform.py\n+++ b/xonsh/platform.py\n@@ -6,6 +6,7 @@\n import sys\n import signal\n import pathlib\n+import builtins\n import platform\n import functools\n import subprocess\n@@ -285,16 +286,22 @@\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+    bash_on_path = builtins.__xonsh_commands_cache__.lazy_locate_binary('bash',\n+                                                                        ignore_alias=True)\n+    if bash_on_path:\n+        # Check if Bash is from the \"Windows Subsystem for Linux\" (WSL)\n+        # which can't be used by xonsh foreign-shell/completer\n+        out = subprocess.check_output([bash_on_path, '--version'],\n+                                      stderr=subprocess.PIPE,\n+                                      universal_newlines=True)\n+        if 'pc-linux-gnu' in out.splitlines()[0]:\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+        else:\n+            wbc = bash_on_path\n     return wbc\n \n #\n", "issue": "git completion on windows broken\nGit completions on windows has stopped working:\r\n```\r\nsnail@sea ~\\Documents\\xonsh master $ $BASH_COMPLETIONS\r\n['C:\\\\Program Files\\\\Git\\\\usr\\\\share\\\\bash-completion\\\\bash_completion', \r\n'C:\\\\Program Files\\\\Git\\\\mingw64\\\\share\\\\git\\\\completion\\\\git-completion.bash']\r\n```\r\n\r\nI guess it could be some of the recent fixes to bash completion scripts. Do we require bash completion 2.0? \r\n\r\nOn windows we use the git bash completions that come bundled with 'Git for Windows'. I don't think that 2.0\r\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 signal\nimport pathlib\nimport platform\nimport functools\nimport subprocess\nimport importlib.util\n\nfrom xonsh.lazyasd import LazyBool, lazyobject, lazybool\n\n\n@lazyobject\ndef distro():\n    try:\n        import distro as d\n    except ImportError:\n        d = None\n    except Exception:\n        raise\n    return d\n\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``. \"\"\"\nON_FREEBSD = LazyBool(lambda: (sys.platform.startswith('freebsd')),\n                      globals(), 'ON_FREEBSD')\n\"\"\"``True`` if on a FreeBSD operating system, else ``False``.\"\"\"\nON_NETBSD = LazyBool(lambda: (sys.platform.startswith('netbsd')),\n                     globals(), 'ON_NETBSD')\n\"\"\"``True`` if on a NetBSD operating system, else ``False``.\"\"\"\nON_BSD = LazyBool(lambda: ON_FREEBSD or ON_NETBSD,\n                  globals(), 'ON_BSD')\n\"\"\"``True`` if on a BSD operating system, 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', 'conda-forge'}),\n    globals(), 'ON_ANACONDA')\n\"\"\" ``True`` if executed in an Anaconda instance, else ``False``. \"\"\"\nCAN_RESIZE_WINDOW = LazyBool(lambda: hasattr(signal, 'SIGWINCH'),\n                             globals(), 'CAN_RESIZE_WINDOW')\n\"\"\"``True`` if we can resize terminal window, as provided by the presense of\nsignal.SIGWINCH, else ``False``.\n\"\"\"\n\n\n@lazybool\ndef HAS_PYGMENTS():\n    \"\"\"``True`` if `pygments` is available, else ``False``.\"\"\"\n    spec = importlib.util.find_spec('pygments')\n    return (spec is not None)\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('prompt_toolkit')\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 ptk_version_is_supported():\n    minimum_required_ptk_version = (1, 0)\n    return ptk_version_info()[:2] >= minimum_required_ptk_version\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@lazyobject\ndef seps():\n    \"\"\"String of all path separators.\"\"\"\n    s = os.path.sep\n    if os.path.altsep is not None:\n        s += os.path.altsep\n    return s\n\n\ndef pathsplit(p):\n    \"\"\"This is a safe version of os.path.split(), which does not work on input\n    without a drive.\n    \"\"\"\n    n = len(p)\n    while n and p[n-1] not in seps:\n        n -= 1\n    pre = p[:n]\n    pre = pre.rstrip(seps) or pre\n    post = p[n:]\n    return pre, post\n\n\ndef pathbasename(p):\n    \"\"\"This is a safe version of os.path.basename(), which does not work on\n    input without a drive.  This version does.\n    \"\"\"\n    return pathsplit(p)[-1]\n\n# termios tc(get|set)attr indexes.\nIFLAG = 0\nOFLAG = 1\nCFLAG = 2\nLFLAG = 3\nISPEED = 4\nOSPEED = 5\nCC = 6\n\n\n#\n# Dev release info\n#\n\n@functools.lru_cache(1)\ndef githash():\n    \"\"\"Returns a tuple contains two strings: the hash and the date.\"\"\"\n    install_base = os.path.dirname(__file__)\n    githash_file = '{}/dev.githash'.format(install_base)\n    if not os.path.exists(githash_file):\n        return None, None\n    sha = None\n    date_ = None\n    try:\n        with open(githash_file) as f:\n            sha, date_ = f.read().strip().split('|')\n    except ValueError:\n        pass\n    return sha, date_\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 the command for Bash on windows.\"\"\"\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\n\n@functools.lru_cache(1)\ndef bash_command():\n    \"\"\"Determines the command for Bash on the current plaform.\"\"\"\n    if ON_WINDOWS:\n        bc = windows_bash_command()\n    else:\n        bc = 'bash'\n    return bc\n\n\n@lazyobject\ndef BASH_COMPLETIONS_DEFAULT():\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        bcd = ('/usr/share/bash-completion/bash_completion', )\n    elif ON_DARWIN:\n        bcd = ('/usr/local/share/bash-completion/bash_completion',  # v2.x\n               '/usr/local/etc/bash_completion')  # v1.x\n    elif ON_WINDOWS and git_for_windows_path():\n        bcd = (os.path.join(git_for_windows_path(),\n                            'usr\\\\share\\\\bash-completion\\\\bash_completion'),\n               os.path.join(git_for_windows_path(),\n                            'mingw64\\\\share\\\\git\\\\completion\\\\'\n                            'git-completion.bash'))\n    else:\n        bcd = ()\n    return bcd\n\n\n@lazyobject\ndef PATH_DEFAULT():\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", "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 signal\nimport pathlib\nimport builtins\nimport platform\nimport functools\nimport subprocess\nimport importlib.util\n\nfrom xonsh.lazyasd import LazyBool, lazyobject, lazybool\n\n\n@lazyobject\ndef distro():\n    try:\n        import distro as d\n    except ImportError:\n        d = None\n    except Exception:\n        raise\n    return d\n\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``. \"\"\"\nON_FREEBSD = LazyBool(lambda: (sys.platform.startswith('freebsd')),\n                      globals(), 'ON_FREEBSD')\n\"\"\"``True`` if on a FreeBSD operating system, else ``False``.\"\"\"\nON_NETBSD = LazyBool(lambda: (sys.platform.startswith('netbsd')),\n                     globals(), 'ON_NETBSD')\n\"\"\"``True`` if on a NetBSD operating system, else ``False``.\"\"\"\nON_BSD = LazyBool(lambda: ON_FREEBSD or ON_NETBSD,\n                  globals(), 'ON_BSD')\n\"\"\"``True`` if on a BSD operating system, 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', 'conda-forge'}),\n    globals(), 'ON_ANACONDA')\n\"\"\" ``True`` if executed in an Anaconda instance, else ``False``. \"\"\"\nCAN_RESIZE_WINDOW = LazyBool(lambda: hasattr(signal, 'SIGWINCH'),\n                             globals(), 'CAN_RESIZE_WINDOW')\n\"\"\"``True`` if we can resize terminal window, as provided by the presense of\nsignal.SIGWINCH, else ``False``.\n\"\"\"\n\n\n@lazybool\ndef HAS_PYGMENTS():\n    \"\"\"``True`` if `pygments` is available, else ``False``.\"\"\"\n    spec = importlib.util.find_spec('pygments')\n    return (spec is not None)\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('prompt_toolkit')\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 ptk_version_is_supported():\n    minimum_required_ptk_version = (1, 0)\n    return ptk_version_info()[:2] >= minimum_required_ptk_version\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@lazyobject\ndef seps():\n    \"\"\"String of all path separators.\"\"\"\n    s = os.path.sep\n    if os.path.altsep is not None:\n        s += os.path.altsep\n    return s\n\n\ndef pathsplit(p):\n    \"\"\"This is a safe version of os.path.split(), which does not work on input\n    without a drive.\n    \"\"\"\n    n = len(p)\n    while n and p[n-1] not in seps:\n        n -= 1\n    pre = p[:n]\n    pre = pre.rstrip(seps) or pre\n    post = p[n:]\n    return pre, post\n\n\ndef pathbasename(p):\n    \"\"\"This is a safe version of os.path.basename(), which does not work on\n    input without a drive.  This version does.\n    \"\"\"\n    return pathsplit(p)[-1]\n\n# termios tc(get|set)attr indexes.\nIFLAG = 0\nOFLAG = 1\nCFLAG = 2\nLFLAG = 3\nISPEED = 4\nOSPEED = 5\nCC = 6\n\n\n#\n# Dev release info\n#\n\n@functools.lru_cache(1)\ndef githash():\n    \"\"\"Returns a tuple contains two strings: the hash and the date.\"\"\"\n    install_base = os.path.dirname(__file__)\n    githash_file = '{}/dev.githash'.format(install_base)\n    if not os.path.exists(githash_file):\n        return None, None\n    sha = None\n    date_ = None\n    try:\n        with open(githash_file) as f:\n            sha, date_ = f.read().strip().split('|')\n    except ValueError:\n        pass\n    return sha, date_\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 the command for Bash on windows.\"\"\"\n    # Check that bash is on path otherwise try the default directory\n    # used by Git for windows\n    wbc = 'bash'\n    bash_on_path = builtins.__xonsh_commands_cache__.lazy_locate_binary('bash',\n                                                                        ignore_alias=True)\n    if bash_on_path:\n        # Check if Bash is from the \"Windows Subsystem for Linux\" (WSL)\n        # which can't be used by xonsh foreign-shell/completer\n        out = subprocess.check_output([bash_on_path, '--version'],\n                                      stderr=subprocess.PIPE,\n                                      universal_newlines=True)\n        if 'pc-linux-gnu' in out.splitlines()[0]:\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        else:\n            wbc = bash_on_path\n    return wbc\n\n#\n# Environment variables defaults\n#\n\n\n@functools.lru_cache(1)\ndef bash_command():\n    \"\"\"Determines the command for Bash on the current plaform.\"\"\"\n    if ON_WINDOWS:\n        bc = windows_bash_command()\n    else:\n        bc = 'bash'\n    return bc\n\n\n@lazyobject\ndef BASH_COMPLETIONS_DEFAULT():\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        bcd = ('/usr/share/bash-completion/bash_completion', )\n    elif ON_DARWIN:\n        bcd = ('/usr/local/share/bash-completion/bash_completion',  # v2.x\n               '/usr/local/etc/bash_completion')  # v1.x\n    elif ON_WINDOWS and git_for_windows_path():\n        bcd = (os.path.join(git_for_windows_path(),\n                            'usr\\\\share\\\\bash-completion\\\\bash_completion'),\n               os.path.join(git_for_windows_path(),\n                            'mingw64\\\\share\\\\git\\\\completion\\\\'\n                            'git-completion.bash'))\n    else:\n        bcd = ()\n    return bcd\n\n\n@lazyobject\ndef PATH_DEFAULT():\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", "path": "xonsh/platform.py"}]}