Skip to content

Commit 7893de0

Browse files
committed
added implementation's first iteration
1 parent 0d03e2a commit 7893de0

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

core/dbt/config/project.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from dbt.constants import (
1919
DBT_PROJECT_FILE_NAME,
2020
DEPENDENCIES_FILE_NAME,
21+
PACKAGE_LOCK_FILE_NAME,
2122
PACKAGE_LOCK_HASH_KEY,
2223
PACKAGES_FILE_NAME,
2324
)
@@ -152,6 +153,11 @@ def package_config_from_data(
152153
return packages
153154

154155

156+
def load_package_lock_config(project_root: str) -> PackageConfig:
157+
locked_packages = load_yml_dict(f"{project_root}/{PACKAGE_LOCK_FILE_NAME}")
158+
return PackageConfig.from_dict(locked_packages)
159+
160+
155161
def _parse_versions(versions: Union[List[str], str]) -> List[VersionSpecifier]:
156162
"""Parse multiple versions as read from disk. The versions value may be any
157163
one of:

core/dbt/config/runtime.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from dbt.adapters.contracts.relation import ComponentName
2525
from dbt.adapters.factory import get_include_paths, get_relation_class_by_name
2626
from dbt.artifacts.resources import Quoting
27-
from dbt.config.project import load_raw_project
27+
from dbt.config.project import load_package_lock_config, load_raw_project
2828
from dbt.contracts.graph.manifest import ManifestMetadata
2929
from dbt.contracts.project import Configuration
3030
from dbt.events.types import UnusedResourceConfigPath
@@ -400,13 +400,15 @@ def load_dependencies(self, base_only=False) -> Mapping[str, "RuntimeConfig"]:
400400
# Test setup -- we want to load macros without dependencies
401401
project_paths = itertools.chain(internal_packages)
402402
else:
403-
# raise exception if fewer installed packages than in packages.yml
404-
count_packages_specified = len(self.packages.packages) # type: ignore
405-
count_packages_installed = len(tuple(self._get_project_directories()))
406-
if count_packages_specified > count_packages_installed:
403+
locked_packages = load_package_lock_config(self.project_root)
404+
expected_packages_names = {p.name for p in locked_packages.packages if p.name is not None} # type: ignore
405+
installed_packages = {p.stem for p in self._get_project_directories()}
406+
407+
uninstalled_packages = expected_packages_names - installed_packages
408+
409+
if uninstalled_packages:
407410
raise UninstalledPackagesFoundError(
408-
count_packages_specified,
409-
count_packages_installed,
411+
list(uninstalled_packages),
410412
self.packages_specified_path,
411413
self.packages_install_path,
412414
)

core/dbt/exceptions.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,23 +1073,21 @@ def get_message(self) -> str:
10731073
class UninstalledPackagesFoundError(CompilationError):
10741074
def __init__(
10751075
self,
1076-
count_packages_specified: int,
1077-
count_packages_installed: int,
1076+
uninstalled_packages: List[str],
10781077
packages_specified_path: str,
10791078
packages_install_path: str,
10801079
):
1081-
self.count_packages_specified = count_packages_specified
1082-
self.count_packages_installed = count_packages_installed
1080+
self.uninstalled_packages = uninstalled_packages
10831081
self.packages_specified_path = packages_specified_path
10841082
self.packages_install_path = packages_install_path
10851083
super().__init__(msg=self.get_message())
10861084

10871085
def get_message(self) -> str:
1086+
uninstalled_packages_str = ", ".join(self.uninstalled_packages)
10881087
msg = (
1089-
f"dbt found {self.count_packages_specified} package(s) "
1090-
f"specified in {self.packages_specified_path}, but only "
1091-
f"{self.count_packages_installed} package(s) installed "
1092-
f'in {self.packages_install_path}. Run "dbt deps" to '
1088+
f"dbt could not find following packages: {uninstalled_packages_str}. "
1089+
f"Packages are specified in {self.packages_specified_path}, "
1090+
f'and installed in {self.packages_install_path}. Run "dbt deps" to '
10931091
"install package dependencies."
10941092
)
10951093
return msg

0 commit comments

Comments
 (0)