diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-01-30 16:53:22 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-01-30 16:53:22 +0000 |
commit | ce6763317433ca8509f45bd1d471fb4ad2eeffdd (patch) | |
tree | a648ad7d54a5d3ffaa8519e7c73ea27541105c9b /pre_commit/util.py | |
parent | Releasing debian version 2.21.0-1. (diff) | |
download | pre-commit-ce6763317433ca8509f45bd1d471fb4ad2eeffdd.tar.xz pre-commit-ce6763317433ca8509f45bd1d471fb4ad2eeffdd.zip |
Merging upstream version 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.py | 35 |
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' |