Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions infrahub_sdk/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,23 @@
@classmethod
def load_from_disk(cls, paths: list[Path]) -> list[Self]:
yaml_files: list[Self] = []
file_extensions = {".yaml", ".yml", ".json"} # FIXME: .json is not a YAML file, should be removed
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LucasG0 do you know why we have .json here? too afraid about side effect of removing it from here


paths = sorted(paths, key=lambda p: p.name) # Ensure order when processing paths

for file_path in paths:
if file_path.is_file() and file_path.suffix in [".yaml", ".yml", ".json"]:
yaml_files.extend(cls.load_file_from_disk(path=file_path))
if not file_path.exists():
# Check if the provided path exists, relevant for the first call coming from the user
raise FileNotValidError(name=str(file_path), message=f"{file_path} does not exist!")

Check warning on line 130 in infrahub_sdk/yaml.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/yaml.py#L130

Added line #L130 was not covered by tests
if file_path.is_file():
if file_path.suffix in file_extensions:
yaml_files.extend(cls.load_file_from_disk(path=file_path))
# else: silently skip files with unrelevant extensions (e.g. .md, .py...)
elif file_path.is_dir():
# Introduce recursion to handle sub-folders
sub_paths = [Path(sub_file_path) for sub_file_path in file_path.glob("*")]
sub_files = cls.load_from_disk(paths=sub_paths)
sorted_sub_files = sorted(sub_files, key=lambda x: x.location)
yaml_files.extend(sorted_sub_files)
else:
raise FileNotValidError(name=str(file_path), message=f"{file_path} does not exist!")
yaml_files.extend(cls.load_from_disk(paths=sub_paths))
# else: skip non-file, non-dir (e.g., symlink...)

return yaml_files

Expand Down