Skip to content

Commit

Permalink
Refactor a chunk of code (for packages to search for a macro name) as…
Browse files Browse the repository at this point in the history
… a class method
  • Loading branch information
dbeatty10 committed Sep 9, 2022
1 parent cfece2c commit 1a94a15
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions core/dbt/context/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,24 @@ def _get_adapter_macro_prefixes(self) -> List[str]:
search_prefixes = get_adapter_type_names(self._adapter.type()) + ["default"]
return search_prefixes

def _get_search_packages(self, macro_namespace: Optional[str] = None):
namespace = macro_namespace

if namespace is None:
search_packages = [None]
elif isinstance(namespace, str):
search_packages = self._adapter.config.get_macro_search_order(namespace)
if not search_packages and namespace in self._adapter.config.dependencies:
search_packages = [self.config.project_name, namespace]
else:
# Not a string and not None so must be a list
raise CompilationException(
f"In adapter.dispatch, got a list macro_namespace argument "
f'("{macro_namespace}"), but macro_namespace should be None or a string.'
)

return search_packages

def dispatch(
self,
macro_name: str,
Expand All @@ -145,20 +163,7 @@ def dispatch(
if packages is not None:
raise macro_invalid_dispatch_arg(macro_name)

namespace = macro_namespace

if namespace is None:
search_packages = [None]
elif isinstance(namespace, str):
search_packages = self._adapter.config.get_macro_search_order(namespace)
if not search_packages and namespace in self._adapter.config.dependencies:
search_packages = [self.config.project_name, namespace]
else:
# Not a string and not None so must be a list
raise CompilationException(
f"In adapter.dispatch, got a list macro_namespace argument "
f'("{macro_namespace}"), but macro_namespace should be None or a string.'
)
search_packages = self._get_search_packages(macro_namespace)

attempts = []

Expand Down

0 comments on commit 1a94a15

Please sign in to comment.