Exemplo n.º 1
0
 def _get_namespace_builder(self):
     internal_packages = get_adapter_package_names(
         self.config.credentials.type)
     return MacroNamespaceBuilder(
         self.config.project_name,
         self.search_package,
         self.macro_stack,
         internal_packages,
         self.model,
     )
Exemplo n.º 2
0
 def _get_namespace_builder(self) -> MacroNamespaceBuilder:
     # avoid an import loop
     from dbt.adapters.factory import get_adapter_package_names
     internal_packages: List[str] = get_adapter_package_names(
         self.config.credentials.type)
     return MacroNamespaceBuilder(
         self.config.project_name,
         self.search_package,
         self.macro_stack,
         internal_packages,
         None,
     )
Exemplo n.º 3
0
 def reparse_macros(self):
     internal_package_names = get_adapter_package_names(
         self.root_project.credentials.type
     )
     macro_resolver = MacroResolver(
         self.manifest.macros,
         self.root_project.project_name,
         internal_package_names
     )
     base_ctx = generate_base_context({})
     for macro in self.manifest.macros.values():
         possible_macro_calls = statically_extract_macro_calls(macro.macro_sql, base_ctx)
         for macro_name in possible_macro_calls:
             # adapter.dispatch calls can generate a call with the same name as the macro
             # it ought to be an adapter prefix (postgres_) or default_
             if macro_name == macro.name:
                 continue
             dep_macro_id = macro_resolver.get_macro_id(macro.package_name, macro_name)
             if dep_macro_id:
                 macro.depends_on.add_macro(dep_macro_id)  # will check for dupes
Exemplo n.º 4
0
    def _find_macros_by_name(
        self,
        name: str,
        root_project_name: str,
        filter: Optional[Callable[[MacroCandidate], bool]] = None
    ) -> CandidateList:
        """Find macros by their name.
        """
        # avoid an import cycle
        from dbt.adapters.factory import get_adapter_package_names
        candidates: CandidateList = CandidateList()
        packages = set(get_adapter_package_names(self.metadata.adapter_type))
        for unique_id, macro in self.macros.items():
            if macro.name != name:
                continue
            candidate = MacroCandidate(
                locality=_get_locality(macro, root_project_name, packages),
                macro=macro,
            )
            if filter is None or filter(candidate):
                candidates.append(candidate)

        return candidates
Exemplo n.º 5
0
    def __init__(
        self,
        project,
        manifest,
        root_project,
    ) -> None:
        super().__init__(project, manifest, root_project)
        all_v_2 = (self.root_project.config_version == 2
                   and self.project.config_version == 2)
        if all_v_2:
            ctx = generate_schema_yml(self.root_project,
                                      self.project.project_name)
        else:
            ctx = generate_target_context(self.root_project,
                                          self.root_project.cli_vars)

        self.raw_renderer = SchemaYamlRenderer(ctx)

        internal_package_names = get_adapter_package_names(
            self.root_project.credentials.type)
        self.macro_resolver = MacroResolver(self.manifest.macros,
                                            self.root_project.project_name,
                                            internal_package_names)