Use covdefaults to handle coveragerc

This commit is contained in:
Anthony Sottile
2020-02-29 14:00:31 -08:00
parent 4a3b10f0ed
commit 67c1beb322
19 changed files with 42 additions and 81 deletions

View File

@@ -17,16 +17,16 @@ get_default_version = helpers.basic_get_default_version
healthy = helpers.basic_healthy
def md5(s: str) -> str: # pragma: windows no cover
def md5(s: str) -> str: # pragma: win32 no cover
return hashlib.md5(s.encode()).hexdigest()
def docker_tag(prefix: Prefix) -> str: # pragma: windows no cover
def docker_tag(prefix: Prefix) -> str: # pragma: win32 no cover
md5sum = md5(os.path.basename(prefix.prefix_dir)).lower()
return f'pre-commit-{md5sum}'
def docker_is_running() -> bool: # pragma: windows no cover
def docker_is_running() -> bool: # pragma: win32 no cover
try:
cmd_output_b('docker', 'ps')
except CalledProcessError:
@@ -35,7 +35,7 @@ def docker_is_running() -> bool: # pragma: windows no cover
return True
def assert_docker_available() -> None: # pragma: windows no cover
def assert_docker_available() -> None: # pragma: win32 no cover
assert docker_is_running(), (
'Docker is either not running or not configured in this environment'
)
@@ -45,7 +45,7 @@ def build_docker_image(
prefix: Prefix,
*,
pull: bool,
) -> None: # pragma: windows no cover
) -> None: # pragma: win32 no cover
cmd: Tuple[str, ...] = (
'docker', 'build',
'--tag', docker_tag(prefix),
@@ -60,7 +60,7 @@ def build_docker_image(
def install_environment(
prefix: Prefix, version: str, additional_dependencies: Sequence[str],
) -> None: # pragma: windows no cover
) -> None: # pragma: win32 no cover
helpers.assert_version_default('docker', version)
helpers.assert_no_additional_deps('docker', additional_dependencies)
assert_docker_available()
@@ -76,14 +76,14 @@ def install_environment(
os.mkdir(directory)
def get_docker_user() -> str: # pragma: windows no cover
def get_docker_user() -> str: # pragma: win32 no cover
try:
return f'{os.getuid()}:{os.getgid()}'
except AttributeError:
return '1000:1000'
def docker_cmd() -> Tuple[str, ...]: # pragma: windows no cover
def docker_cmd() -> Tuple[str, ...]: # pragma: win32 no cover
return (
'docker', 'run',
'--rm',
@@ -100,7 +100,7 @@ def run_hook(
hook: Hook,
file_args: Sequence[str],
color: bool,
) -> Tuple[int, bytes]: # pragma: windows no cover
) -> Tuple[int, bytes]: # pragma: win32 no cover
assert_docker_available()
# Rebuild the docker image in case it has gone missing, as many people do
# automated cleanup of docker images.

View File

@@ -16,7 +16,7 @@ def run_hook(
hook: Hook,
file_args: Sequence[str],
color: bool,
) -> Tuple[int, bytes]: # pragma: windows no cover
) -> Tuple[int, bytes]: # pragma: win32 no cover
assert_docker_available()
cmd = docker_cmd() + hook.cmd
return helpers.run_xargs(hook, cmd, file_args, color=color)

View File

@@ -35,7 +35,7 @@ def get_env_patch(venv: str) -> PatchesT:
elif sys.platform == 'win32': # pragma: no cover
install_prefix = bin_dir(venv)
lib_dir = 'Scripts'
else: # pragma: windows no cover
else: # pragma: win32 no cover
install_prefix = venv
lib_dir = 'lib'
return (

View File

@@ -25,7 +25,7 @@ healthy = helpers.basic_healthy
def get_env_patch(
venv: str,
language_version: str,
) -> PatchesT: # pragma: windows no cover
) -> PatchesT: # pragma: win32 no cover
patches: PatchesT = (
('GEM_HOME', os.path.join(venv, 'gems')),
('RBENV_ROOT', venv),
@@ -43,7 +43,7 @@ def get_env_patch(
return patches
@contextlib.contextmanager # pragma: windows no cover
@contextlib.contextmanager # pragma: win32 no cover
def in_env(
prefix: Prefix,
language_version: str,
@@ -64,7 +64,7 @@ def _extract_resource(filename: str, dest: str) -> None:
def _install_rbenv(
prefix: Prefix,
version: str = C.DEFAULT,
) -> None: # pragma: windows no cover
) -> None: # pragma: win32 no cover
directory = helpers.environment_dir(ENVIRONMENT_DIR, version)
_extract_resource('rbenv.tar.gz', prefix.path('.'))
@@ -80,7 +80,7 @@ def _install_rbenv(
def _install_ruby(
prefix: Prefix,
version: str,
) -> None: # pragma: windows no cover
) -> None: # pragma: win32 no cover
try:
helpers.run_setup_cmd(prefix, ('rbenv', 'download', version))
except CalledProcessError: # pragma: no cover (usually find with download)
@@ -90,7 +90,7 @@ def _install_ruby(
def install_environment(
prefix: Prefix, version: str, additional_dependencies: Sequence[str],
) -> None: # pragma: windows no cover
) -> None: # pragma: win32 no cover
additional_dependencies = tuple(additional_dependencies)
directory = helpers.environment_dir(ENVIRONMENT_DIR, version)
with clean_path_on_failure(prefix.path(directory)):
@@ -121,6 +121,6 @@ def run_hook(
hook: Hook,
file_args: Sequence[str],
color: bool,
) -> Tuple[int, bytes]: # pragma: windows no cover
) -> Tuple[int, bytes]: # pragma: win32 no cover
with in_env(hook.prefix, hook.language_version):
return helpers.run_xargs(hook, hook.cmd, file_args, color=color)

View File

@@ -21,12 +21,12 @@ BUILD_DIR = '.build'
BUILD_CONFIG = 'release'
def get_env_patch(venv: str) -> PatchesT: # pragma: windows no cover
def get_env_patch(venv: str) -> PatchesT: # pragma: win32 no cover
bin_path = os.path.join(venv, BUILD_DIR, BUILD_CONFIG)
return (('PATH', (bin_path, os.pathsep, Var('PATH'))),)
@contextlib.contextmanager # pragma: windows no cover
@contextlib.contextmanager # pragma: win32 no cover
def in_env(prefix: Prefix) -> Generator[None, None, None]:
envdir = prefix.path(
helpers.environment_dir(ENVIRONMENT_DIR, C.DEFAULT),
@@ -37,7 +37,7 @@ def in_env(prefix: Prefix) -> Generator[None, None, None]:
def install_environment(
prefix: Prefix, version: str, additional_dependencies: Sequence[str],
) -> None: # pragma: windows no cover
) -> None: # pragma: win32 no cover
helpers.assert_version_default('swift', version)
helpers.assert_no_additional_deps('swift', additional_dependencies)
directory = prefix.path(
@@ -59,6 +59,6 @@ def run_hook(
hook: Hook,
file_args: Sequence[str],
color: bool,
) -> Tuple[int, bytes]: # pragma: windows no cover
) -> Tuple[int, bytes]: # pragma: win32 no cover
with in_env(hook.prefix):
return helpers.run_xargs(hook, hook.cmd, file_args, color=color)