Skip to content

Commit 10078fe

Browse files
committed
Simply log the directory being created, rather than the whole ancestry.
1 parent cded66c commit 10078fe

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

distutils/dir_util.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def mkpath(name, mode=0o777, verbose=True, dry_run=False): # noqa: C901
2020
means the current directory, which of course exists), then do nothing.
2121
Raise DistutilsFileError if unable to create some directory along the way
2222
(eg. some sub-path exists, but is a file rather than a directory).
23-
If 'verbose' is true, print a one-line summary of each mkdir to stdout.
23+
If 'verbose' is true, log the directory created.
2424
Return the list of directories actually created.
2525
2626
os.makedirs is not used because:
@@ -36,12 +36,11 @@ def mkpath(name, mode=0o777, verbose=True, dry_run=False): # noqa: C901
3636
if not isinstance(name, str):
3737
raise DistutilsInternalError(f"mkpath: 'name' must be a string (got {name!r})")
3838

39-
# XXX what's the better way to handle verbosity? print as we create
40-
# each directory in the path (the current behaviour), or only announce
41-
# the creation of the whole path? (quite easy to do the latter since
42-
# we're not using a recursive algorithm)
43-
4439
name = os.path.normpath(name)
40+
41+
if verbose and not os.path.isdir(name):
42+
log.info("creating %s", name)
43+
4544
created_dirs = []
4645
if os.path.isdir(name) or name == '':
4746
return created_dirs
@@ -66,9 +65,6 @@ def mkpath(name, mode=0o777, verbose=True, dry_run=False): # noqa: C901
6665
if abs_head in _path_created:
6766
continue
6867

69-
if verbose >= 1:
70-
log.info("creating %s", head)
71-
7268
if not dry_run:
7369
try:
7470
os.mkdir(head, mode)

distutils/tests/test_dir_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_mkpath_remove_tree_verbosity(self, caplog):
3434
remove_tree(self.root_target, verbose=False)
3535

3636
mkpath(self.target, verbose=True)
37-
wanted = [f'creating {self.root_target}', f'creating {self.target}']
37+
wanted = [f'creating {self.target}']
3838
assert caplog.messages == wanted
3939
caplog.clear()
4040

0 commit comments

Comments
 (0)