Skip to content

Commit

Permalink
deps call sites (#4199)
Browse files Browse the repository at this point in the history
* add struct logging to base

* add struct logging to git

* add struct logging to deps

* remove blank line

* fixed stray merge error
  • Loading branch information
emmyoop authored and Nathaniel May committed Nov 9, 2021
1 parent 3cafc9e commit e0b0eda
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
5 changes: 3 additions & 2 deletions core/dbt/deps/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

from dbt.clients import system
from dbt.contracts.project import ProjectPackageMetadata
from dbt.logger import GLOBAL_LOGGER as logger
from dbt.events.functions import fire_event
from dbt.events.types import DepsSetDownloadDirectory

DOWNLOADS_PATH = None

Expand All @@ -31,7 +32,7 @@ def downloads_directory():
remove_downloads = True

system.make_directory(DOWNLOADS_PATH)
logger.debug("Set downloads directory='{}'".format(DOWNLOADS_PATH))
fire_event(DepsSetDownloadDirectory(path=DOWNLOADS_PATH))

yield DOWNLOADS_PATH

Expand Down
9 changes: 3 additions & 6 deletions core/dbt/deps/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
from dbt.exceptions import (
ExecutableError, warn_or_error, raise_dependency_error
)
from dbt.logger import GLOBAL_LOGGER as logger
from dbt.events.functions import fire_event
from dbt.events.types import EnsureGitInstalled
from dbt import ui

PIN_PACKAGE_URL = 'https://docs.getdbt.com/docs/package-management#section-specifying-package-versions' # noqa
Expand Down Expand Up @@ -81,11 +82,7 @@ def _checkout(self):
)
except ExecutableError as exc:
if exc.cmd and exc.cmd[0] == 'git':
logger.error(
'Make sure git is installed on your machine. More '
'information: '
'https://docs.getdbt.com/docs/package-management'
)
fire_event(EnsureGitInstalled())
raise
return os.path.join(get_downloads_path(), dir_)

Expand Down
8 changes: 4 additions & 4 deletions core/dbt/deps/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
ProjectPackageMetadata,
LocalPackage,
)
from dbt.logger import GLOBAL_LOGGER as logger
from dbt.events.functions import fire_event
from dbt.events.types import DepsCreatingLocalSymlink, DepsSymlinkNotAvailable


class LocalPackageMixin:
Expand Down Expand Up @@ -57,12 +58,11 @@ def install(self, project, renderer):
system.remove_file(dest_path)

if can_create_symlink:
logger.debug(' Creating symlink to local dependency.')
fire_event(DepsCreatingLocalSymlink())
system.make_symlink(src_path, dest_path)

else:
logger.debug(' Symlinks are not available on this '
'OS, copying dependency.')
fire_event(DepsSymlinkNotAvailable())
shutil.copytree(src_path, dest_path)


Expand Down
29 changes: 29 additions & 0 deletions core/dbt/events/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1609,6 +1609,31 @@ def cli_msg(self) -> str:
return self.msg


@dataclass
class DepsSetDownloadDirectory(DebugLevel, CliEventABC):
path: str

def cli_msg(self) -> str:
return f"Set downloads directory='{self.path}'"


class EnsureGitInstalled(ErrorLevel, CliEventABC):
def cli_msg(self) -> str:
return ('Make sure git is installed on your machine. More '
'information: '
'https://docs.getdbt.com/docs/package-management')


class DepsCreatingLocalSymlink(DebugLevel, CliEventABC):
def cli_msg(self) -> str:
return ' Creating symlink to local dependency.'


class DepsSymlinkNotAvailable(DebugLevel, CliEventABC):
def cli_msg(self) -> str:
return ' Symlinks are not available on this OS, copying dependency.'


# since mypy doesn't run on every file we need to suggest to mypy that every
# class gets instantiated. But we don't actually want to run this code.
# making the conditional `if False` causes mypy to skip it as dead code so
Expand Down Expand Up @@ -1778,3 +1803,7 @@ def cli_msg(self) -> str:
InvalidProfileTemplateYAML()
ProjectNameAlreadyExists(name='')
GetAddendum(msg='')
DepsSetDownloadDirectory(path='')
EnsureGitInstalled()
DepsCreatingLocalSymlink()
DepsSymlinkNotAvailable()

0 comments on commit e0b0eda

Please sign in to comment.