mkdirp -> os.makedirs(..., exist_ok=True)

This commit is contained in:
Anthony Sottile 2020-01-12 11:50:40 -08:00
parent 67c2dcd90d
commit 2a9893d0f0
5 changed files with 9 additions and 21 deletions

View file

@ -14,7 +14,6 @@ from pre_commit.repository import all_hooks
from pre_commit.repository import install_hook_envs
from pre_commit.store import Store
from pre_commit.util import make_executable
from pre_commit.util import mkdirp
from pre_commit.util import resource_text
@ -78,7 +77,7 @@ def _install_hook_script(
) -> None:
hook_path, legacy_path = _hook_paths(hook_type, git_dir=git_dir)
mkdirp(os.path.dirname(hook_path))
os.makedirs(os.path.dirname(hook_path), exist_ok=True)
# If we have an existing hook, move it to pre-commit.legacy
if os.path.lexists(hook_path) and not is_our_script(hook_path):

View file

@ -8,7 +8,6 @@ from pre_commit import git
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 mkdirp
from pre_commit.xargs import xargs
@ -55,7 +54,7 @@ def _unstaged_changes_cleared(patch_dir: str) -> Generator[None, None, None]:
f'Stashing unstaged files to {patch_filename}.',
)
# Save the current unstaged changes as a patch
mkdirp(patch_dir)
os.makedirs(patch_dir, exist_ok=True)
with open(patch_filename, 'wb') as patch_file:
patch_file.write(diff_stdout_binary)

View file

@ -16,7 +16,6 @@ from pre_commit import git
from pre_commit.util import CalledProcessError
from pre_commit.util import clean_path_on_failure
from pre_commit.util import cmd_output_b
from pre_commit.util import mkdirp
from pre_commit.util import resource_text
from pre_commit.util import rmtree
@ -45,7 +44,7 @@ class Store:
self.db_path = os.path.join(self.directory, 'db.db')
if not os.path.exists(self.directory):
mkdirp(self.directory)
os.makedirs(self.directory, exist_ok=True)
with open(os.path.join(self.directory, 'README'), 'w') as f:
f.write(
'This directory is maintained by the pre-commit project.\n'

View file

@ -29,14 +29,6 @@ else: # pragma: no cover (<PY37)
EnvironT = Union[Dict[str, str], 'os._Environ']
def mkdirp(path: str) -> None:
try:
os.makedirs(path)
except OSError:
if not os.path.exists(path):
raise
@contextlib.contextmanager
def clean_path_on_failure(path: str) -> Generator[None, None, None]:
"""Cleans up the directory on an exceptional failure."""