Repository: pre-commit/pre-commit

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')
>>>
```



Discussion:

Resolving patch:
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,
         )
 
 


Test patch: