Skip to content

Commit

Permalink
ignoring non yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
asosnovsky committed Sep 2, 2022
1 parent 2dfbc31 commit 6ee7ce8
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
13 changes: 10 additions & 3 deletions api/src/yaml_serializer/__init__.py
@@ -1,21 +1,28 @@
from pathlib import Path
from typing import Iterator, NamedTuple, Tuple, Union
from typing import Iterator, NamedTuple, Tuple

from yaml.nodes import Node

from src.logger import get_logger

from .manager import YamlManager

dump_yaml = YamlManager.dump_yaml
load_yaml = YamlManager.load_yaml

logger = get_logger(__file__)


def load_dir_yaml(folder_or_file: Path) -> Iterator[Tuple[Path, dict | list]]:
if folder_or_file.is_dir():
for file in folder_or_file.iterdir():
yield from load_dir_yaml(file)
else:
with folder_or_file.open("r") as fp:
yield folder_or_file, load_yaml(fp, root_path=folder_or_file.parent)
if folder_or_file.suffix.lower() == ".yaml":
with folder_or_file.open("r") as fp:
yield folder_or_file, load_yaml(fp, root_path=folder_or_file.parent)
else:
logger.info(f"Ignoring the file {folder_or_file}")


@YamlManager.as_constructor("!include")
Expand Down
7 changes: 7 additions & 0 deletions api/tests/samples/config-10/packages/README.md
@@ -0,0 +1,7 @@
# all the packages!

This is really cool :)

- A list item!

<<more thisngs!>>
7 changes: 7 additions & 0 deletions api/tests/samples/config-11/packages/sub/README.md
@@ -0,0 +1,7 @@
# all the packages!

This is really cool :)

- A list item!

<<more thisngs!>>
7 changes: 7 additions & 0 deletions api/tests/samples/config-12/packages/sub/README.md
@@ -0,0 +1,7 @@
# all the packages!

This is really cool :)

- A list item!

<<more thisngs!>>
7 changes: 7 additions & 0 deletions api/tests/samples/config-13/packages/sub/README.md
@@ -0,0 +1,7 @@
# all the packages!

This is really cool :)

- A list item!

<<more thisngs!>>

0 comments on commit 6ee7ce8

Please sign in to comment.