Skip to content

Commit

Permalink
Merge pull request #603 from noqdev/fix/en-2401-falsy-parent-directory
Browse files Browse the repository at this point in the history
Fixed EN-2401 Check parent directory truthy-ness before attempt to create it
  • Loading branch information
smoy authored Aug 22, 2023
2 parents 7fe40f7 + 5d1162c commit 3ad0757
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion iambic/config/dynamic_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,11 @@ def write(self, exclude_none=True, exclude_unset=False, exclude_defaults=True):
)

file_path = os.path.expanduser(self.file_path)
os.makedirs(os.path.dirname(file_path), exist_ok=True)
parent_directory = os.path.dirname(file_path)
# if the user feeds in a filename like 'xyz.yaml'
# parent_directory is '', which is not acceptable
# to makedirs
os.makedirs(parent_directory, exist_ok=True)
with open(file_path, "w") as f:
f.write(yaml.dump(sorted_input_dict))

Expand Down
7 changes: 6 additions & 1 deletion iambic/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,12 @@ def write(self, exclude_none=True, exclude_unset=True, exclude_defaults=True):
self.validate_model_afterward()

as_yaml = self.get_body(exclude_none, exclude_unset, exclude_defaults)
os.makedirs(os.path.dirname(os.path.expanduser(self.file_path)), exist_ok=True)
parent_directory = os.path.dirname(os.path.expanduser(self.file_path))
# if the user feeds in a filename like 'xyz.yaml'
# parent_directory is '', which is not acceptable
# to makedirs
if parent_directory:
os.makedirs(parent_directory, exist_ok=True)
with open(self.file_path, "w") as f:
f.write(as_yaml)

Expand Down

0 comments on commit 3ad0757

Please sign in to comment.