prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Latest virtualenv breaks pre-commit
  See also #299 
  
  Failure looks like:
  
  ```
  17:00:19 hookid: sort-simple-yaml
  17:00:19 
  17:00:19 bash: /nail/home/push/.pre-commit/reposkzFrD//tmp/tmp.cEk6TCoZOS/srv-configs/py_env-default/bin/activate: No such file or directory
  ```
  
  ```
  $ pip install virtualenv --upgrade
  Downloading/unpacking virtualenv
    Downloading virtualenv-14.0.0-py2.py3-none-any.whl (1.8MB): 1.8MB downloaded
  Installing collected packages: virtualenv
  Successfully installed virtualenv
  Cleaning up...
  $ python
  Python 2.6.7 (r267:88850, Dec  2 2011, 20:27:26) 
  [GCC 4.4.3] on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import virtualenv
  >>> virtualenv.path_locations('foo')
  ('/nail/home/asottile/foo', '/nail/home/asottile/foo/lib/python2.6', '/nail/home/asottile/foo/include/python2.6', '/nail/home/asottile/foo/bin')
  >>> 
  $ pip install virtualenv==1.11.5
  Downloading/unpacking virtualenv==1.11.5
    Downloading virtualenv-1.11.5.tar.gz (1.8MB): 1.8MB downloaded
    Running setup.py (path:/nail/home/asottile/venv/build/virtualenv/setup.py) egg_info for package virtualenv
      warning: no previously-included files matching '*' found under directory 'docs/_templates'
      warning: no previously-included files matching '*' found under directory 'docs/_build'
  Installing collected packages: virtualenv
    Found existing installation: virtualenv 14.0.0
      Uninstalling virtualenv:
        Successfully uninstalled virtualenv
    Running setup.py install for virtualenv
      warning: no previously-included files matching '*' found under directory 'docs/_templates'
      warning: no previously-included files matching '*' found under directory 'docs/_build'
      Installing virtualenv script to /nail/home/asottile/venv/bin
      Installing virtualenv-2.6 script to /nail/home/asottile/venv/bin
  Successfully installed virtualenv
  Cleaning up...
  $ python
  Python 2.6.7 (r267:88850, Dec  2 2011, 20:27:26) 
  [GCC 4.4.3] on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import virtualenv
  >>> virtualenv.path_locations('foo')
  ('foo', 'foo/lib/python2.6', 'foo/include/python2.6', 'foo/bin')
  >>>
  ```
  
  
  </issue>
  <code>
  [start of pre_commit/languages/python.py]
  1 from __future__ import unicode_literals
  2 
  3 import contextlib
  4 import distutils.spawn
  5 import os
  6 import sys
  7 
  8 import virtualenv
  9 
  10 from pre_commit.languages import helpers
  11 from pre_commit.util import clean_path_on_failure
  12 from pre_commit.util import shell_escape
  13 
  14 
  15 ENVIRONMENT_DIR = 'py_env'
  16 
  17 
  18 class PythonEnv(helpers.Environment):
  19     @property
  20     def env_prefix(self):
  21         return ". '{{prefix}}{0}activate' &&".format(
  22             virtualenv.path_locations(
  23                 helpers.environment_dir(ENVIRONMENT_DIR, self.language_version)
  24             )[-1].rstrip(os.sep) + os.sep,
  25         )
  26 
  27 
  28 @contextlib.contextmanager
  29 def in_env(repo_cmd_runner, language_version):
  30     yield PythonEnv(repo_cmd_runner, language_version)
  31 
  32 
  33 def norm_version(version):
  34     if os.name == 'nt':  # pragma: no cover (windows)
  35         # Try looking up by name
  36         if distutils.spawn.find_executable(version):
  37             return version
  38 
  39         # If it is in the form pythonx.x search in the default
  40         # place on windows
  41         if version.startswith('python'):
  42             return r'C:\{0}\python.exe'.format(version.replace('.', ''))
  43 
  44         # Otherwise assume it is a path
  45     return os.path.expanduser(version)
  46 
  47 
  48 def install_environment(
  49         repo_cmd_runner,
  50         version='default',
  51         additional_dependencies=None,
  52 ):
  53     assert repo_cmd_runner.exists('setup.py')
  54     directory = helpers.environment_dir(ENVIRONMENT_DIR, version)
  55 
  56     # Install a virtualenv
  57     with clean_path_on_failure(repo_cmd_runner.path(directory)):
  58         venv_cmd = [
  59             sys.executable, '-m', 'virtualenv',
  60             '{{prefix}}{0}'.format(directory)
  61         ]
  62         if version != 'default':
  63             venv_cmd.extend(['-p', norm_version(version)])
  64         repo_cmd_runner.run(venv_cmd)
  65         with in_env(repo_cmd_runner, version) as env:
  66             env.run("cd '{prefix}' && pip install .", encoding=None)
  67             if additional_dependencies:
  68                 env.run(
  69                     "cd '{prefix}' && pip install " +
  70                     ' '.join(
  71                         shell_escape(dep) for dep in additional_dependencies
  72                     ),
  73                     encoding=None,
  74                 )
  75 
  76 
  77 def run_hook(repo_cmd_runner, hook, file_args):
  78     with in_env(repo_cmd_runner, hook['language_version']) as env:
  79         return helpers.run_hook(env, hook, file_args)
  80
  [end of pre_commit/languages/python.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/pre_commit/languages/python.py b/pre_commit/languages/python.py
  --- a/pre_commit/languages/python.py
  +++ b/pre_commit/languages/python.py
  @@ -5,8 +5,6 @@
   import os
   import sys
   
  -import virtualenv
  -
   from pre_commit.languages import helpers
   from pre_commit.util import clean_path_on_failure
   from pre_commit.util import shell_escape
  @@ -15,13 +13,22 @@
   ENVIRONMENT_DIR = 'py_env'
   
   
  +def bin_dir(venv):
  +    """On windows there's a different directory for the virtualenv"""
  +    if os.name == 'nt':  # pragma: no cover (windows)
  +        return os.path.join(venv, 'Scripts')
  +    else:
  +        return os.path.join(venv, 'bin')
  +
  +
   class PythonEnv(helpers.Environment):
       @property
       def env_prefix(self):
  -        return ". '{{prefix}}{0}activate' &&".format(
  -            virtualenv.path_locations(
  +        return ". '{{prefix}}{0}{1}activate' &&".format(
  +            bin_dir(
                   helpers.environment_dir(ENVIRONMENT_DIR, self.language_version)
  -            )[-1].rstrip(os.sep) + os.sep,
  +            ),
  +            os.sep,
           )
  
verification_info: {"golden_diff": "diff --git a/pre_commit/languages/python.py b/pre_commit/languages/python.py\n--- a/pre_commit/languages/python.py\n+++ b/pre_commit/languages/python.py\n@@ -5,8 +5,6 @@\n import os\n import sys\n \n-import virtualenv\n-\n from pre_commit.languages import helpers\n from pre_commit.util import clean_path_on_failure\n from pre_commit.util import shell_escape\n@@ -15,13 +13,22 @@\n ENVIRONMENT_DIR = 'py_env'\n \n \n+def bin_dir(venv):\n+    \"\"\"On windows there's a different directory for the virtualenv\"\"\"\n+    if os.name == 'nt':  # pragma: no cover (windows)\n+        return os.path.join(venv, 'Scripts')\n+    else:\n+        return os.path.join(venv, 'bin')\n+\n+\n class PythonEnv(helpers.Environment):\n     @property\n     def env_prefix(self):\n-        return \". '{{prefix}}{0}activate' &&\".format(\n-            virtualenv.path_locations(\n+        return \". '{{prefix}}{0}{1}activate' &&\".format(\n+            bin_dir(\n                 helpers.environment_dir(ENVIRONMENT_DIR, self.language_version)\n-            )[-1].rstrip(os.sep) + os.sep,\n+            ),\n+            os.sep,\n         )\n", "issue": "Latest virtualenv breaks pre-commit\nSee also #299 \n\nFailure looks like:\n\n```\n17:00:19 hookid: sort-simple-yaml\n17:00:19 \n17:00:19 bash: /nail/home/push/.pre-commit/reposkzFrD//tmp/tmp.cEk6TCoZOS/srv-configs/py_env-default/bin/activate: No such file or directory\n```\n\n```\n$ pip install virtualenv --upgrade\nDownloading/unpacking virtualenv\n  Downloading virtualenv-14.0.0-py2.py3-none-any.whl (1.8MB): 1.8MB downloaded\nInstalling collected packages: virtualenv\nSuccessfully installed virtualenv\nCleaning up...\n$ python\nPython 2.6.7 (r267:88850, Dec  2 2011, 20:27:26) \n[GCC 4.4.3] on linux2\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n>>> import virtualenv\n>>> virtualenv.path_locations('foo')\n('/nail/home/asottile/foo', '/nail/home/asottile/foo/lib/python2.6', '/nail/home/asottile/foo/include/python2.6', '/nail/home/asottile/foo/bin')\n>>> \n$ pip install virtualenv==1.11.5\nDownloading/unpacking virtualenv==1.11.5\n  Downloading virtualenv-1.11.5.tar.gz (1.8MB): 1.8MB downloaded\n  Running setup.py (path:/nail/home/asottile/venv/build/virtualenv/setup.py) egg_info for package virtualenv\n    warning: no previously-included files matching '*' found under directory 'docs/_templates'\n    warning: no previously-included files matching '*' found under directory 'docs/_build'\nInstalling collected packages: virtualenv\n  Found existing installation: virtualenv 14.0.0\n    Uninstalling virtualenv:\n      Successfully uninstalled virtualenv\n  Running setup.py install for virtualenv\n    warning: no previously-included files matching '*' found under directory 'docs/_templates'\n    warning: no previously-included files matching '*' found under directory 'docs/_build'\n    Installing virtualenv script to /nail/home/asottile/venv/bin\n    Installing virtualenv-2.6 script to /nail/home/asottile/venv/bin\nSuccessfully installed virtualenv\nCleaning up...\n$ python\nPython 2.6.7 (r267:88850, Dec  2 2011, 20:27:26) \n[GCC 4.4.3] on linux2\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n>>> import virtualenv\n>>> virtualenv.path_locations('foo')\n('foo', 'foo/lib/python2.6', 'foo/include/python2.6', 'foo/bin')\n>>>\n```\n\n", "before_files": [{"content": "from __future__ import unicode_literals\n\nimport contextlib\nimport distutils.spawn\nimport os\nimport sys\n\nimport virtualenv\n\nfrom pre_commit.languages import helpers\nfrom pre_commit.util import clean_path_on_failure\nfrom pre_commit.util import shell_escape\n\n\nENVIRONMENT_DIR = 'py_env'\n\n\nclass PythonEnv(helpers.Environment):\n    @property\n    def env_prefix(self):\n        return \". '{{prefix}}{0}activate' &&\".format(\n            virtualenv.path_locations(\n                helpers.environment_dir(ENVIRONMENT_DIR, self.language_version)\n            )[-1].rstrip(os.sep) + os.sep,\n        )\n\n\n@contextlib.contextmanager\ndef in_env(repo_cmd_runner, language_version):\n    yield PythonEnv(repo_cmd_runner, language_version)\n\n\ndef norm_version(version):\n    if os.name == 'nt':  # pragma: no cover (windows)\n        # Try looking up by name\n        if distutils.spawn.find_executable(version):\n            return version\n\n        # If it is in the form pythonx.x search in the default\n        # place on windows\n        if version.startswith('python'):\n            return r'C:\\{0}\\python.exe'.format(version.replace('.', ''))\n\n        # Otherwise assume it is a path\n    return os.path.expanduser(version)\n\n\ndef install_environment(\n        repo_cmd_runner,\n        version='default',\n        additional_dependencies=None,\n):\n    assert repo_cmd_runner.exists('setup.py')\n    directory = helpers.environment_dir(ENVIRONMENT_DIR, version)\n\n    # Install a virtualenv\n    with clean_path_on_failure(repo_cmd_runner.path(directory)):\n        venv_cmd = [\n            sys.executable, '-m', 'virtualenv',\n            '{{prefix}}{0}'.format(directory)\n        ]\n        if version != 'default':\n            venv_cmd.extend(['-p', norm_version(version)])\n        repo_cmd_runner.run(venv_cmd)\n        with in_env(repo_cmd_runner, version) as env:\n            env.run(\"cd '{prefix}' && pip install .\", encoding=None)\n            if additional_dependencies:\n                env.run(\n                    \"cd '{prefix}' && pip install \" +\n                    ' '.join(\n                        shell_escape(dep) for dep in additional_dependencies\n                    ),\n                    encoding=None,\n                )\n\n\ndef run_hook(repo_cmd_runner, hook, file_args):\n    with in_env(repo_cmd_runner, hook['language_version']) as env:\n        return helpers.run_hook(env, hook, file_args)\n", "path": "pre_commit/languages/python.py"}]}