Skip to content

Commit

Permalink
Load manifest from path in ManifestLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
jochemvandooren committed Mar 18, 2024
1 parent b8636f2 commit db2643b
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/dbt_score/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Objects related to loading the dbt manifest."""

import json
from collections import defaultdict
from dataclasses import dataclass, field
from pathlib import Path
from typing import Any


Expand All @@ -28,7 +29,7 @@ def from_raw_values(cls, raw_values: dict[str, Any]) -> "Constraint":
type=raw_values["type"],
name=raw_values["name"],
expression=raw_values["expression"],
_raw_values=raw_values
_raw_values=raw_values,
)


Expand Down Expand Up @@ -58,7 +59,7 @@ def from_node(cls, test_node: dict[str, Any]) -> "Test":
type=test_node["test_metadata"]["name"],
kwargs=test_node["test_metadata"].get("kwargs", {}),
tags=test_node.get("tags", []),
_raw_values=test_node
_raw_values=test_node,
)


Expand Down Expand Up @@ -105,7 +106,7 @@ def from_node_values(
tags=values["tags"],
tests=[Test.from_node(test) for test in test_values],
_raw_values=values,
_raw_test_values=test_values
_raw_test_values=test_values,
)


Expand Down Expand Up @@ -215,14 +216,15 @@ def from_node(
class ManifestLoader:
"""Load the models and tests from the manifest."""

def __init__(self, raw_manifest: dict[str, Any]):
def __init__(self, file_path: Path):
"""Initialize the ManifestLoader.
Args:
raw_manifest: The dictionary representation of the JSON manifest.
file_path: The file path of the JSON manifest.
"""
self.raw_manifest = raw_manifest
self.raw_nodes = raw_manifest.get("nodes", {})
self.file_path = file_path
self.raw_manifest = json.loads(self.file_path.read_text(encoding="utf-8"))
self.raw_nodes = self.raw_manifest.get("nodes", {})
self.models: list[Model] = []
self.tests: dict[str, list[dict[str, Any]]] = defaultdict(list)

Expand Down

0 comments on commit db2643b

Please sign in to comment.