From f68611b715424b6012f16cad670a8d0b37a7af0a Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Tue, 1 Nov 2022 20:18:53 -0400 Subject: [PATCH] add typing to DepsTask.run --- core/dbt/deps/base.py | 2 +- core/dbt/events/types.py | 2 +- core/dbt/task/deps.py | 14 ++++++++++---- tests/unit/test_events.py | 5 +++-- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/core/dbt/deps/base.py b/core/dbt/deps/base.py index 1557b0d7a35..27567440a52 100644 --- a/core/dbt/deps/base.py +++ b/core/dbt/deps/base.py @@ -74,7 +74,7 @@ def _fetch_metadata(self, project, renderer): raise NotImplementedError @abc.abstractmethod - def install(self, project): + def install(self, project, renderer): raise NotImplementedError @abc.abstractmethod diff --git a/core/dbt/events/types.py b/core/dbt/events/types.py index de562fb62aa..21abaa16383 100644 --- a/core/dbt/events/types.py +++ b/core/dbt/events/types.py @@ -1706,7 +1706,7 @@ def code(self): def message(self) -> str: return "Updates available for packages: {} \ \nUpdate your versions in packages.yml, then run dbt deps".format( - self.packages + self.packages.value ) diff --git a/core/dbt/task/deps.py b/core/dbt/task/deps.py index 5e8beff43f3..14ba794cd4d 100644 --- a/core/dbt/task/deps.py +++ b/core/dbt/task/deps.py @@ -1,3 +1,5 @@ +from typing import Optional + import dbt.utils import dbt.deprecations import dbt.exceptions @@ -6,7 +8,9 @@ from dbt.config.renderer import DbtProjectYamlRenderer from dbt.deps.base import downloads_directory from dbt.deps.resolver import resolve_packages +from dbt.deps.registry import RegistryPinnedPackage +from dbt.events.proto_types import ListOfStrings from dbt.events.functions import fire_event from dbt.events.types import ( DepsNoPackagesFound, @@ -29,7 +33,9 @@ class DepsTask(BaseTask): def __init__(self, args, config: UnsetProfileConfig): super().__init__(args=args, config=config) - def track_package_install(self, package_name: str, source_type: str, version: str) -> None: + def track_package_install( + self, package_name: str, source_type: str, version: Optional[str] + ) -> None: # Hub packages do not need to be hashed, as they are public # Use the string 'local' for local package versions if source_type == "local": @@ -45,7 +51,7 @@ def track_package_install(self, package_name: str, source_type: str, version: st {"name": package_name, "source": source_type, "version": version}, ) - def run(self): + def run(self) -> None: system.make_directory(self.config.packages_install_path) packages = self.config.packages.packages if not packages: @@ -66,7 +72,7 @@ def run(self): fire_event(DepsStartPackageInstall(package_name=package_name)) package.install(self.config, renderer) fire_event(DepsInstallInfo(version_name=package.nice_version_name())) - if source_type == "hub": + if isinstance(package, RegistryPinnedPackage): version_latest = package.get_version_latest() if version_latest != version: packages_to_upgrade.append(package_name) @@ -81,7 +87,7 @@ def run(self): ) if packages_to_upgrade: fire_event(EmptyLine()) - fire_event(DepsNotifyUpdatesAvailable(packages=packages_to_upgrade)) + fire_event(DepsNotifyUpdatesAvailable(packages=ListOfStrings(packages_to_upgrade))) @classmethod def from_args(cls, args): diff --git a/tests/unit/test_events.py b/tests/unit/test_events.py index 6ba1b1ba69c..8d7aeaa7aae 100644 --- a/tests/unit/test_events.py +++ b/tests/unit/test_events.py @@ -13,7 +13,7 @@ ErrorLevel, TestLevel, ) -from dbt.events.proto_types import NodeInfo, RunResultMsg, ReferenceKeyMsg +from dbt.events.proto_types import ListOfStrings, NodeInfo, RunResultMsg, ReferenceKeyMsg from importlib import reload import dbt.events.functions as event_funcs import dbt.flags as flags @@ -321,7 +321,8 @@ def MockNode(): DepsInstallInfo(version_name=""), DepsUpdateAvailable(version_latest=""), DepsListSubdirectory(subdirectory=""), - DepsNotifyUpdatesAvailable(packages=[]), + DepsNotifyUpdatesAvailable(packages=ListOfStrings()), + DepsNotifyUpdatesAvailable(packages=ListOfStrings(['dbt-utils'])), DatabaseErrorRunningHook(hook_type=""), EmptyLine(), HooksRunning(num_hooks=0, hook_type=""),