Skip to content

Commit 9444891

Browse files
committed
Rearrabge maybe_make, and remove option that doesn't make sense in the context of that function.
1 parent cc8372a commit 9444891

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

domdf_python_tools/paths.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def delete(filename: PathLike, **kwargs):
149149
os.remove(os.path.join(os.getcwd(), filename), **kwargs)
150150

151151

152-
def maybe_make(directory: PathLike, mode: int = 0o777, parents: bool = False, exist_ok: bool = False):
152+
def maybe_make(directory: PathLike, mode: int = 0o777, parents: bool = False):
153153
"""
154154
Create a directory at the given path, but only if the directory does not already exist.
155155
@@ -164,18 +164,18 @@ def maybe_make(directory: PathLike, mode: int = 0o777, parents: bool = False, ex
164164
If :py:obj:`True`, any missing parents of this path are created as needed; they are created with the
165165
default permissions without taking mode into account (mimicking the POSIX mkdir -p command).
166166
:no-default parents:
167-
:param exist_ok: If :py:obj:`False` (the default), a :class:`FileExistsError` is raised if the
168-
target directory already exists. If :py:obj:`True`, :class:`FileExistsError` exceptions
169-
will be ignored (same behavior as the POSIX mkdir -p command), but only if the last path
170-
component is not an existing non-directory file.
171-
:no-default exist_ok:
167+
168+
.. versionchanged:: 1.6.0 Removed the ``'exist_ok'`` option, since it made no sense in this context.
169+
172170
"""
173171

174172
if not isinstance(directory, pathlib.Path):
175173
directory = pathlib.Path(directory)
176174

177-
if not directory.exists():
178-
directory.mkdir(mode, parents, exist_ok)
175+
try:
176+
directory.mkdir(mode, parents, exist_ok=True)
177+
except FileExistsError:
178+
pass
179179

180180

181181
def parent_path(path: PathLike) -> pathlib.Path:
@@ -365,7 +365,6 @@ def maybe_make(
365365
self,
366366
mode: int = 0o777,
367367
parents: bool = False,
368-
exist_ok: bool = False,
369368
):
370369
"""
371370
Create a directory at this path, but only if the directory does not already exist.
@@ -380,18 +379,18 @@ def maybe_make(
380379
If :py:obj:`True`, any missing parents of this path are created as needed; they are created with the
381380
default permissions without taking mode into account (mimicking the POSIX mkdir -p command).
382381
:no-default parents:
383-
:param exist_ok: If :py:obj:`False` (the default), a :class:`FileExistsError` is raised if the
384-
target directory already exists. If :py:obj:`True`, :class:`FileExistsError` exceptions
385-
will be ignored (same behavior as the POSIX mkdir -p command), but only if the last path
386-
component is not an existing non-directory file.
387-
:no-default exist_ok:
388382
389383
:rtype:
390384
391385
.. versionadded:: 0.3.8
386+
387+
.. versionchanged:: 1.6.0 Removed the ``'exist_ok'`` option, since it made no sense in this context.
392388
"""
393389

394-
maybe_make(self, mode=mode, parents=parents, exist_ok=exist_ok)
390+
try:
391+
self.mkdir(mode, parents, exist_ok=True)
392+
except FileExistsError:
393+
pass
395394

396395
def append_text(
397396
self,

0 commit comments

Comments
 (0)