prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  venv tests break virtualenv's `pip` when run from a `-mvirtualenv` virtualenv
  Here's a reproduction, not exactly sure what's happening here:
  
  ```
  $ tox -e py36 -r --notest
  GLOB sdist-make: /home/asottile/workspace/pre-commit/setup.py
  py36 create: /home/asottile/workspace/pre-commit/.tox/py36
  py36 installdeps: -rrequirements-dev.txt
  py36 inst: /home/asottile/workspace/pre-commit/.tox/dist/pre_commit-1.10.0.zip
  py36 installed: You are using pip version 9.0.1, however version 10.0.1 is available.,You should consider upgrading via the 'pip install --upgrade pip' command.,aspy.yaml==1.1.1,atomicwrites==1.1.5,attrs==18.1.0,cached-property==1.4.2,cfgv==1.0.0,coverage==4.5.1,flake8==3.5.0,identify==1.0.18,mccabe==0.6.1,mock==2.0.0,more-itertools==4.2.0,nodeenv==1.3.0,pbr==4.0.3,pluggy==0.6.0,-e git+git@github.com:pre-commit/pre-commit@97fb49a533de9a378d20f0a41e79df118362e534#egg=pre_commit,py==1.5.3,pycodestyle==2.3.1,pyflakes==1.6.0,pytest==3.6.0,pytest-env==0.6.2,PyYAML==3.12,six==1.11.0,toml==0.9.4,virtualenv==16.0.0
  ___________________________________ summary ____________________________________
    py36: skipped tests
    congratulations :)
  
  $ head -1 .tox/py36/bin/pip
  #!/home/asottile/workspace/pre-commit/.tox/py36/bin/python3.6
  $ .tox/py36/bin/pytest tests -k venv
  ============================= test session starts ==============================
  platform linux -- Python 3.6.5, pytest-3.6.0, py-1.5.3, pluggy-0.6.0
  rootdir: /home/asottile/workspace/pre-commit, inifile: tox.ini
  plugins: env-0.6.2
  collected 500 items / 492 deselected                                           
  
  tests/repository_test.py ..                                              [ 25%]
  tests/commands/install_uninstall_test.py .                               [ 37%]
  tests/languages/all_test.py .....                                        [100%]
  
  =================== 8 passed, 492 deselected in 4.12 seconds ===================
  $ head -1 .tox/py36/bin/pip
  #!/home/asottile/workspace/pre-commit/.tox/py36/bin/python3.6
  $ tox -e py36 -- tests -k venv
  GLOB sdist-make: /home/asottile/workspace/pre-commit/setup.py
  py36 inst-nodeps: /home/asottile/workspace/pre-commit/.tox/dist/pre_commit-1.10.0.zip
  py36 installed: You are using pip version 9.0.1, however version 10.0.1 is available.,You should consider upgrading via the 'pip install --upgrade pip' command.,aspy.yaml==1.1.1,atomicwrites==1.1.5,attrs==18.1.0,cached-property==1.4.2,cfgv==1.0.0,coverage==4.5.1,flake8==3.5.0,identify==1.0.18,mccabe==0.6.1,mock==2.0.0,more-itertools==4.2.0,nodeenv==1.3.0,pbr==4.0.3,pluggy==0.6.0,pre-commit==1.10.0,py==1.5.3,pycodestyle==2.3.1,pyflakes==1.6.0,pytest==3.6.0,pytest-env==0.6.2,PyYAML==3.12,six==1.11.0,toml==0.9.4,virtualenv==16.0.0
  py36 runtests: PYTHONHASHSEED='93802395'
  py36 runtests: commands[0] | coverage erase
  py36 runtests: commands[1] | coverage run -m pytest tests -k venv
  ============================= test session starts ==============================
  platform linux -- Python 3.6.5, pytest-3.6.0, py-1.5.3, pluggy-0.6.0
  rootdir: /home/asottile/workspace/pre-commit, inifile: tox.ini
  plugins: env-0.6.2
  collected 500 items / 492 deselected                                           
  
  tests/repository_test.py ..                                              [ 25%]
  tests/commands/install_uninstall_test.py .                               [ 37%]
  tests/languages/all_test.py .....                                        [100%]
  
  =================== 8 passed, 492 deselected in 4.32 seconds ===================
  py36 runtests: commands[2] | coverage report --fail-under 99
  Name                                              Stmts   Miss Branch BrPart  Cover   Missing
  ---------------------------------------------------------------------------------------------
  ...
  17 files skipped due to complete coverage.
  ERROR: InvocationError: '/home/asottile/workspace/pre-commit/.tox/py36/bin/coverage report --fail-under 99'
  ___________________________________ summary ____________________________________
  ERROR:   py36: commands failed
  
  $ head -1 .tox/py36/bin/pip
  #!/tmp/pytest-of-asottile/pytest-3/test_python_venv0/0/.pre-commit/repo5xcuq11q/py_venv-python3.6/bin/python3.6
  ```
  
  </issue>
  <code>
  [start of pre_commit/languages/python_venv.py]
  1 from __future__ import unicode_literals
  2 
  3 from pre_commit.languages import python
  4 from pre_commit.util import cmd_output
  5 
  6 
  7 ENVIRONMENT_DIR = 'py_venv'
  8 
  9 
  10 def make_venv(envdir, python):
  11     cmd_output(python, '-mvenv', envdir, cwd='/')
  12 
  13 
  14 get_default_version = python.get_default_version
  15 _interface = python.py_interface(ENVIRONMENT_DIR, make_venv)
  16 in_env, healthy, run_hook, install_environment = _interface
  17
  [end of pre_commit/languages/python_venv.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_venv.py b/pre_commit/languages/python_venv.py
  --- a/pre_commit/languages/python_venv.py
  +++ b/pre_commit/languages/python_venv.py
  @@ -1,14 +1,46 @@
   from __future__ import unicode_literals
   
  +import os.path
  +
   from pre_commit.languages import python
  +from pre_commit.util import CalledProcessError
   from pre_commit.util import cmd_output
   
   
   ENVIRONMENT_DIR = 'py_venv'
   
   
  +def orig_py_exe(exe):  # pragma: no cover (platform specific)
  +    """A -mvenv virtualenv made from a -mvirtualenv virtualenv installs
  +    packages to the incorrect location.  Attempt to find the _original_ exe
  +    and invoke `-mvenv` from there.
  +
  +    See:
  +    - https://github.com/pre-commit/pre-commit/issues/755
  +    - https://github.com/pypa/virtualenv/issues/1095
  +    - https://bugs.python.org/issue30811
  +    """
  +    try:
  +        prefix_script = 'import sys; print(sys.real_prefix)'
  +        _, prefix, _ = cmd_output(exe, '-c', prefix_script)
  +        prefix = prefix.strip()
  +    except CalledProcessError:
  +        # not created from -mvirtualenv
  +        return exe
  +
  +    if os.name == 'nt':
  +        expected = os.path.join(prefix, 'python.exe')
  +    else:
  +        expected = os.path.join(prefix, 'bin', os.path.basename(exe))
  +
  +    if os.path.exists(expected):
  +        return expected
  +    else:
  +        return exe
  +
  +
   def make_venv(envdir, python):
  -    cmd_output(python, '-mvenv', envdir, cwd='/')
  +    cmd_output(orig_py_exe(python), '-mvenv', envdir, cwd='/')
   
   
   get_default_version = python.get_default_version
  
verification_info: {"golden_diff": "diff --git a/pre_commit/languages/python_venv.py b/pre_commit/languages/python_venv.py\n--- a/pre_commit/languages/python_venv.py\n+++ b/pre_commit/languages/python_venv.py\n@@ -1,14 +1,46 @@\n from __future__ import unicode_literals\n \n+import os.path\n+\n from pre_commit.languages import python\n+from pre_commit.util import CalledProcessError\n from pre_commit.util import cmd_output\n \n \n ENVIRONMENT_DIR = 'py_venv'\n \n \n+def orig_py_exe(exe):  # pragma: no cover (platform specific)\n+    \"\"\"A -mvenv virtualenv made from a -mvirtualenv virtualenv installs\n+    packages to the incorrect location.  Attempt to find the _original_ exe\n+    and invoke `-mvenv` from there.\n+\n+    See:\n+    - https://github.com/pre-commit/pre-commit/issues/755\n+    - https://github.com/pypa/virtualenv/issues/1095\n+    - https://bugs.python.org/issue30811\n+    \"\"\"\n+    try:\n+        prefix_script = 'import sys; print(sys.real_prefix)'\n+        _, prefix, _ = cmd_output(exe, '-c', prefix_script)\n+        prefix = prefix.strip()\n+    except CalledProcessError:\n+        # not created from -mvirtualenv\n+        return exe\n+\n+    if os.name == 'nt':\n+        expected = os.path.join(prefix, 'python.exe')\n+    else:\n+        expected = os.path.join(prefix, 'bin', os.path.basename(exe))\n+\n+    if os.path.exists(expected):\n+        return expected\n+    else:\n+        return exe\n+\n+\n def make_venv(envdir, python):\n-    cmd_output(python, '-mvenv', envdir, cwd='/')\n+    cmd_output(orig_py_exe(python), '-mvenv', envdir, cwd='/')\n \n \n get_default_version = python.get_default_version\n", "issue": "venv tests break virtualenv's `pip` when run from a `-mvirtualenv` virtualenv\nHere's a reproduction, not exactly sure what's happening here:\r\n\r\n```\r\n$ tox -e py36 -r --notest\r\nGLOB sdist-make: /home/asottile/workspace/pre-commit/setup.py\r\npy36 create: /home/asottile/workspace/pre-commit/.tox/py36\r\npy36 installdeps: -rrequirements-dev.txt\r\npy36 inst: /home/asottile/workspace/pre-commit/.tox/dist/pre_commit-1.10.0.zip\r\npy36 installed: You are using pip version 9.0.1, however version 10.0.1 is available.,You should consider upgrading via the 'pip install --upgrade pip' command.,aspy.yaml==1.1.1,atomicwrites==1.1.5,attrs==18.1.0,cached-property==1.4.2,cfgv==1.0.0,coverage==4.5.1,flake8==3.5.0,identify==1.0.18,mccabe==0.6.1,mock==2.0.0,more-itertools==4.2.0,nodeenv==1.3.0,pbr==4.0.3,pluggy==0.6.0,-e git+git@github.com:pre-commit/pre-commit@97fb49a533de9a378d20f0a41e79df118362e534#egg=pre_commit,py==1.5.3,pycodestyle==2.3.1,pyflakes==1.6.0,pytest==3.6.0,pytest-env==0.6.2,PyYAML==3.12,six==1.11.0,toml==0.9.4,virtualenv==16.0.0\r\n___________________________________ summary ____________________________________\r\n  py36: skipped tests\r\n  congratulations :)\r\n\r\n$ head -1 .tox/py36/bin/pip\r\n#!/home/asottile/workspace/pre-commit/.tox/py36/bin/python3.6\r\n$ .tox/py36/bin/pytest tests -k venv\r\n============================= test session starts ==============================\r\nplatform linux -- Python 3.6.5, pytest-3.6.0, py-1.5.3, pluggy-0.6.0\r\nrootdir: /home/asottile/workspace/pre-commit, inifile: tox.ini\r\nplugins: env-0.6.2\r\ncollected 500 items / 492 deselected                                           \r\n\r\ntests/repository_test.py ..                                              [ 25%]\r\ntests/commands/install_uninstall_test.py .                               [ 37%]\r\ntests/languages/all_test.py .....                                        [100%]\r\n\r\n=================== 8 passed, 492 deselected in 4.12 seconds ===================\r\n$ head -1 .tox/py36/bin/pip\r\n#!/home/asottile/workspace/pre-commit/.tox/py36/bin/python3.6\r\n$ tox -e py36 -- tests -k venv\r\nGLOB sdist-make: /home/asottile/workspace/pre-commit/setup.py\r\npy36 inst-nodeps: /home/asottile/workspace/pre-commit/.tox/dist/pre_commit-1.10.0.zip\r\npy36 installed: You are using pip version 9.0.1, however version 10.0.1 is available.,You should consider upgrading via the 'pip install --upgrade pip' command.,aspy.yaml==1.1.1,atomicwrites==1.1.5,attrs==18.1.0,cached-property==1.4.2,cfgv==1.0.0,coverage==4.5.1,flake8==3.5.0,identify==1.0.18,mccabe==0.6.1,mock==2.0.0,more-itertools==4.2.0,nodeenv==1.3.0,pbr==4.0.3,pluggy==0.6.0,pre-commit==1.10.0,py==1.5.3,pycodestyle==2.3.1,pyflakes==1.6.0,pytest==3.6.0,pytest-env==0.6.2,PyYAML==3.12,six==1.11.0,toml==0.9.4,virtualenv==16.0.0\r\npy36 runtests: PYTHONHASHSEED='93802395'\r\npy36 runtests: commands[0] | coverage erase\r\npy36 runtests: commands[1] | coverage run -m pytest tests -k venv\r\n============================= test session starts ==============================\r\nplatform linux -- Python 3.6.5, pytest-3.6.0, py-1.5.3, pluggy-0.6.0\r\nrootdir: /home/asottile/workspace/pre-commit, inifile: tox.ini\r\nplugins: env-0.6.2\r\ncollected 500 items / 492 deselected                                           \r\n\r\ntests/repository_test.py ..                                              [ 25%]\r\ntests/commands/install_uninstall_test.py .                               [ 37%]\r\ntests/languages/all_test.py .....                                        [100%]\r\n\r\n=================== 8 passed, 492 deselected in 4.32 seconds ===================\r\npy36 runtests: commands[2] | coverage report --fail-under 99\r\nName                                              Stmts   Miss Branch BrPart  Cover   Missing\r\n---------------------------------------------------------------------------------------------\r\n...\r\n17 files skipped due to complete coverage.\r\nERROR: InvocationError: '/home/asottile/workspace/pre-commit/.tox/py36/bin/coverage report --fail-under 99'\r\n___________________________________ summary ____________________________________\r\nERROR:   py36: commands failed\r\n\r\n$ head -1 .tox/py36/bin/pip\r\n#!/tmp/pytest-of-asottile/pytest-3/test_python_venv0/0/.pre-commit/repo5xcuq11q/py_venv-python3.6/bin/python3.6\r\n```\n", "before_files": [{"content": "from __future__ import unicode_literals\n\nfrom pre_commit.languages import python\nfrom pre_commit.util import cmd_output\n\n\nENVIRONMENT_DIR = 'py_venv'\n\n\ndef make_venv(envdir, python):\n    cmd_output(python, '-mvenv', envdir, cwd='/')\n\n\nget_default_version = python.get_default_version\n_interface = python.py_interface(ENVIRONMENT_DIR, make_venv)\nin_env, healthy, run_hook, install_environment = _interface\n", "path": "pre_commit/languages/python_venv.py"}]}