Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move system client to common #9294

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
2474722
moving types_pb2.py to common/events
colin-rogers-dbt Oct 25, 2023
07743b7
merge
colin-rogers-dbt Oct 25, 2023
252e3e3
Merge branch 'feature/decouple-adapters-from-core' of https://github.…
colin-rogers-dbt Oct 26, 2023
ff9d519
Merge branch 'feature/decouple-adapters-from-core' of https://github.…
colin-rogers-dbt Nov 2, 2023
bf079b1
Merge branch 'feature/decouple-adapters-from-core' of https://github.…
colin-rogers-dbt Nov 28, 2023
3187ded
Merge branch 'feature/decouple-adapters-from-core' of https://github.…
colin-rogers-dbt Nov 28, 2023
4da67bf
Merge branch 'feature/decouple-adapters-from-core' of https://github.…
colin-rogers-dbt Dec 5, 2023
c03823f
Merge branch 'feature/decouple-adapters-from-core' of https://github.…
colin-rogers-dbt Dec 6, 2023
2811ccd
Merge branch 'feature/decouple-adapters-from-core' of https://github.…
colin-rogers-dbt Dec 7, 2023
e88138a
Merge branch 'feature/decouple-adapters-from-core' of https://github.…
colin-rogers-dbt Dec 7, 2023
977a842
Merge branch 'feature/decouple-adapters-from-core' of https://github.…
colin-rogers-dbt Dec 7, 2023
3ddfcdd
Merge branch 'feature/decouple-adapters-from-core' of https://github.…
colin-rogers-dbt Dec 12, 2023
082b0c6
Merge branch 'feature/decouple-adapters-from-core' of https://github.…
colin-rogers-dbt Dec 14, 2023
611981f
Merge branch 'feature/decouple-adapters-from-core' of https://github.…
colin-rogers-dbt Dec 14, 2023
3665fb1
Merge branch 'feature/decouple-adapters-from-core' of https://github.…
colin-rogers-dbt Dec 14, 2023
26c8d64
move system.py to common
colin-rogers-dbt Dec 15, 2023
7fb12fd
add changie update README
colin-rogers-dbt Dec 15, 2023
2507323
remove dbt.utils from semver.py
colin-rogers-dbt Dec 15, 2023
e777c3a
remove aliasing connection_exception_retry
colin-rogers-dbt Dec 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20231214-164107.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: move system.py to common as dbt-bigquery relies on it to call gcloud
time: 2023-12-14T16:41:07.539814-08:00
custom:
Author: colin-rogers-dbt
Issue: "9293"
2 changes: 1 addition & 1 deletion core/dbt/clients/git.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
import os.path

from dbt.clients.system import run_cmd, rmdir
from dbt.common.clients.system import run_cmd, rmdir
from dbt.common.events.functions import fire_event
from dbt.common.events.types import (
GitSparseCheckoutSubdirectory,
Expand Down
3 changes: 2 additions & 1 deletion core/dbt/clients/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
RegistryResponseMissingNestedKeys,
RegistryResponseExtraNestedKeys,
)
from dbt.utils import memoized, _connection_exception_retry as connection_exception_retry
from dbt.utils import memoized
from dbt.common.utils.connection import connection_exception_retry
from dbt import deprecations
from dbt.common import semver
import os
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import dbt.common.exceptions.base
import errno
import fnmatch
import functools
Expand All @@ -24,7 +25,7 @@
SystemReportReturnCode,
)
from dbt.common.exceptions import DbtInternalError
from dbt.utils import _connection_exception_retry as connection_exception_retry
from dbt.common.utils.connection import connection_exception_retry
from pathspec import PathSpec # type: ignore

if sys.platform == "win32":
Expand Down Expand Up @@ -197,7 +198,7 @@


def write_json(path: str, data: Dict[str, Any]) -> bool:
return write_file(path, json.dumps(data, cls=dbt.utils.JSONEncoder))
return write_file(path, json.dumps(data, cls=dbt.common.utils.encoding.JSONEncoder))


def _windows_rmdir_readonly(func: Callable[[str], Any], path: str, exc: Tuple[Any, OSError, Any]):
Expand Down Expand Up @@ -385,7 +386,7 @@


def _handle_windows_error(exc: OSError, cwd: str, cmd: List[str]) -> NoReturn:
cls: Type[dbt.common.exceptions.DbtBaseException] = dbt.exceptions.CommandError
cls: Type[dbt.common.exceptions.DbtBaseException] = dbt.common.exceptions.base.CommandError

Check warning on line 389 in core/dbt/common/clients/system.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/common/clients/system.py#L389

Added line #L389 was not covered by tests
if exc.errno == errno.ENOENT:
message = (
"Could not find command, ensure it is in the user's PATH "
Expand All @@ -411,7 +412,7 @@
def _interpret_oserror(exc: OSError, cwd: str, cmd: List[str]) -> NoReturn:
"""Interpret an OSError exception and raise the appropriate dbt exception."""
if len(cmd) == 0:
raise dbt.exceptions.CommandError(cwd, cmd)
raise dbt.common.exceptions.base.CommandError(cwd, cmd)

Check warning on line 415 in core/dbt/common/clients/system.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/common/clients/system.py#L415

Added line #L415 was not covered by tests

# all of these functions raise unconditionally
if os.name == "nt":
Expand All @@ -428,7 +429,7 @@
def run_cmd(cwd: str, cmd: List[str], env: Optional[Dict[str, Any]] = None) -> Tuple[bytes, bytes]:
fire_event(SystemExecutingCmd(cmd=cmd))
if len(cmd) == 0:
raise dbt.exceptions.CommandError(cwd, cmd)
raise dbt.common.exceptions.base.CommandError(cwd, cmd)

Check warning on line 432 in core/dbt/common/clients/system.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/common/clients/system.py#L432

Added line #L432 was not covered by tests

# the env argument replaces the environment entirely, which has exciting
# consequences on Windows! Do an update instead.
Expand Down Expand Up @@ -502,7 +503,7 @@
if rename_to:
downloaded_path = os.path.join(dest_dir, tar_dir_name)
desired_path = os.path.join(dest_dir, rename_to)
dbt.clients.system.rename(downloaded_path, desired_path, force=True)
dbt.common.clients.system.rename(downloaded_path, desired_path, force=True)


def chmod_and_retry(func, path, exc_info):
Expand Down
14 changes: 14 additions & 0 deletions core/dbt/common/exceptions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

def data(self):
# if overriding, make sure the result is json-serializable.
return {

Check warning on line 28 in core/dbt/common/exceptions/base.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/common/exceptions/base.py#L28

Added line #L28 was not covered by tests
"type": self.__class__.__name__,
"message": str(self),
}
Expand All @@ -46,16 +46,16 @@
first = True

if len(stack) > 1:
lines.append("")

Check warning on line 49 in core/dbt/common/exceptions/base.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/common/exceptions/base.py#L49

Added line #L49 was not covered by tests

for item in stack:
msg = "called by"

Check warning on line 52 in core/dbt/common/exceptions/base.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/common/exceptions/base.py#L51-L52

Added lines #L51 - L52 were not covered by tests

if first:
msg = "in"
first = False

Check warning on line 56 in core/dbt/common/exceptions/base.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/common/exceptions/base.py#L54-L56

Added lines #L54 - L56 were not covered by tests

lines.append(f"> {msg}")

Check warning on line 58 in core/dbt/common/exceptions/base.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/common/exceptions/base.py#L58

Added line #L58 was not covered by tests

return lines

Expand All @@ -63,7 +63,7 @@
if hasattr(self.msg, "split"):
split_msg = self.msg.split("\n")
else:
split_msg = str(self.msg).split("\n")

Check warning on line 66 in core/dbt/common/exceptions/base.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/common/exceptions/base.py#L66

Added line #L66 was not covered by tests

lines = ["{}".format(self.type + " Error")] + split_msg

Expand All @@ -84,7 +84,7 @@
def add_node(self, node=None):
if node is not None and node is not self.node:
if self.node is not None:
self.stack.append(self.node)

Check warning on line 87 in core/dbt/common/exceptions/base.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/common/exceptions/base.py#L87

Added line #L87 was not covered by tests
self.node = node

@property
Expand Down Expand Up @@ -129,7 +129,7 @@
jsonschema.ValidationError), return the relevant parts as a string
"""
if not isinstance(exc, ValidationError):
return str(exc)

Check warning on line 132 in core/dbt/common/exceptions/base.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/common/exceptions/base.py#L132

Added line #L132 was not covered by tests
path = "[%s]" % "][".join(map(repr, exc.relative_path))
return f"at path {path}: {exc.message}"

Expand All @@ -142,7 +142,7 @@
if hasattr(self.msg, "split"):
split_msg = self.msg.split("\n")
else:
split_msg = str(self.msg).split("\n")

Check warning on line 145 in core/dbt/common/exceptions/base.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/common/exceptions/base.py#L145

Added line #L145 was not covered by tests

lines = ["{}{}".format(self.type + " Error", node_string)] + split_msg

Expand All @@ -151,18 +151,18 @@
return lines[0] + "\n" + "\n".join([" " + line for line in lines[1:]])

def data(self):
result = DbtBaseException.data(self)
if self.node is None:
return result

Check warning on line 156 in core/dbt/common/exceptions/base.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/common/exceptions/base.py#L154-L156

Added lines #L154 - L156 were not covered by tests

result.update(

Check warning on line 158 in core/dbt/common/exceptions/base.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/common/exceptions/base.py#L158

Added line #L158 was not covered by tests
{
"raw_code": self.node.raw_code,
# the node isn't always compiled, but if it is, include that!
"compiled_code": getattr(self.node, "compiled_code", None),
}
)
return result

Check warning on line 165 in core/dbt/common/exceptions/base.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/common/exceptions/base.py#L165

Added line #L165 was not covered by tests


class CompilationError(DbtRuntimeError):
Expand All @@ -175,7 +175,7 @@

def _fix_dupe_msg(self, path_1: str, path_2: str, name: str, type_name: str) -> str:
if path_1 == path_2:
return (

Check warning on line 178 in core/dbt/common/exceptions/base.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/common/exceptions/base.py#L178

Added line #L178 was not covered by tests
f"remove one of the {type_name} entries for {name} in this file:\n - {path_1!s}\n"
)
else:
Expand Down Expand Up @@ -252,10 +252,24 @@

class UnexpectedNullError(DbtDatabaseError):
def __init__(self, field_name: str, source):
self.field_name = field_name
self.source = source
msg = (

Check warning on line 257 in core/dbt/common/exceptions/base.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/common/exceptions/base.py#L255-L257

Added lines #L255 - L257 were not covered by tests
f"Expected a non-null value when querying field '{self.field_name}' of table "
f" {self.source} but received value 'null' instead"
)
super().__init__(msg)

Check warning on line 261 in core/dbt/common/exceptions/base.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/common/exceptions/base.py#L261

Added line #L261 was not covered by tests


class CommandError(DbtRuntimeError):
def __init__(self, cwd: str, cmd: List[str], msg: str = "Error running command") -> None:
cmd_scrubbed = list(scrub_secrets(cmd_txt, env_secrets()) for cmd_txt in cmd)
super().__init__(msg)
self.cwd = cwd
self.cmd = cmd_scrubbed
self.args = (cwd, cmd_scrubbed, msg)

def __str__(self):
if len(self.cmd) == 0:
return f"{self.msg}: No arguments given"

Check warning on line 274 in core/dbt/common/exceptions/base.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/common/exceptions/base.py#L274

Added line #L274 was not covered by tests
return f'{self.msg}: "{self.cmd[0]}"'
1 change: 0 additions & 1 deletion core/dbt/common/semver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import dbt.common.exceptions.base
from dbt.common.exceptions import VersionsNotCompatibleError
import dbt.utils

from dbt.common.dataclass_schema import dbtClassMixin, StrEnum
from typing import Optional
Expand Down
33 changes: 33 additions & 0 deletions core/dbt/common/utils/connection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import time

from dbt.common.events.types import RecordRetryException, RetryExternalCall
from dbt.exceptions import ConnectionError
from tarfile import ReadError

import requests


def connection_exception_retry(fn, max_attempts: int, attempt: int = 0):
"""Attempts to run a function that makes an external call, if the call fails
on a Requests exception or decompression issue (ReadError), it will be tried
up to 5 more times. All exceptions that Requests explicitly raises inherit from
requests.exceptions.RequestException. See https://github.com/dbt-labs/dbt-core/issues/4579
for context on this decompression issues specifically.
"""
try:
return fn()
except (
requests.exceptions.RequestException,
ReadError,
EOFError,
) as exc:
if attempt <= max_attempts - 1:
# This import needs to be inline to avoid circular dependency
from dbt.common.events.functions import fire_event

fire_event(RecordRetryException(exc=str(exc)))
fire_event(RetryExternalCall(attempt=attempt, max=max_attempts))
time.sleep(1)
return connection_exception_retry(fn, max_attempts, attempt + 1)
else:
raise ConnectionError("External connection exception occurred: " + str(exc))
2 changes: 1 addition & 1 deletion core/dbt/compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from dbt.flags import get_flags
from dbt.adapters.factory import get_adapter
from dbt.clients import jinja
from dbt.clients.system import make_directory
from dbt.common.clients.system import make_directory
from dbt.context.providers import generate_runtime_model_context
from dbt.contracts.graph.manifest import Manifest, UniqueID
from dbt.contracts.graph.nodes import (
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/config/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dbt.common.dataclass_schema import ValidationError

from dbt.flags import get_flags
from dbt.clients.system import load_file_contents
from dbt.common.clients.system import load_file_contents
from dbt.clients.yaml_helper import load_yaml_text
from dbt.adapters.contracts.connection import Credentials, HasCredentials
from dbt.contracts.project import ProfileConfig, UserConfig
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/config/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
PACKAGES_FILE_NAME,
PACKAGE_LOCK_HASH_KEY,
)
from dbt.clients.system import path_exists, load_file_contents
from dbt.common.clients.system import path_exists, load_file_contents
from dbt.clients.yaml_helper import load_yaml_text
from dbt.adapters.contracts.connection import QueryComment
from dbt.exceptions import (
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/config/selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from .renderer import BaseRenderer

from dbt.clients.system import (
from dbt.common.clients.system import (
load_file_contents,
path_exists,
resolve_path_from_base,
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/contracts/graph/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
)
from dbt.common.dataclass_schema import dbtClassMixin, ExtensibleDbtClassMixin

from dbt.clients.system import write_file
from dbt.common.clients.system import write_file
from dbt.contracts.files import FileHash
from dbt.contracts.graph.saved_queries import Export, QueryParams
from dbt.contracts.graph.semantic_models import (
Expand Down Expand Up @@ -1742,16 +1742,16 @@
return self.depends_on.nodes

def same_metrics(self, old: "SavedQuery") -> bool:
return self.query_params.metrics == old.query_params.metrics

Check warning on line 1745 in core/dbt/contracts/graph/nodes.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/contracts/graph/nodes.py#L1745

Added line #L1745 was not covered by tests

def same_group_by(self, old: "SavedQuery") -> bool:
return self.query_params.group_by == old.query_params.group_by

Check warning on line 1748 in core/dbt/contracts/graph/nodes.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/contracts/graph/nodes.py#L1748

Added line #L1748 was not covered by tests

def same_description(self, old: "SavedQuery") -> bool:
return self.description == old.description

def same_where(self, old: "SavedQuery") -> bool:
return self.query_params.where == old.query_params.where

Check warning on line 1754 in core/dbt/contracts/graph/nodes.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/contracts/graph/nodes.py#L1754

Added line #L1754 was not covered by tests

def same_label(self, old: "SavedQuery") -> bool:
return self.label == old.label
Expand All @@ -1763,15 +1763,15 @@
return self.group == old.group

def same_exports(self, old: "SavedQuery") -> bool:
if len(self.exports) != len(old.exports):
return False

Check warning on line 1767 in core/dbt/contracts/graph/nodes.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/contracts/graph/nodes.py#L1766-L1767

Added lines #L1766 - L1767 were not covered by tests

# exports should be in the same order, so we zip them for easy iteration
for (old_export, new_export) in zip(old.exports, self.exports):
if not new_export.same_contents(old_export):
return False

Check warning on line 1772 in core/dbt/contracts/graph/nodes.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/contracts/graph/nodes.py#L1770-L1772

Added lines #L1770 - L1772 were not covered by tests

return True

Check warning on line 1774 in core/dbt/contracts/graph/nodes.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/contracts/graph/nodes.py#L1774

Added line #L1774 was not covered by tests

def same_contents(self, old: Optional["SavedQuery"]) -> bool:
# existing when it didn't before is a change!
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/contracts/graph/semantic_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
SemanticManifestValidator,
)

from dbt.clients.system import write_file
from dbt.common.clients.system import write_file
from dbt.common.events.base_types import EventLevel
from dbt.common.events.functions import fire_event
from dbt.common.events.types import SemanticValidationFailure
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/contracts/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
Tuple,
)

from dbt.clients.system import write_json
from dbt.common.clients.system import write_json


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/contracts/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from datetime import datetime
from typing import List, Tuple, ClassVar, Type, TypeVar, Dict, Any, Optional

from dbt.clients.system import write_json, read_json
from dbt.common.clients.system import write_json, read_json
from dbt.exceptions import (
DbtInternalError,
DbtRuntimeError,
Expand Down Expand Up @@ -208,7 +208,7 @@
def get_artifact_schema_version(dct: dict) -> int:
schema_version = dct.get("metadata", {}).get("dbt_schema_version", None)
if not schema_version:
raise ValueError("Artifact is missing schema version")

Check warning on line 211 in core/dbt/contracts/util.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/contracts/util.py#L211

Added line #L211 was not covered by tests

# schema_version is in this format: https://schemas.getdbt.com/dbt/manifest/v10.json
# What the code below is doing:
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/deps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Defines the base classes of `PinnedPackage` and `UnpinnedPackage`.

`downloads_directory` sets the directory packages will be downloaded to.

`_install` has retry logic if the download or untarring process hit exceptions (see `dbt.utils._connection_exception_retry`).
`_install` has retry logic if the download or untarring process hit exceptions (see `dbt.common.utils.connection_exception_retry`).

## `git.py`

Expand Down
6 changes: 3 additions & 3 deletions core/dbt/deps/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
from pathlib import Path
from typing import List, Optional, Generic, TypeVar, Dict

from dbt.clients import system
from dbt.common.clients import system
from dbt.contracts.project import ProjectPackageMetadata
from dbt.common.events.functions import fire_event
from dbt.common.events.types import DepsSetDownloadDirectory
from dbt.utils import _connection_exception_retry as connection_exception_retry
from dbt.common.utils.connection import connection_exception_retry

DOWNLOADS_PATH = None

Expand Down Expand Up @@ -86,7 +86,7 @@

@abc.abstractmethod
def to_dict(self) -> Dict[str, str]:
raise NotImplementedError

Check warning on line 89 in core/dbt/deps/base.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/deps/base.py#L89

Added line #L89 was not covered by tests

def fetch_metadata(self, project, renderer):
if not self._cached_metadata:
Expand Down Expand Up @@ -126,7 +126,7 @@
download appears successful but the file did not make it through as expected
(generally due to a github incident). Either way we want to retry downloading
and untarring to see if we can get a success. Call this within
`_connection_exception_retry`
`connection_exception_retry`
"""

system.download(download_url, tar_path)
Expand Down
3 changes: 2 additions & 1 deletion core/dbt/deps/git.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
from typing import List, Optional, Dict

from dbt.clients import git, system
from dbt.clients import git
from dbt.common.clients import system
from dbt.config.project import PartialProject, Project
from dbt.config.renderer import PackageRenderer
from dbt.contracts.project import (
Expand Down Expand Up @@ -58,7 +59,7 @@
def to_dict(self) -> Dict[str, str]:
git_scrubbed = scrub_secrets(self.git_unrendered, env_secrets())
if self.git_unrendered != git_scrubbed:
warn_or_error(DepsScrubbedPackageName(package_name=git_scrubbed))

Check warning on line 62 in core/dbt/deps/git.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/deps/git.py#L62

Added line #L62 was not covered by tests
ret = {
"git": git_scrubbed,
"revision": self.revision,
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/deps/local.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import shutil
from typing import Dict

from dbt.clients import system
from dbt.common.clients import system
from dbt.deps.base import PinnedPackage, UnpinnedPackage
from dbt.contracts.project import (
ProjectPackageMetadata,
Expand Down
4 changes: 2 additions & 2 deletions core/dbt/deps/tarball.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
from pathlib import Path
from typing import Dict

from dbt.clients import system
from dbt.common.clients import system
from dbt.config.project import PartialProject
from dbt.contracts.project import TarballPackage
from dbt.deps.base import PinnedPackage, UnpinnedPackage, get_downloads_path
from dbt.exceptions import DependencyError, scrub_secrets, env_secrets
from dbt.common.events.functions import warn_or_error
from dbt.events.types import DepsScrubbedPackageName
from dbt.utils import _connection_exception_retry as connection_exception_retry
from dbt.common.utils.connection import connection_exception_retry


class TarballPackageMixin:
Expand Down Expand Up @@ -42,7 +42,7 @@
def to_dict(self) -> Dict[str, str]:
tarball_scrubbed = scrub_secrets(self.tarball_unrendered, env_secrets())
if self.tarball_unrendered != tarball_scrubbed:
warn_or_error(DepsScrubbedPackageName(package_name=tarball_scrubbed))

Check warning on line 45 in core/dbt/deps/tarball.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/deps/tarball.py#L45

Added line #L45 was not covered by tests
return {
"tarball": tarball_scrubbed,
"name": self.package,
Expand Down Expand Up @@ -82,10 +82,10 @@
connection_exception_retry(download_untar_fn, 5)
dest_path = self.get_installation_path(project, renderer)
if os.path.exists(dest_path):
if system.path_is_symlink(dest_path):
system.remove_file(dest_path)

Check warning on line 86 in core/dbt/deps/tarball.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/deps/tarball.py#L85-L86

Added lines #L85 - L86 were not covered by tests
else:
system.rmdir(dest_path)

Check warning on line 88 in core/dbt/deps/tarball.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/deps/tarball.py#L88

Added line #L88 was not covered by tests
system.move(self.untarred_path, dest_path)


Expand All @@ -110,7 +110,7 @@
)

def incorporate(self, other: "TarballUnpinnedPackage") -> "TarballUnpinnedPackage":
return TarballUnpinnedPackage(

Check warning on line 113 in core/dbt/deps/tarball.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/deps/tarball.py#L113

Added line #L113 was not covered by tests
tarball=self.tarball, tarball_unrendered=self.tarball_unrendered, package=self.package
)

Expand Down
15 changes: 1 addition & 14 deletions core/dbt/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
env_secrets,
scrub_secrets,
DbtValidationError,
CommandError,
)
from dbt.node_types import NodeType, AccessType

Expand Down Expand Up @@ -135,20 +136,6 @@
pass


class CommandError(DbtRuntimeError):
def __init__(self, cwd: str, cmd: List[str], msg: str = "Error running command") -> None:
cmd_scrubbed = list(scrub_secrets(cmd_txt, env_secrets()) for cmd_txt in cmd)
super().__init__(msg)
self.cwd = cwd
self.cmd = cmd_scrubbed
self.args = (cwd, cmd_scrubbed, msg)

def __str__(self):
if len(self.cmd) == 0:
return f"{self.msg}: No arguments given"
return f'{self.msg}: "{self.cmd[0]}"'


class ExecutableError(CommandError):
def __init__(self, cwd: str, cmd: List[str], msg: str) -> None:
super().__init__(cwd, cmd, msg)
Expand Down Expand Up @@ -631,7 +618,7 @@
def get_message(self) -> str:
target_package_string = ""
if self.target_doc_package is not None:
target_package_string = f"in package '{self.target_doc_package}' "

Check warning on line 621 in core/dbt/exceptions.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/exceptions.py#L621

Added line #L621 was not covered by tests
msg = f"Documentation for '{self.node.unique_id}' depends on doc '{self.target_doc_name}' {target_package_string} which was not found"
return msg

Expand Down
4 changes: 2 additions & 2 deletions core/dbt/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,9 @@ def process(self, record):


def make_log_dir_if_missing(log_dir):
import dbt.clients.system
import dbt.common.clients.system

dbt.clients.system.make_directory(log_dir)
dbt.common.clients.system.make_directory(log_dir)


class DebugWarnings(logbook.compat.redirected_warnings):
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/parser/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
from dbt.node_types import NodeType, AccessType
from dbt.clients.jinja import get_rendered, MacroStack
from dbt.clients.jinja_static import statically_extract_macro_calls
from dbt.clients.system import (
from dbt.common.clients.system import (
make_directory,
path_exists,
read_json,
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/parser/read_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pathspec # type: ignore
import pathlib
from dataclasses import dataclass, field
from dbt.clients.system import load_file_contents
from dbt.common.clients.system import load_file_contents
from dbt.contracts.files import (
FilePath,
ParseFileType,
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/parser/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pathspec import PathSpec # type: ignore

from dbt.common.clients.jinja import extract_toplevel_blocks, BlockTag
from dbt.clients.system import find_matching
from dbt.common.clients.system import find_matching
from dbt.config import Project
from dbt.contracts.files import FilePath, AnySourceFile
from dbt.exceptions import ParsingError, DbtInternalError
Expand Down
11 changes: 7 additions & 4 deletions core/dbt/task/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
DebugCmdOut,
DebugCmdResult,
)
import dbt.clients.system
import dbt.common.clients.system
import dbt.exceptions
import dbt.common.exceptions
from dbt.adapters.factory import get_adapter, register_adapter
Expand Down Expand Up @@ -110,7 +110,8 @@ def run(self) -> bool:
if self.args.config_dir:
fire_event(
OpenCommand(
open_cmd=dbt.clients.system.open_dir_cmd(), profiles_dir=str(self.profiles_dir)
open_cmd=dbt.common.clients.system.open_dir_cmd(),
profiles_dir=str(self.profiles_dir),
)
)
return DebugRunStatus.SUCCESS.value
Expand Down Expand Up @@ -202,7 +203,9 @@ def _load_profile(self) -> SubtaskStatus:
),
)

raw_profile_data = load_yaml_text(dbt.clients.system.load_file_contents(self.profile_path))
raw_profile_data = load_yaml_text(
dbt.common.clients.system.load_file_contents(self.profile_path)
)
if isinstance(raw_profile_data, dict):
self.raw_profile_data = raw_profile_data

Expand Down Expand Up @@ -395,7 +398,7 @@ def _target_found(self) -> str:

def test_git(self) -> SubtaskStatus:
try:
dbt.clients.system.run_cmd(os.getcwd(), ["git", "--help"])
dbt.common.clients.system.run_cmd(os.getcwd(), ["git", "--help"])
except dbt.exceptions.ExecutableError as exc:
return SubtaskStatus(
log_msg=red("ERROR"),
Expand Down
Loading
Loading