Merge pull request #335 from pre-commit/fix_for_latest_virtualenv

Fix pre-commit for latest virtualenv.  Resolves #299.  Resolves #334
This commit is contained in:
Anthony Sottile 2016-01-19 18:34:18 -08:00
commit 6adf242444
2 changed files with 15 additions and 5 deletions

View file

@ -5,8 +5,6 @@ import distutils.spawn
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 @@ from pre_commit.util import shell_escape
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,
)

View file

@ -6,3 +6,6 @@ flake8
mock
pylint<1.4
pytest
# setuptools breaks pypy3 with extraneous output
setuptools<18.5