Skip to content

Commit

Permalink
Use Manifest instead of ParseResults [#3163]
Browse files Browse the repository at this point in the history
automatic commit by git-black, original commits:
  307d47e
  • Loading branch information
gshank authored and iknox-fa committed Feb 8, 2022
1 parent c272cd9 commit 7ef5aa9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
2 changes: 1 addition & 1 deletion core/dbt/adapters/base/impl.py
Expand Up @@ -274,7 +274,7 @@ def load_macro_manifest(self) -> MacroManifest:
if self._macro_manifest_lazy is None:
# avoid a circular import
from dbt.parser.manifest import ManifestLoader
manifest = ManifestLoader.load_macros(

self.config, self.connections.set_query_header
)
self._macro_manifest_lazy = manifest
Expand Down
21 changes: 7 additions & 14 deletions core/dbt/contracts/graph/manifest.py
Expand Up @@ -116,7 +116,7 @@ def add_source(self, source: ParsedSourceDefinition):

def populate(self, manifest):
for source in manifest.sources.values():
if hasattr(source, 'source_name'):
if hasattr(source, "source_name"):
self.add_source(source)

def perform_lookup(
Expand Down Expand Up @@ -968,7 +968,7 @@ def add_macro(self, source_file: SourceFile, macro: ParsedMacro):
# note that the line wrap eats newlines, so if you want newlines,
# this is the result :(
msg = line_wrap_message(
f'''\
f"""\
dbt found two macros named "{macro.name}" in the project
"{macro.package_name}".
Expand All @@ -979,8 +979,8 @@ def add_macro(self, source_file: SourceFile, macro: ParsedMacro):
- {macro.original_file_path}
- {other_path}
''',
subtract=2
""",
subtract=2,
)
raise_compiler_error(msg)

Expand Down Expand Up @@ -1143,11 +1143,7 @@ class WritableManifest(ArtifactMixin):
metadata: ManifestMetadata = field(metadata=dict(
description='Metadata about the manifest',
))


def _check_duplicates(
value: HasUniqueID, src: Mapping[str, HasUniqueID]
):
def _check_duplicates(value: HasUniqueID, src: Mapping[str, HasUniqueID]):
if value.unique_id in src:
raise_duplicate_resource_name(value, src[value.unique_id])

Expand All @@ -1156,13 +1152,10 @@ def _check_duplicates(
V_T = TypeVar('V_T')


def _expect_value(
key: K_T, src: Mapping[K_T, V_T], old_file: SourceFile, name: str
) -> V_T:
def _expect_value(key: K_T, src: Mapping[K_T, V_T], old_file: SourceFile, name: str) -> V_T:
if key not in src:
raise CompilationException(
'Expected to find "{}" in cached "result.{}" based '
'on cached file information: {}!'
.format(key, name, old_file)
"on cached file information: {}!".format(key, name, old_file)
)
return src[key]
19 changes: 11 additions & 8 deletions core/dbt/parser/manifest.py
Expand Up @@ -578,7 +578,8 @@ def is_partial_parsable(self, manifest: Manifest) -> Tuple[bool, Optional[str]]:
reparse_reason = ReparseReason.prof_env_vars_changed

missing_keys = {
k for k in self.manifest.state_check.project_hashes
k
for k in self.manifest.state_check.project_hashes
if k not in manifest.state_check.project_hashes
}
if missing_keys:
Expand Down Expand Up @@ -677,12 +678,14 @@ def build_manifest_state_check(self):
# to not pass, it doesn't matter. If we move to more granular checking
# of env_vars, that would need to change.
vars_hash = FileHash.from_contents(
'\x00'.join([
getattr(config.args, 'vars', '{}') or '{}',
getattr(config.args, 'profile', '') or '',
getattr(config.args, 'target', '') or '',
__version__
])
"\x00".join(
[
getattr(config.args, "vars", "{}") or "{}",
getattr(config.args, "profile", "") or "",
getattr(config.args, "target", "") or "",
__version__,
]
)
)

# Create a FileHash of the env_vars in the project
Expand All @@ -709,7 +712,7 @@ def build_manifest_state_check(self):
# Create a FileHashes for dbt_project for all dependencies
project_hashes = {}
for name, project in all_projects.items():
path = os.path.join(project.project_root, 'dbt_project.yml')
path = os.path.join(project.project_root, "dbt_project.yml")
with open(path) as fp:
project_hashes[name] = FileHash.from_contents(fp.read())

Expand Down
10 changes: 8 additions & 2 deletions core/dbt/parser/schemas.py
Expand Up @@ -167,7 +167,10 @@ def _trimmed(inp: str) -> str:

class SchemaParser(SimpleParser[GenericTestBlock, ParsedGenericTestNode]):
def __init__(
self, project, manifest, root_project,
self,
project,
manifest,
root_project,
) -> None:
super().__init__(project, manifest, root_project)

Expand Down Expand Up @@ -394,7 +397,10 @@ def render_test_update(self, node, config, builder, schema_file_id):
try:
# make a base context that doesn't have the magic kwargs field
context = generate_test_context(
node, self.root_project, self.manifest, config,
node,
self.root_project,
self.manifest,
config,
self.macro_resolver,
)
# update with rendered test kwargs (which collects any refs)
Expand Down

0 comments on commit 7ef5aa9

Please sign in to comment.