mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-14 13:00:10 -06:00
remove docker_is_running check from source
Moved to testing.util so it can be used for the skipif_cant_run_docker test hooks.
This commit is contained in:
committed by
Anthony Sottile
parent
f1de792877
commit
eb8b48aeb4
@@ -7,9 +7,7 @@ import pre_commit.constants as C
|
||||
from pre_commit.hook import Hook
|
||||
from pre_commit.languages import helpers
|
||||
from pre_commit.prefix import Prefix
|
||||
from pre_commit.util import CalledProcessError
|
||||
from pre_commit.util import clean_path_on_failure
|
||||
from pre_commit.util import cmd_output_b
|
||||
|
||||
ENVIRONMENT_DIR = 'docker'
|
||||
PRE_COMMIT_LABEL = 'PRE_COMMIT'
|
||||
@@ -26,21 +24,6 @@ def docker_tag(prefix: Prefix) -> str: # pragma: win32 no cover
|
||||
return f'pre-commit-{md5sum}'
|
||||
|
||||
|
||||
def docker_is_running() -> bool: # pragma: win32 no cover
|
||||
try:
|
||||
cmd_output_b('docker', 'ps')
|
||||
except CalledProcessError:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def assert_docker_available() -> None: # pragma: win32 no cover
|
||||
assert docker_is_running(), (
|
||||
'Docker is either not running or not configured in this environment'
|
||||
)
|
||||
|
||||
|
||||
def build_docker_image(
|
||||
prefix: Prefix,
|
||||
*,
|
||||
@@ -63,7 +46,6 @@ def install_environment(
|
||||
) -> None: # pragma: win32 no cover
|
||||
helpers.assert_version_default('docker', version)
|
||||
helpers.assert_no_additional_deps('docker', additional_dependencies)
|
||||
assert_docker_available()
|
||||
|
||||
directory = prefix.path(
|
||||
helpers.environment_dir(ENVIRONMENT_DIR, C.DEFAULT),
|
||||
@@ -101,7 +83,6 @@ def run_hook(
|
||||
file_args: Sequence[str],
|
||||
color: bool,
|
||||
) -> 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.
|
||||
build_docker_image(hook.prefix, pull=False)
|
||||
|
||||
@@ -3,7 +3,6 @@ from typing import Tuple
|
||||
|
||||
from pre_commit.hook import Hook
|
||||
from pre_commit.languages import helpers
|
||||
from pre_commit.languages.docker import assert_docker_available
|
||||
from pre_commit.languages.docker import docker_cmd
|
||||
|
||||
ENVIRONMENT_DIR = None
|
||||
@@ -17,6 +16,5 @@ def run_hook(
|
||||
file_args: Sequence[str],
|
||||
color: bool,
|
||||
) -> 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)
|
||||
|
||||
@@ -5,14 +5,24 @@ import subprocess
|
||||
import pytest
|
||||
|
||||
from pre_commit import parse_shebang
|
||||
from pre_commit.languages.docker import docker_is_running
|
||||
from pre_commit.util import CalledProcessError
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import cmd_output_b
|
||||
from testing.auto_namedtuple import auto_namedtuple
|
||||
|
||||
|
||||
TESTING_DIR = os.path.abspath(os.path.dirname(__file__))
|
||||
|
||||
|
||||
def docker_is_running() -> bool: # pragma: win32 no cover
|
||||
try:
|
||||
cmd_output_b('docker', 'ps')
|
||||
except CalledProcessError: # pragma: no cover
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def get_resource_path(path):
|
||||
return os.path.join(TESTING_DIR, 'resources', path)
|
||||
|
||||
|
||||
@@ -1,15 +1,6 @@
|
||||
from unittest import mock
|
||||
|
||||
from pre_commit.languages import docker
|
||||
from pre_commit.util import CalledProcessError
|
||||
|
||||
|
||||
def test_docker_is_running_process_error():
|
||||
with mock.patch(
|
||||
'pre_commit.languages.docker.cmd_output_b',
|
||||
side_effect=CalledProcessError(1, (), 0, b'', None),
|
||||
):
|
||||
assert docker.docker_is_running() is False
|
||||
|
||||
|
||||
def test_docker_fallback_user():
|
||||
|
||||
Reference in New Issue
Block a user