Skip to content

Commit

Permalink
building: use os.makedirs(exist_ok=True) when creating directories
Browse files Browse the repository at this point in the history
When creating parent directory structure for collected files
in COLLECT and BUNDLE, avoid explicitly checking whether the
directory already exists. Instead, call `os.makedirs` with
`exists_ok=True` and catch the `FileExistsError`.
  • Loading branch information
rokm committed Jun 14, 2023
1 parent b1cdbf1 commit eb6e396
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions PyInstaller/building/api.py
Expand Up @@ -964,9 +964,9 @@ def assemble(self):
# Create parent directory structure, if necessary
dest_path = os.path.join(self.name, dest_name) # Absolute destination path
dest_dir = os.path.dirname(dest_path)
if not os.path.exists(dest_dir):
os.makedirs(dest_dir)
elif not os.path.isdir(dest_dir):
try:
os.makedirs(dest_dir, exist_ok=True)
except FileExistsError:
raise SystemExit(
f"Pyinstaller needs to create a directory at {dest_dir!r}, "
"but there already exists a file at that path!"
Expand Down
6 changes: 3 additions & 3 deletions PyInstaller/building/osx.py
Expand Up @@ -608,9 +608,9 @@ def assemble(self):
# Create parent directory structure, if necessary
dest_path = os.path.join(self.name, dest_name) # Absolute destination path
dest_dir = os.path.dirname(dest_path)
if not os.path.exists(dest_dir):
os.makedirs(dest_dir)
elif not os.path.isdir(dest_dir):
try:
os.makedirs(dest_dir, exist_ok=True)
except FileExistsError:
raise SystemExit(
f"Pyinstaller needs to create a directory at {dest_dir!r}, "
"but there already exists a file at that path!"
Expand Down

0 comments on commit eb6e396

Please sign in to comment.