Skip to content

Commit

Permalink
use dbt_common instead of implicit namespace package
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleArk committed Jan 9, 2024
1 parent fd0199b commit eb6b6f4
Show file tree
Hide file tree
Showing 66 changed files with 152 additions and 152 deletions.
9 changes: 0 additions & 9 deletions dbt/common/events/__init__.py

This file was deleted.

7 changes: 0 additions & 7 deletions dbt/common/exceptions/__init__.py

This file was deleted.

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
from collections import namedtuple

from dbt.common.exceptions import (
from dbt_common.exceptions import (
BlockDefinitionNotAtTopError,
DbtInternalError,
MissingCloseTagError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import json
from typing import Iterable, List, Dict, Union, Optional, Any

from dbt.common.exceptions import DbtRuntimeError
from dbt.common.utils import ForgivingJSONEncoder
from dbt_common.exceptions import DbtRuntimeError
from dbt_common.utils import ForgivingJSONEncoder

BOM = BOM_UTF8.decode("utf-8") # '\ufeff'

Expand Down
8 changes: 4 additions & 4 deletions dbt/common/clients/jinja.py → dbt_common/clients/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@
import jinja2.parser
import jinja2.sandbox

from dbt.common.utils import (
from dbt_common.utils import (
get_dbt_macro_name,
get_docs_macro_name,
get_materialization_macro_name,
get_test_macro_name,
)
from dbt.common.clients._jinja_blocks import BlockIterator, BlockData, BlockTag
from dbt_common.clients._jinja_blocks import BlockIterator, BlockData, BlockTag

from dbt.common.exceptions import (
from dbt_common.exceptions import (
CompilationError,
DbtInternalError,
CaughtMacroErrorWithNodeError,
MaterializationArgError,
JinjaRenderingError,
UndefinedCompilationError,
)
from dbt.common.exceptions.macros import MacroReturn, UndefinedMacroError, CaughtMacroError
from dbt_common.exceptions.macros import MacroReturn, UndefinedMacroError, CaughtMacroError


SUPPORTED_LANG_ARG = jinja2.nodes.Name("supported_languages", "param")
Expand Down
38 changes: 19 additions & 19 deletions dbt/common/clients/system.py → dbt_common/clients/system.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import dbt.common.exceptions.base
import dbt_common.exceptions.base
import errno
import fnmatch
import functools
Expand All @@ -14,18 +14,18 @@
from pathlib import Path
from typing import Any, Callable, Dict, List, NoReturn, Optional, Tuple, Type, Union

import dbt.common.exceptions
import dbt_common.exceptions
import requests
from dbt.common.events.functions import fire_event
from dbt.common.events.types import (
from dbt_common.events.functions import fire_event
from dbt_common.events.types import (
SystemCouldNotWrite,
SystemExecutingCmd,
SystemStdOut,
SystemStdErr,
SystemReportReturnCode,
)
from dbt.common.exceptions import DbtInternalError
from dbt.common.utils.connection import connection_exception_retry
from dbt_common.exceptions import DbtInternalError
from dbt_common.utils.connection import connection_exception_retry
from pathspec import PathSpec # type: ignore

if sys.platform == "win32":
Expand Down Expand Up @@ -154,7 +154,7 @@ def make_symlink(source: str, link_path: str) -> None:
"""
if not supports_symlinks():
# TODO: why not import these at top?
raise dbt.common.exceptions.SymbolicLinkError()
raise dbt_common.exceptions.SymbolicLinkError()

os.symlink(source, link_path)

Expand Down Expand Up @@ -198,7 +198,7 @@ def read_json(path: str) -> Dict[str, Any]:


def write_json(path: str, data: Dict[str, Any]) -> bool:
return write_file(path, json.dumps(data, cls=dbt.common.utils.encoding.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 @@ -345,7 +345,7 @@ def _handle_posix_cwd_error(exc: OSError, cwd: str, cmd: List[str]) -> NoReturn:
message = "Not a directory"
else:
message = "Unknown OSError: {} - cwd".format(str(exc))
raise dbt.common.exceptions.WorkingDirectoryError(cwd, cmd, message)
raise dbt_common.exceptions.WorkingDirectoryError(cwd, cmd, message)


def _handle_posix_cmd_error(exc: OSError, cwd: str, cmd: List[str]) -> NoReturn:
Expand All @@ -355,7 +355,7 @@ def _handle_posix_cmd_error(exc: OSError, cwd: str, cmd: List[str]) -> NoReturn:
message = "User does not have permissions for this command"
else:
message = "Unknown OSError: {} - cmd".format(str(exc))
raise dbt.common.exceptions.ExecutableError(cwd, cmd, message)
raise dbt_common.exceptions.ExecutableError(cwd, cmd, message)


def _handle_posix_error(exc: OSError, cwd: str, cmd: List[str]) -> NoReturn:
Expand Down Expand Up @@ -386,22 +386,22 @@ def _handle_posix_error(exc: OSError, cwd: str, cmd: List[str]) -> NoReturn:


def _handle_windows_error(exc: OSError, cwd: str, cmd: List[str]) -> NoReturn:
cls: Type[dbt.common.exceptions.DbtBaseException] = dbt.common.exceptions.base.CommandError
cls: Type[dbt_common.exceptions.DbtBaseException] = dbt_common.exceptions.base.CommandError
if exc.errno == errno.ENOENT:
message = (
"Could not find command, ensure it is in the user's PATH "
"and that the user has permissions to run it"
)
cls = dbt.common.exceptions.ExecutableError
cls = dbt_common.exceptions.ExecutableError
elif exc.errno == errno.ENOEXEC:
message = "Command was not executable, ensure it is valid"
cls = dbt.common.exceptions.ExecutableError
cls = dbt_common.exceptions.ExecutableError
elif exc.errno == errno.ENOTDIR:
message = (
"Unable to cd: path does not exist, user does not have"
" permissions, or not a directory"
)
cls = dbt.common.exceptions.WorkingDirectoryError
cls = dbt_common.exceptions.WorkingDirectoryError
else:
message = 'Unknown error: {} (errno={}: "{}")'.format(
str(exc), exc.errno, errno.errorcode.get(exc.errno, "<Unknown!>")
Expand All @@ -412,7 +412,7 @@ def _handle_windows_error(exc: OSError, cwd: str, cmd: List[str]) -> NoReturn:
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.common.exceptions.base.CommandError(cwd, cmd)
raise dbt_common.exceptions.base.CommandError(cwd, cmd)

# all of these functions raise unconditionally
if os.name == "nt":
Expand All @@ -421,15 +421,15 @@ def _interpret_oserror(exc: OSError, cwd: str, cmd: List[str]) -> NoReturn:
_handle_posix_error(exc, cwd, cmd)

# this should not be reachable, raise _something_ at least!
raise dbt.common.exceptions.DbtInternalError(
raise dbt_common.exceptions.DbtInternalError(
"Unhandled exception in _interpret_oserror: {}".format(exc)
)


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.common.exceptions.base.CommandError(cwd, cmd)
raise dbt_common.exceptions.base.CommandError(cwd, cmd)

# the env argument replaces the environment entirely, which has exciting
# consequences on Windows! Do an update instead.
Expand All @@ -455,7 +455,7 @@ def run_cmd(cwd: str, cmd: List[str], env: Optional[Dict[str, Any]] = None) -> T

if proc.returncode != 0:
fire_event(SystemReportReturnCode(returncode=proc.returncode))
raise dbt.common.exceptions.CommandResultError(cwd, cmd, proc.returncode, out, err)
raise dbt_common.exceptions.CommandResultError(cwd, cmd, proc.returncode, out, err)

return out, err

Expand Down Expand Up @@ -503,7 +503,7 @@ def untar_package(tar_path: str, dest_dir: str, rename_to: Optional[str] = None)
if rename_to:
downloaded_path = os.path.join(dest_dir, tar_dir_name)
desired_path = os.path.join(dest_dir, rename_to)
dbt.common.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
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from itertools import chain
from typing import Callable, Dict, Any, List, TypeVar, Type

from dbt.common.contracts.config.metadata import Metadata
from dbt.common.exceptions import CompilationError, DbtInternalError
from dbt.common.contracts.config.properties import AdditionalPropertiesAllowed
from dbt.common.contracts.util import Replaceable
from dbt_common.contracts.config.metadata import Metadata
from dbt_common.exceptions import CompilationError, DbtInternalError
from dbt_common.contracts.config.properties import AdditionalPropertiesAllowed
from dbt_common.contracts.util import Replaceable

T = TypeVar("T", bound="BaseConfig")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dbt.common.dataclass_schema import StrEnum
from dbt_common.dataclass_schema import StrEnum


class OnConfigurationChangeOption(StrEnum):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from enum import Enum
from typing import TypeVar, Type, Optional, Dict, Any

from dbt.common.exceptions import DbtInternalError
from dbt_common.exceptions import DbtInternalError

M = TypeVar("M", bound="Metadata")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dataclasses import dataclass, field
from typing import Dict, Any

from dbt.common.dataclass_schema import ExtensibleDbtClassMixin
from dbt_common.dataclass_schema import ExtensibleDbtClassMixin


class AdditionalPropertiesMixin:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from enum import Enum
from typing import Optional, List

from dbt.common.dataclass_schema import dbtClassMixin
from dbt_common.dataclass_schema import dbtClassMixin


class ConstraintType(str, Enum):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dataclasses


# TODO: remove from dbt.common.contracts.util:: Replaceable + references
# TODO: remove from dbt_common.contracts.util:: Replaceable + references
class Replaceable:
def replace(self, **kwargs):
return dataclasses.replace(self, **kwargs)
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions dbt_common/events/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from dbt_common.events.base_types import EventLevel
from dbt_common.events.event_manager_client import get_event_manager
from dbt_common.events.functions import get_stdout_config
from dbt_common.events.logger import LineFormat

# make sure event manager starts with a logger
get_event_manager().add_logger(
get_stdout_config(LineFormat.PlainText, True, EventLevel.INFO, False)
)
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from enum import Enum
import os
import threading
from dbt.common.events import types_pb2
from dbt_common.events import types_pb2
import sys
from google.protobuf.json_format import ParseDict, MessageToDict, MessageToJson
from google.protobuf.message import Message
from dbt.common.events.helpers import get_json_string_utcnow
from dbt_common.events.helpers import get_json_string_utcnow
from typing import Optional

from dbt.common.invocation import get_invocation_id
from dbt_common.invocation import get_invocation_id

if sys.version_info >= (3, 8):
from typing import Protocol
Expand All @@ -23,7 +23,7 @@


def get_global_metadata_vars() -> dict:
from dbt.common.events.functions import get_metadata_vars
from dbt_common.events.functions import get_metadata_vars

return get_metadata_vars()

Expand Down Expand Up @@ -70,8 +70,8 @@ def __init__(self, *args, **kwargs) -> None:
self.pb_msg = ParseDict(kwargs, msg_cls())
except Exception:
# Imports need to be here to avoid circular imports
from dbt.common.events.types import Note
from dbt.common.events.functions import fire_event
from dbt_common.events.types import Note
from dbt_common.events.functions import fire_event

error_msg = f"[{class_name}]: Unable to parse dict {kwargs}"
# If we're testing throw an error so that we notice failures
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import logging
from typing import Union

from dbt.common.events.base_types import EventLevel
from dbt.common.events.types import Note
from dbt.common.events.event_manager import IEventManager
from dbt_common.events.base_types import EventLevel
from dbt_common.events.types import Note
from dbt_common.events.event_manager import IEventManager


_log_level_to_event_level_map = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import traceback
from typing import Callable, List, Optional, Protocol, Tuple

from dbt.common.events.base_types import BaseEvent, EventLevel, msg_from_base_event, EventMsg
from dbt.common.events.logger import LoggerConfig, _Logger, _TextLogger, _JsonLogger, LineFormat
from dbt_common.events.base_types import BaseEvent, EventLevel, msg_from_base_event, EventMsg
from dbt_common.events.logger import LoggerConfig, _Logger, _TextLogger, _JsonLogger, LineFormat


class EventManager:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Since dbt-rpc does not do its own log setup, and since some events can
# currently fire before logs can be configured by setup_event_logger(), we
# create a default configuration with default settings and no file output.
from dbt.common.events.event_manager import IEventManager, EventManager
from dbt_common.events.event_manager import IEventManager, EventManager

_EVENT_MANAGER: IEventManager = EventManager()

Expand Down
4 changes: 2 additions & 2 deletions dbt/common/events/format.py → dbt_common/events/format.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from dbt.common import ui
from dbt_common import ui

from typing import Optional, Union
from datetime import datetime

from dbt.common.events.interfaces import LoggableDbtObject
from dbt_common.events.interfaces import LoggableDbtObject


def format_fancy_output_line(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from pathlib import Path

from dbt.common.events.event_manager_client import get_event_manager
from dbt.common.invocation import get_invocation_id
from dbt.common.helper_types import WarnErrorOptions
from dbt.common.utils import ForgivingJSONEncoder
from dbt.common.events.base_types import BaseEvent, EventLevel, EventMsg
from dbt.common.events.logger import LoggerConfig, LineFormat
from dbt.common.exceptions import scrub_secrets, env_secrets
from dbt.common.events.types import Note
from dbt_common.events.event_manager_client import get_event_manager
from dbt_common.invocation import get_invocation_id
from dbt_common.helper_types import WarnErrorOptions
from dbt_common.utils import ForgivingJSONEncoder
from dbt_common.events.base_types import BaseEvent, EventLevel, EventMsg
from dbt_common.events.logger import LoggerConfig, LineFormat
from dbt_common.exceptions import scrub_secrets, env_secrets
from dbt_common.events.types import Note
from functools import partial
import json
import os
Expand Down Expand Up @@ -115,7 +115,7 @@ def warn_or_error(event, node=None) -> None:
if WARN_ERROR or WARN_ERROR_OPTIONS.includes(type(event).__name__):

# TODO: resolve this circular import when at top
from dbt.common.exceptions import EventCompilationError
from dbt_common.exceptions import EventCompilationError

raise EventCompilationError(event.message(), node)
else:
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit eb6b6f4

Please sign in to comment.