Fixups to make appveyor happy

This commit is contained in:
Anthony Sottile 2017-01-16 17:55:34 -08:00
parent 1e5c3324e3
commit b6937f33e2
8 changed files with 41 additions and 43 deletions

View file

@ -14,6 +14,8 @@ omit =
exclude_lines = exclude_lines =
# Have to re-enable the standard pragma # Have to re-enable the standard pragma
\#\s*pragma: no cover \#\s*pragma: no cover
# We optionally substitute this
${COVERAGE_IGNORE_WINDOWS}
# Don't complain if tests don't hit defensive assertion code: # Don't complain if tests don't hit defensive assertion code:
^\s*raise AssertionError\b ^\s*raise AssertionError\b

View file

@ -1,4 +1,7 @@
environment: environment:
global:
COVERAGE_IGNORE_WINDOWS: '# pragma: windows no cover'
TOX_TESTENV_PASSENV: COVERAGE_IGNORE_WINDOWS
matrix: matrix:
- TOXENV: py27 - TOXENV: py27
- TOXENV: py35 - TOXENV: py35

View file

@ -16,30 +16,30 @@ ENVIRONMENT_DIR = 'docker'
PRE_COMMIT_LABEL = 'PRE_COMMIT' PRE_COMMIT_LABEL = 'PRE_COMMIT'
def md5(s): def md5(s): # pragma: windows no cover
return hashlib.md5(five.to_bytes(s)).hexdigest() return hashlib.md5(five.to_bytes(s)).hexdigest()
def docker_tag(repo_cmd_runner): def docker_tag(repo_cmd_runner): # pragma: windows no cover
return 'pre-commit-{}'.format( return 'pre-commit-{}'.format(
md5(os.path.basename(repo_cmd_runner.path())) md5(os.path.basename(repo_cmd_runner.path()))
).lower() ).lower()
def docker_is_running(): def docker_is_running(): # pragma: windows no cover
try: try:
return cmd_output('docker', 'ps')[0] == 0 return cmd_output('docker', 'ps')[0] == 0
except CalledProcessError: except CalledProcessError:
return False return False
def assert_docker_available(): def assert_docker_available(): # pragma: windows no cover
assert docker_is_running(), ( assert docker_is_running(), (
'Docker is either not running or not configured in this environment' 'Docker is either not running or not configured in this environment'
) )
def build_docker_image(repo_cmd_runner, **kwargs): def build_docker_image(repo_cmd_runner, **kwargs): # pragma: windows no cover
pull = kwargs.pop('pull') pull = kwargs.pop('pull')
assert not kwargs, kwargs assert not kwargs, kwargs
cmd = ( cmd = (
@ -56,7 +56,7 @@ def install_environment(
repo_cmd_runner, repo_cmd_runner,
version='default', version='default',
additional_dependencies=(), additional_dependencies=(),
): ): # pragma: windows no cover
assert repo_cmd_runner.exists('Dockerfile'), ( assert repo_cmd_runner.exists('Dockerfile'), (
'No Dockerfile was found in the hook repository' 'No Dockerfile was found in the hook repository'
) )
@ -65,9 +65,9 @@ def install_environment(
) )
assert_docker_available() assert_docker_available()
directory = repo_cmd_runner.path(helpers.environment_dir( directory = repo_cmd_runner.path(
ENVIRONMENT_DIR, 'default', helpers.environment_dir(ENVIRONMENT_DIR, 'default'),
)) )
# Docker doesn't really have relevant disk environment, but pre-commit # Docker doesn't really have relevant disk environment, but pre-commit
# still needs to cleanup it's state files on failure # still needs to cleanup it's state files on failure
@ -76,7 +76,7 @@ def install_environment(
os.mkdir(directory) os.mkdir(directory)
def run_hook(repo_cmd_runner, hook, file_args): def run_hook(repo_cmd_runner, hook, file_args): # pragma: windows no cover
assert_docker_available() assert_docker_available()
# Rebuild the docker image in case it has gone missing, as many people do # Rebuild the docker image in case it has gone missing, as many people do
# automated cleanup of docker images. # automated cleanup of docker images.

View file

@ -14,7 +14,7 @@ from pre_commit.xargs import xargs
ENVIRONMENT_DIR = 'node_env' ENVIRONMENT_DIR = 'node_env'
def get_env_patch(venv): def get_env_patch(venv): # pragma: windows no cover
return ( return (
('NODE_VIRTUAL_ENV', venv), ('NODE_VIRTUAL_ENV', venv),
('NPM_CONFIG_PREFIX', venv), ('NPM_CONFIG_PREFIX', venv),
@ -25,9 +25,8 @@ def get_env_patch(venv):
@contextlib.contextmanager @contextlib.contextmanager
def in_env(repo_cmd_runner, language_version): def in_env(repo_cmd_runner, language_version): # pragma: windows no cover
envdir = os.path.join( envdir = repo_cmd_runner.path(
repo_cmd_runner.prefix_dir,
helpers.environment_dir(ENVIRONMENT_DIR, language_version), helpers.environment_dir(ENVIRONMENT_DIR, language_version),
) )
with envcontext(get_env_patch(envdir)): with envcontext(get_env_patch(envdir)):
@ -38,7 +37,7 @@ def install_environment(
repo_cmd_runner, repo_cmd_runner,
version='default', version='default',
additional_dependencies=(), additional_dependencies=(),
): ): # pragma: windows no cover
additional_dependencies = tuple(additional_dependencies) additional_dependencies = tuple(additional_dependencies)
assert repo_cmd_runner.exists('package.json') assert repo_cmd_runner.exists('package.json')
directory = helpers.environment_dir(ENVIRONMENT_DIR, version) directory = helpers.environment_dir(ENVIRONMENT_DIR, version)
@ -62,6 +61,6 @@ def install_environment(
) )
def run_hook(repo_cmd_runner, hook, file_args): def run_hook(repo_cmd_runner, hook, file_args): # pragma: windows no cover
with in_env(repo_cmd_runner, hook['language_version']): with in_env(repo_cmd_runner, hook['language_version']):
return xargs(helpers.to_cmd(hook), file_args) return xargs(helpers.to_cmd(hook), file_args)

View file

@ -32,8 +32,7 @@ def get_env_patch(venv):
@contextlib.contextmanager @contextlib.contextmanager
def in_env(repo_cmd_runner, language_version): def in_env(repo_cmd_runner, language_version):
envdir = os.path.join( envdir = repo_cmd_runner.path(
repo_cmd_runner.prefix_dir,
helpers.environment_dir(ENVIRONMENT_DIR, language_version), helpers.environment_dir(ENVIRONMENT_DIR, language_version),
) )
with envcontext(get_env_patch(envdir)): with envcontext(get_env_patch(envdir)):

View file

@ -18,7 +18,7 @@ from pre_commit.xargs import xargs
ENVIRONMENT_DIR = 'rbenv' ENVIRONMENT_DIR = 'rbenv'
def get_env_patch(venv, language_version): def get_env_patch(venv, language_version): # pragma: windows no cover
patches = ( patches = (
('GEM_HOME', os.path.join(venv, 'gems')), ('GEM_HOME', os.path.join(venv, 'gems')),
('RBENV_ROOT', venv), ('RBENV_ROOT', venv),
@ -34,16 +34,17 @@ def get_env_patch(venv, language_version):
@contextlib.contextmanager @contextlib.contextmanager
def in_env(repo_cmd_runner, language_version): def in_env(repo_cmd_runner, language_version): # pragma: windows no cover
envdir = os.path.join( envdir = repo_cmd_runner.path(
repo_cmd_runner.prefix_dir,
helpers.environment_dir(ENVIRONMENT_DIR, language_version), helpers.environment_dir(ENVIRONMENT_DIR, language_version),
) )
with envcontext(get_env_patch(envdir, language_version)): with envcontext(get_env_patch(envdir, language_version)):
yield yield
def _install_rbenv(repo_cmd_runner, version='default'): def _install_rbenv(
repo_cmd_runner, version='default',
): # pragma: windows no cover
directory = helpers.environment_dir(ENVIRONMENT_DIR, version) directory = helpers.environment_dir(ENVIRONMENT_DIR, version)
with tarfile.open(resource_filename('rbenv.tar.gz')) as tf: with tarfile.open(resource_filename('rbenv.tar.gz')) as tf:
@ -86,7 +87,7 @@ def _install_rbenv(repo_cmd_runner, version='default'):
activate_file.write('export RBENV_VERSION="{}"\n'.format(version)) activate_file.write('export RBENV_VERSION="{}"\n'.format(version))
def _install_ruby(runner, version): def _install_ruby(runner, version): # pragma: windows no cover
try: try:
helpers.run_setup_cmd(runner, ('rbenv', 'download', version)) helpers.run_setup_cmd(runner, ('rbenv', 'download', version))
except CalledProcessError: # pragma: no cover (usually find with download) except CalledProcessError: # pragma: no cover (usually find with download)
@ -98,7 +99,7 @@ def install_environment(
repo_cmd_runner, repo_cmd_runner,
version='default', version='default',
additional_dependencies=(), additional_dependencies=(),
): ): # pragma: windows no cover
additional_dependencies = tuple(additional_dependencies) additional_dependencies = tuple(additional_dependencies)
directory = helpers.environment_dir(ENVIRONMENT_DIR, version) directory = helpers.environment_dir(ENVIRONMENT_DIR, version)
with clean_path_on_failure(repo_cmd_runner.path(directory)): with clean_path_on_failure(repo_cmd_runner.path(directory)):
@ -126,6 +127,6 @@ def install_environment(
) )
def run_hook(repo_cmd_runner, hook, file_args): def run_hook(repo_cmd_runner, hook, file_args): # pragma: windows no cover
with in_env(repo_cmd_runner, hook['language_version']): with in_env(repo_cmd_runner, hook['language_version']):
return xargs(helpers.to_cmd(hook), file_args) return xargs(helpers.to_cmd(hook), file_args)

View file

@ -14,20 +14,14 @@ BUILD_DIR = '.build'
BUILD_CONFIG = 'release' BUILD_CONFIG = 'release'
def get_env_patch(venv): def get_env_patch(venv): # pragma: windows no cover
bin_path = os.path.join(venv, BUILD_DIR, BUILD_CONFIG) bin_path = os.path.join(venv, BUILD_DIR, BUILD_CONFIG)
patches = ( return (('PATH', (bin_path, os.pathsep, Var('PATH'))),)
('PATH', (
bin_path, os.pathsep, Var('PATH'),
)),
)
return patches
@contextlib.contextmanager @contextlib.contextmanager
def in_env(repo_cmd_runner): def in_env(repo_cmd_runner): # pragma: windows no cover
envdir = os.path.join( envdir = repo_cmd_runner.path(
repo_cmd_runner.prefix_dir,
helpers.environment_dir(ENVIRONMENT_DIR, 'default'), helpers.environment_dir(ENVIRONMENT_DIR, 'default'),
) )
with envcontext(get_env_patch(envdir)): with envcontext(get_env_patch(envdir)):
@ -38,13 +32,13 @@ def install_environment(
repo_cmd_runner, repo_cmd_runner,
version='default', version='default',
additional_dependencies=(), additional_dependencies=(),
): ): # pragma: windows no cover
assert version == 'default', ( assert version == 'default', (
'Pre-commit does not support language_version for docker ' 'Pre-commit does not support language_version for docker '
) )
directory = repo_cmd_runner.path(helpers.environment_dir( directory = repo_cmd_runner.path(
ENVIRONMENT_DIR, 'default', helpers.environment_dir(ENVIRONMENT_DIR, 'default'),
)) )
# Build the swift package # Build the swift package
with clean_path_on_failure(directory): with clean_path_on_failure(directory):
@ -57,6 +51,6 @@ def install_environment(
)) ))
def run_hook(repo_cmd_runner, hook, file_args): def run_hook(repo_cmd_runner, hook, file_args): # pragma: windows no cover
with in_env(repo_cmd_runner): with in_env(repo_cmd_runner):
return xargs(helpers.to_cmd(hook), file_args) return xargs(helpers.to_cmd(hook), file_args)

View file

@ -1,12 +1,12 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import distutils
import os.path import os.path
import shutil import shutil
import jsonschema import jsonschema
import pytest import pytest
from pre_commit import parse_shebang
from pre_commit.languages.docker import docker_is_running from pre_commit.languages.docker import docker_is_running
from pre_commit.util import cmd_output from pre_commit.util import cmd_output
from pre_commit.util import cwd from pre_commit.util import cwd
@ -70,7 +70,7 @@ skipif_slowtests_false = pytest.mark.skipif(
) )
skipif_cant_run_swift = pytest.mark.skipif( skipif_cant_run_swift = pytest.mark.skipif(
distutils.spawn.find_executable('swift') is None, parse_shebang.find_executable('swift') is None,
reason='swift isn\'t installed or can\'t be found' reason='swift isn\'t installed or can\'t be found'
) )