summaryrefslogtreecommitdiffstats
path: root/pre_commit/commands
diff options
context:
space:
mode:
Diffstat (limited to 'pre_commit/commands')
-rw-r--r--pre_commit/commands/autoupdate.py8
-rw-r--r--pre_commit/commands/migrate_config.py11
-rw-r--r--pre_commit/commands/run.py11
-rw-r--r--pre_commit/commands/try_repo.py6
-rw-r--r--pre_commit/commands/validate_config.py4
-rw-r--r--pre_commit/commands/validate_manifest.py4
6 files changed, 33 insertions, 11 deletions
diff --git a/pre_commit/commands/autoupdate.py b/pre_commit/commands/autoupdate.py
index d5352e5..7ed6e77 100644
--- a/pre_commit/commands/autoupdate.py
+++ b/pre_commit/commands/autoupdate.py
@@ -2,6 +2,7 @@ from __future__ import annotations
import os.path
import re
+import tempfile
from typing import Any
from typing import NamedTuple
from typing import Sequence
@@ -19,9 +20,8 @@ from pre_commit.store import Store
from pre_commit.util import CalledProcessError
from pre_commit.util import cmd_output
from pre_commit.util import cmd_output_b
-from pre_commit.util import tmpdir
-from pre_commit.util import yaml_dump
-from pre_commit.util import yaml_load
+from pre_commit.yaml import yaml_dump
+from pre_commit.yaml import yaml_load
class RevInfo(NamedTuple):
@@ -47,7 +47,7 @@ class RevInfo(NamedTuple):
'FETCH_HEAD', '--tags', '--exact',
)
- with tmpdir() as tmp:
+ with tempfile.TemporaryDirectory() as tmp:
git.init_repo(tmp, self.repo)
cmd_output_b(
*git_cmd, 'fetch', 'origin', 'HEAD', '--tags',
diff --git a/pre_commit/commands/migrate_config.py b/pre_commit/commands/migrate_config.py
index c3d0a50..6f7af4e 100644
--- a/pre_commit/commands/migrate_config.py
+++ b/pre_commit/commands/migrate_config.py
@@ -3,9 +3,11 @@ from __future__ import annotations
import re
import textwrap
+import cfgv
import yaml
-from pre_commit.util import yaml_load
+from pre_commit.clientlib import InvalidConfigError
+from pre_commit.yaml import yaml_load
def _is_header_line(line: str) -> bool:
@@ -44,6 +46,13 @@ def migrate_config(config_file: str, quiet: bool = False) -> int:
with open(config_file) as f:
orig_contents = contents = f.read()
+ with cfgv.reraise_as(InvalidConfigError):
+ with cfgv.validate_context(f'File {config_file}'):
+ try:
+ yaml_load(orig_contents)
+ except Exception as e:
+ raise cfgv.ValidationError(str(e))
+
contents = _migrate_map(contents)
contents = _migrate_sha_to_rev(contents)
diff --git a/pre_commit/commands/run.py b/pre_commit/commands/run.py
index 429e04c..e44e703 100644
--- a/pre_commit/commands/run.py
+++ b/pre_commit/commands/run.py
@@ -189,7 +189,16 @@ def _run_single_hook(
filenames = ()
time_before = time.time()
language = languages[hook.language]
- retcode, out = language.run_hook(hook, filenames, use_color)
+ with language.in_env(hook.prefix, hook.language_version):
+ retcode, out = language.run_hook(
+ hook.prefix,
+ hook.entry,
+ hook.args,
+ filenames,
+ is_local=hook.src == 'local',
+ require_serial=hook.require_serial,
+ color=use_color,
+ )
duration = round(time.time() - time_before, 2) or 0
diff_after = _get_diff()
diff --git a/pre_commit/commands/try_repo.py b/pre_commit/commands/try_repo.py
index ef099f5..539ed3c 100644
--- a/pre_commit/commands/try_repo.py
+++ b/pre_commit/commands/try_repo.py
@@ -3,6 +3,7 @@ from __future__ import annotations
import argparse
import logging
import os.path
+import tempfile
import pre_commit.constants as C
from pre_commit import git
@@ -11,9 +12,8 @@ from pre_commit.clientlib import load_manifest
from pre_commit.commands.run import run
from pre_commit.store import Store
from pre_commit.util import cmd_output_b
-from pre_commit.util import tmpdir
-from pre_commit.util import yaml_dump
from pre_commit.xargs import xargs
+from pre_commit.yaml import yaml_dump
logger = logging.getLogger(__name__)
@@ -49,7 +49,7 @@ def _repo_ref(tmpdir: str, repo: str, ref: str | None) -> tuple[str, str]:
def try_repo(args: argparse.Namespace) -> int:
- with tmpdir() as tempdir:
+ with tempfile.TemporaryDirectory() as tempdir:
repo, ref = _repo_ref(tempdir, args.repo, args.ref)
store = Store(tempdir)
diff --git a/pre_commit/commands/validate_config.py b/pre_commit/commands/validate_config.py
index 91bb017..24bd313 100644
--- a/pre_commit/commands/validate_config.py
+++ b/pre_commit/commands/validate_config.py
@@ -1,9 +1,11 @@
from __future__ import annotations
+from typing import Sequence
+
from pre_commit import clientlib
-def validate_config(filenames: list[str]) -> int:
+def validate_config(filenames: Sequence[str]) -> int:
ret = 0
for filename in filenames:
diff --git a/pre_commit/commands/validate_manifest.py b/pre_commit/commands/validate_manifest.py
index 372a638..419031a 100644
--- a/pre_commit/commands/validate_manifest.py
+++ b/pre_commit/commands/validate_manifest.py
@@ -1,9 +1,11 @@
from __future__ import annotations
+from typing import Sequence
+
from pre_commit import clientlib
-def validate_manifest(filenames: list[str]) -> int:
+def validate_manifest(filenames: Sequence[str]) -> int:
ret = 0
for filename in filenames: