summaryrefslogtreecommitdiffstats
path: root/pre_commit/util.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-01-30 16:53:19 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-01-30 16:53:19 +0000
commit02d5100afa71d1343de4066b812cd4cdc774d812 (patch)
tree6bccae957398fab29aaa226fb0bd65f0c258a36a /pre_commit/util.py
parentAdding upstream version 2.21.0. (diff)
downloadpre-commit-02d5100afa71d1343de4066b812cd4cdc774d812.tar.xz
pre-commit-02d5100afa71d1343de4066b812cd4cdc774d812.zip
Adding upstream version 3.0.2.upstream/3.0.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'pre_commit/util.py')
-rw-r--r--pre_commit/util.py35
1 files changed, 1 insertions, 34 deletions
diff --git a/pre_commit/util.py b/pre_commit/util.py
index b850768..8ea4844 100644
--- a/pre_commit/util.py
+++ b/pre_commit/util.py
@@ -2,36 +2,20 @@ from __future__ import annotations
import contextlib
import errno
-import functools
import importlib.resources
import os.path
import shutil
import stat
import subprocess
import sys
-import tempfile
from types import TracebackType
from typing import Any
from typing import Callable
from typing import Generator
from typing import IO
-import yaml
-
from pre_commit import parse_shebang
-Loader = getattr(yaml, 'CSafeLoader', yaml.SafeLoader)
-yaml_load = functools.partial(yaml.load, Loader=Loader)
-Dumper = getattr(yaml, 'CSafeDumper', yaml.SafeDumper)
-
-
-def yaml_dump(o: Any, **kwargs: Any) -> str:
- # when python/mypy#1484 is solved, this can be `functools.partial`
- return yaml.dump(
- o, Dumper=Dumper, default_flow_style=False, indent=4, sort_keys=False,
- **kwargs,
- )
-
def force_bytes(exc: Any) -> bytes:
with contextlib.suppress(TypeError):
@@ -52,18 +36,6 @@ def clean_path_on_failure(path: str) -> Generator[None, None, None]:
raise
-@contextlib.contextmanager
-def tmpdir() -> Generator[str, None, None]:
- """Contextmanager to create a temporary directory. It will be cleaned up
- afterwards.
- """
- tempdir = tempfile.mkdtemp()
- try:
- yield tempdir
- finally:
- rmtree(tempdir)
-
-
def resource_bytesio(filename: str) -> IO[bytes]:
return importlib.resources.open_binary('pre_commit.resources', filename)
@@ -127,7 +99,7 @@ def cmd_output_b(
_setdefault_kwargs(kwargs)
try:
- cmd = parse_shebang.normalize_cmd(cmd)
+ cmd = parse_shebang.normalize_cmd(cmd, env=kwargs.get('env'))
except parse_shebang.ExecutableNotFoundError as e:
returncode, stdout_b, stderr_b = e.to_output()
else:
@@ -254,10 +226,5 @@ def rmtree(path: str) -> None:
shutil.rmtree(path, ignore_errors=False, onerror=handle_remove_readonly)
-def parse_version(s: str) -> tuple[int, ...]:
- """poor man's version comparison"""
- return tuple(int(p) for p in s.split('.'))
-
-
def win_exe(s: str) -> str:
return s if sys.platform != 'win32' else f'{s}.exe'