Skip to content

Commit

Permalink
refactor: parse_dag_directory take a path
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulFarault committed Oct 22, 2024
1 parent 7795f3a commit bbf82f3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions tdp/core/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def schema_directory(self) -> Path:
@property
def dag_nodes(self) -> Generator[TDPLibDagNodeModel, None, None]:
"""DAG nodes."""
return parse_dag_directory(self._path)
return parse_dag_directory(self.dag_directory)

@property
def playbooks(self) -> dict[str, Playbook]:
Expand Down Expand Up @@ -255,18 +255,17 @@ def read_hosts_from_playbook(


def parse_dag_directory(
collection_path: Path, dag_directory_name=DAG_DIRECTORY_NAME
dag_directory_path: Path,
) -> Generator[TDPLibDagNodeModel, None, None]:
"""Get the DAG nodes of a collection.
Args:
collection_path: Path to the collection.
dag_directory_name: Name of the DAG directory.
dag_directory_path: Path to the DAG directory.
Returns:
List of DAG nodes.
"""
for dag_file in (collection_path / dag_directory_name).glob("*" + YML_EXTENSION):
for dag_file in (dag_directory_path).glob("*" + YML_EXTENSION):
yield from parse_dag_file(dag_file)


Expand Down
4 changes: 2 additions & 2 deletions tests/unit/core/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
PathDoesNotExistsError,
PathIsNotADirectoryError,
check_collection_structure,
parse_dag_directory,
get_collection_playbooks,
parse_dag_directory,
parse_dag_file,
read_hosts_from_playbook,
)
Expand Down Expand Up @@ -217,7 +217,7 @@ def test_get_collection_dag_nodes(tmp_path: Path):
- s1_c1_a
"""
)
dag_nodes = list(parse_dag_directory(collection_path, dag_directory))
dag_nodes = list(parse_dag_directory(dag_directory_path))
assert len(dag_nodes) == 2
assert any(
node.name == "s1_c1_a" and node.depends_on == ["sx_cx_a"] for node in dag_nodes
Expand Down

0 comments on commit bbf82f3

Please sign in to comment.