From 9c4280958763ce4d194defbb9017f924cd49f106 Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Tue, 31 Dec 2019 22:12:11 -0600 Subject: [PATCH] py3: _makedirs -> os.makedirs --- dvc/utils/__init__.py | 5 ++--- dvc/utils/compat.py | 26 -------------------------- 2 files changed, 2 insertions(+), 29 deletions(-) diff --git a/dvc/utils/__init__.py b/dvc/utils/__init__.py index 19c3988db..4eecb1328 100644 --- a/dvc/utils/__init__.py +++ b/dvc/utils/__init__.py @@ -17,7 +17,6 @@ from shortuuid import uuid from dvc.utils.compat import fspath from dvc.utils.compat import fspath_py35 -from dvc.utils.compat import makedirs as _makedirs from dvc.utils.compat import open @@ -142,7 +141,7 @@ def makedirs(path, exist_ok=False, mode=None): path = fspath_py35(path) if mode is None: - _makedirs(path, exist_ok=exist_ok) + os.makedirs(path, exist_ok=exist_ok) return # utilize umask to set proper permissions since Python 3.7 the `mode` @@ -150,7 +149,7 @@ def makedirs(path, exist_ok=False, mode=None): # newly-created intermediate-level directories. umask = os.umask(0o777 - mode) try: - _makedirs(path, exist_ok=exist_ok) + os.makedirs(path, exist_ok=exist_ok) finally: os.umask(umask) diff --git a/dvc/utils/compat.py b/dvc/utils/compat.py index f9bac5175..8c0711ace 100644 --- a/dvc/utils/compat.py +++ b/dvc/utils/compat.py @@ -1,7 +1,6 @@ """Handle import compatibility between Python 2 and Python 3""" import errno -import os import sys from contextlib import contextmanager @@ -15,29 +14,6 @@ is_py2 = _ver[0] == 2 is_py3 = _ver[0] == 3 -def _makedirs(name, mode=0o777, exist_ok=False): - """Source: https://github.com/python/cpython/blob/ - 3ce3dea60646d8a5a1c952469a2eb65f937875b3/Lib/os.py#L196-L226 - """ - head, tail = os.path.split(name) - if not tail: - head, tail = os.path.split(head) - if head and tail and not os.path.exists(head): - try: - _makedirs(head, exist_ok=exist_ok) - except OSError as e: - if e.errno != errno.EEXIST: - raise - cdir = os.curdir - if tail == cdir: - return - try: - os.mkdir(name, mode) - except OSError: - if not exist_ok or not os.path.isdir(name): - raise - - @contextmanager def ignore_file_not_found(): try: @@ -63,7 +39,6 @@ if is_py2: numeric_types = (int, long, float) # noqa: F821 integer_types = (int, long) # noqa: F821 input = raw_input # noqa: F821 - makedirs = _makedirs range = xrange # noqa: F821 FileNotFoundError = IOError JSONDecodeError = ValueError @@ -88,7 +63,6 @@ if is_py2: elif is_py3: import pathlib # noqa: F401 - from os import makedirs # noqa: F401 from urllib.parse import ( # noqa: F401 urlparse, # noqa: F401 urlunparse, # noqa: F401