Skip to content

Commit eca5d2d

Browse files
committed
Move makedirs to fs.py
1 parent 277d28c commit eca5d2d

File tree

15 files changed

+62
-60
lines changed

15 files changed

+62
-60
lines changed

dvc/analytics.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
from dvc.lock import Lock, LockError
1717
from dvc.repo import Repo
1818
from dvc.scm import SCM
19-
from dvc.utils import env2bool, is_binary, makedirs
19+
from dvc.utils import env2bool, is_binary
20+
from dvc.utils.fs import makedirs
2021

2122

2223
logger = logging.getLogger(__name__)

dvc/remote/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
from dvc.progress import Tqdm
2525
from dvc.remote.slow_link_detection import slow_link_guard
2626
from dvc.state import StateNoop
27-
from dvc.utils import makedirs, relpath, tmp_fname
28-
from dvc.utils.fs import move
27+
from dvc.utils import relpath, tmp_fname
28+
from dvc.utils.fs import move, makedirs
2929
from dvc.utils.http import open_url
3030

3131
logger = logging.getLogger(__name__)

dvc/remote/local.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@
2323
from dvc.system import System
2424
from dvc.utils import copyfile
2525
from dvc.utils import file_md5
26-
from dvc.utils import makedirs
2726
from dvc.utils import relpath
2827
from dvc.utils import tmp_fname
2928
from dvc.utils import walk_files
3029
from dvc.compat import fspath_py35
31-
from dvc.utils.fs import move
32-
from dvc.utils.fs import remove
30+
from dvc.utils.fs import move, makedirs, remove
3331

3432
logger = logging.getLogger(__name__)
3533

dvc/repo/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def __init__(self, root_dir=None):
7272
from dvc.repo.metrics import Metrics
7373
from dvc.scm.tree import WorkingTree
7474
from dvc.repo.tag import Tag
75-
from dvc.utils import makedirs
75+
from dvc.utils.fs import makedirs
7676

7777
root_dir = self.find_root(root_dir)
7878

dvc/utils/__init__.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -135,23 +135,6 @@ def copyfile(src, dest, no_progress_bar=False, name=None):
135135
pbar.update(len(buf))
136136

137137

138-
def makedirs(path, exist_ok=False, mode=None):
139-
path = fspath_py35(path)
140-
141-
if mode is None:
142-
os.makedirs(path, exist_ok=exist_ok)
143-
return
144-
145-
# utilize umask to set proper permissions since Python 3.7 the `mode`
146-
# `makedirs` argument no longer affects the file permission bits of
147-
# newly-created intermediate-level directories.
148-
umask = os.umask(0o777 - mode)
149-
try:
150-
os.makedirs(path, exist_ok=exist_ok)
151-
finally:
152-
os.umask(umask)
153-
154-
155138
def _split(list_to_split, chunk_size):
156139
return [
157140
list_to_split[i : i + chunk_size]

dvc/utils/fs.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,20 @@ def normalize_path(path):
152152
parent = os.path.join(normalize_path(parent), "")
153153
child = normalize_path(child)
154154
return child != parent and child.startswith(parent)
155+
156+
157+
def makedirs(path, exist_ok=False, mode=None):
158+
path = fspath_py35(path)
159+
160+
if mode is None:
161+
os.makedirs(path, exist_ok=exist_ok)
162+
return
163+
164+
# utilize umask to set proper permissions since Python 3.7 the `mode`
165+
# `makedirs` argument no longer affects the file permission bits of
166+
# newly-created intermediate-level directories.
167+
umask = os.umask(0o777 - mode)
168+
try:
169+
os.makedirs(path, exist_ok=exist_ok)
170+
finally:
171+
os.umask(umask)

tests/dir_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
import pytest
5151
from funcy.py3 import lmap, retry
5252

53-
from dvc.utils import makedirs
53+
from dvc.utils.fs import makedirs
5454
from dvc.compat import fspath, fspath_py35
5555

5656

tests/func/test_fs.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import os
2+
import stat
3+
4+
import pytest
5+
6+
from dvc.utils.fs import makedirs
7+
8+
9+
@pytest.mark.skipif(os.name == "nt", reason="Not supported for Windows.")
10+
def test_makedirs_permissions(tmp_dir):
11+
dir_mode = 0o755
12+
intermediate_dir = "тестовая-директория"
13+
test_dir = os.path.join(intermediate_dir, "data")
14+
15+
assert not os.path.exists(intermediate_dir)
16+
17+
makedirs(test_dir, mode=dir_mode)
18+
19+
assert stat.S_IMODE(os.stat(test_dir).st_mode) == dir_mode
20+
assert stat.S_IMODE(os.stat(intermediate_dir).st_mode) == dir_mode

tests/func/test_get.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from dvc.repo.get import GetDVCFileError, PathMissingError
1010
from dvc.repo import Repo
1111
from dvc.system import System
12-
from dvc.utils import makedirs
12+
from dvc.utils.fs import makedirs
1313
from dvc.compat import fspath
1414
from tests.utils import trees_equal
1515

tests/func/test_get_url.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pytest
55

66
from dvc.repo import Repo
7-
from dvc.utils import makedirs
7+
from dvc.utils.fs import makedirs
88

99

1010
def test_get_file(repo_dir):

0 commit comments

Comments
 (0)