Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pre_commit/commands/autoupdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os.path
import re
import tempfile
from typing import Any
from typing import NamedTuple
from typing import Sequence
Expand All @@ -19,7 +20,6 @@
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

Expand Down Expand Up @@ -47,7 +47,7 @@ def update(self, tags_only: bool, freeze: bool) -> RevInfo:
'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',
Expand Down
4 changes: 2 additions & 2 deletions pre_commit/commands/try_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import argparse
import logging
import os.path
import tempfile

import pre_commit.constants as C
from pre_commit import git
Expand All @@ -11,7 +12,6 @@
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

Expand Down Expand Up @@ -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)
Expand Down
13 changes: 0 additions & 13 deletions pre_commit/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import stat
import subprocess
import sys
import tempfile
from types import TracebackType
from typing import Any
from typing import Callable
Expand Down Expand Up @@ -52,18 +51,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)

Expand Down
7 changes: 0 additions & 7 deletions tests/util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from pre_commit.util import make_executable
from pre_commit.util import parse_version
from pre_commit.util import rmtree
from pre_commit.util import tmpdir


def test_CalledProcessError_str():
Expand Down Expand Up @@ -74,12 +73,6 @@ class MySystemExit(SystemExit):
assert not os.path.exists('foo')


def test_tmpdir():
with tmpdir() as tempdir:
assert os.path.exists(tempdir)
assert not os.path.exists(tempdir)


def test_cmd_output_exe_not_found():
ret, out, _ = cmd_output('dne', check=False)
assert ret == 1
Expand Down