mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-10 07:18:27 +01:00
py3: _makedirs -> os.makedirs
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user