from __future__ import absolute_import
from pexpect import spawn, which, EOF, TIMEOUT

from __future__ import absolute_import
from pexpect import which as which_base, is_executable_file, EOF, TIMEOUT
import os

try:
    from pexpect import spawn
    import pty
except ImportError:
    pty = None


def which(filename):
    '''This takes a given filename; tries to find it in the environment path;
    then checks if it is executable. This returns the full path to the filename
    if found and executable. Otherwise this returns None.'''

    # Special case where filename contains an explicit path.
    if os.path.dirname(filename) != '' and is_executable_file(filename):
        return filename
    if 'PATH' not in os.environ or os.environ['PATH'] == '':
        p = os.defpath
    else:
        p = os.environ['PATH']
    pathlist = p.split(os.pathsep)
    for path in pathlist:
        ff = os.path.join(path, filename)
        if pty:
            if is_executable_file(ff):
                return ff
        else:
            pathext = os.environ.get('Pathext', '.exe;.com;.bat;.cmd')
            pathext = pathext.split(os.pathsep) + ['']
            for ext in pathext:
                if os.access(ff + ext, os.X_OK):
                    return ff + ext
    return None

Add handling of which on Windows
Add handling of which on Windows

  from __future__ import absolute_import
- from pexpect import spawn, which, EOF, TIMEOUT
+ from pexpect import which as which_base, is_executable_file, EOF, TIMEOUT
+ import os
  
+ try:
+     from pexpect import spawn
+     import pty
+ except ImportError:
+     pty = None
+ 
+ 
+ def which(filename):
+     '''This takes a given filename; tries to find it in the environment path;
+     then checks if it is executable. This returns the full path to the filename
+     if found and executable. Otherwise this returns None.'''
+ 
+     # Special case where filename contains an explicit path.
+     if os.path.dirname(filename) != '' and is_executable_file(filename):
+         return filename
+     if 'PATH' not in os.environ or os.environ['PATH'] == '':
+         p = os.defpath
+     else:
+         p = os.environ['PATH']
+     pathlist = p.split(os.pathsep)
+     for path in pathlist:
+         ff = os.path.join(path, filename)
+         if pty:
+             if is_executable_file(ff):
+                 return ff
+         else:
+             pathext = os.environ.get('Pathext', '.exe;.com;.bat;.cmd')
+             pathext = pathext.split(os.pathsep) + ['']
+             for ext in pathext:
+                 if os.access(ff + ext, os.X_OK):
+                     return ff + ext
+     return None
+ 
Add handling of which on Windows
## Code Before:
from __future__ import absolute_import
from pexpect import spawn, which, EOF, TIMEOUT

## Instruction:
Add handling of which on Windows
## Code After:
from __future__ import absolute_import
from pexpect import which as which_base, is_executable_file, EOF, TIMEOUT
import os

try:
    from pexpect import spawn
    import pty
except ImportError:
    pty = None


def which(filename):
    '''This takes a given filename; tries to find it in the environment path;
    then checks if it is executable. This returns the full path to the filename
    if found and executable. Otherwise this returns None.'''

    # Special case where filename contains an explicit path.
    if os.path.dirname(filename) != '' and is_executable_file(filename):
        return filename
    if 'PATH' not in os.environ or os.environ['PATH'] == '':
        p = os.defpath
    else:
        p = os.environ['PATH']
    pathlist = p.split(os.pathsep)
    for path in pathlist:
        ff = os.path.join(path, filename)
        if pty:
            if is_executable_file(ff):
                return ff
        else:
            pathext = os.environ.get('Pathext', '.exe;.com;.bat;.cmd')
            pathext = pathext.split(os.pathsep) + ['']
            for ext in pathext:
                if os.access(ff + ext, os.X_OK):
                    return ff + ext
    return None
