Adding upstream version 2.14.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
af2c814963
commit
dcfd04081c
15 changed files with 148 additions and 56 deletions
|
@ -1,7 +1,6 @@
|
|||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import socket
|
||||
from typing import Sequence
|
||||
from typing import Tuple
|
||||
|
||||
|
@ -9,6 +8,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
|
||||
|
||||
|
@ -26,12 +26,28 @@ def _is_in_docker() -> bool:
|
|||
return False
|
||||
|
||||
|
||||
def _get_container_id() -> str:
|
||||
# It's assumed that we already check /proc/1/cgroup in _is_in_docker. The
|
||||
# cpuset cgroup controller existed since cgroups were introduced so this
|
||||
# way of getting the container ID is pretty reliable.
|
||||
with open('/proc/1/cgroup', 'rb') as f:
|
||||
for line in f.readlines():
|
||||
if line.split(b':')[1] == b'cpuset':
|
||||
return os.path.basename(line.split(b':')[2]).strip().decode()
|
||||
raise RuntimeError('Failed to find the container ID in /proc/1/cgroup.')
|
||||
|
||||
|
||||
def _get_docker_path(path: str) -> str:
|
||||
if not _is_in_docker():
|
||||
return path
|
||||
hostname = socket.gethostname()
|
||||
|
||||
_, out, _ = cmd_output_b('docker', 'inspect', hostname)
|
||||
container_id = _get_container_id()
|
||||
|
||||
try:
|
||||
_, out, _ = cmd_output_b('docker', 'inspect', container_id)
|
||||
except CalledProcessError:
|
||||
# self-container was not visible from here (perhaps docker-in-docker)
|
||||
return path
|
||||
|
||||
container, = json.loads(out)
|
||||
for mount in container['Mounts']:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue