mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 16:24:40 +04:00
Tests pass on windows
This commit is contained in:
parent
56e5c4eb2d
commit
143ed94500
21 changed files with 224 additions and 109 deletions
|
|
@ -13,7 +13,7 @@ ENVIRONMENT_DIR = 'node_env'
|
|||
class NodeEnv(helpers.Environment):
|
||||
@property
|
||||
def env_prefix(self):
|
||||
return '. {{prefix}}{0}/bin/activate &&'.format(ENVIRONMENT_DIR)
|
||||
return ". '{{prefix}}{0}/bin/activate' &&".format(ENVIRONMENT_DIR)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
|
|
@ -37,7 +37,7 @@ def install_environment(repo_cmd_runner, version='default'):
|
|||
repo_cmd_runner.run(cmd)
|
||||
|
||||
with in_env(repo_cmd_runner) as node_env:
|
||||
node_env.run('cd {prefix} && npm install -g')
|
||||
node_env.run("cd '{prefix}' && npm install -g")
|
||||
|
||||
|
||||
def run_hook(repo_cmd_runner, hook, file_args):
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import contextlib
|
||||
import distutils.spawn
|
||||
import os
|
||||
|
||||
import virtualenv
|
||||
|
||||
from pre_commit.languages import helpers
|
||||
from pre_commit.util import clean_path_on_failure
|
||||
|
|
@ -12,7 +16,12 @@ ENVIRONMENT_DIR = 'py_env'
|
|||
class PythonEnv(helpers.Environment):
|
||||
@property
|
||||
def env_prefix(self):
|
||||
return '. {{prefix}}{0}/bin/activate &&'.format(ENVIRONMENT_DIR)
|
||||
return ". '{{prefix}}{0}activate' &&".format(
|
||||
virtualenv.path_locations(
|
||||
ENVIRONMENT_DIR,
|
||||
)[-1].rstrip(os.sep) + os.sep,
|
||||
'activate',
|
||||
)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
|
|
@ -20,6 +29,15 @@ def in_env(repo_cmd_runner):
|
|||
yield PythonEnv(repo_cmd_runner)
|
||||
|
||||
|
||||
def norm_version(version):
|
||||
if os.name == 'nt': # pragma: no cover (windows)
|
||||
if not distutils.spawn.find_executable(version):
|
||||
# The default place for python on windows is:
|
||||
# C:\PythonXX\python.exe
|
||||
version = r'C:\{0}\python.exe'.format(version.replace('.', ''))
|
||||
return version
|
||||
|
||||
|
||||
def install_environment(repo_cmd_runner, version='default'):
|
||||
assert repo_cmd_runner.exists('setup.py')
|
||||
|
||||
|
|
@ -27,10 +45,10 @@ def install_environment(repo_cmd_runner, version='default'):
|
|||
with clean_path_on_failure(repo_cmd_runner.path(ENVIRONMENT_DIR)):
|
||||
venv_cmd = ['virtualenv', '{{prefix}}{0}'.format(ENVIRONMENT_DIR)]
|
||||
if version != 'default':
|
||||
venv_cmd.extend(['-p', version])
|
||||
venv_cmd.extend(['-p', norm_version(version)])
|
||||
repo_cmd_runner.run(venv_cmd)
|
||||
with in_env(repo_cmd_runner) as env:
|
||||
env.run('cd {prefix} && pip install .')
|
||||
env.run("cd '{prefix}' && pip install .")
|
||||
|
||||
|
||||
def run_hook(repo_cmd_runner, hook, file_args):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue