From eb6b6f4a155f94d4863d8f503f8eb997ab6226d3 Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Tue, 9 Jan 2024 15:50:10 -0500 Subject: [PATCH] use dbt_common instead of implicit namespace package --- dbt/common/events/__init__.py | 9 ----- dbt/common/exceptions/__init__.py | 7 ---- {dbt/common => dbt_common}/__init__.py | 0 .../common => dbt_common}/clients/__init__.py | 0 .../clients/_jinja_blocks.py | 2 +- .../clients/agate_helper.py | 4 +- {dbt/common => dbt_common}/clients/jinja.py | 8 ++-- {dbt/common => dbt_common}/clients/system.py | 38 +++++++++--------- {dbt/common => dbt_common}/constants.py | 0 .../contracts/__init__.py | 0 .../contracts/config/__init__.py | 0 .../contracts/config/base.py | 8 ++-- .../contracts/config/materialization.py | 2 +- .../contracts/config/metadata.py | 2 +- .../contracts/config/properties.py | 2 +- .../contracts/connection.py | 0 .../contracts/constraints.py | 2 +- {dbt/common => dbt_common}/contracts/util.py | 2 +- .../common => dbt_common}/dataclass_schema.py | 0 {dbt/common => dbt_common}/events/README.md | 0 dbt_common/events/__init__.py | 9 +++++ .../events/base_types.py | 12 +++--- .../events/contextvars.py | 0 .../events/event_handler.py | 6 +-- .../events/event_manager.py | 4 +- .../events/event_manager_client.py | 2 +- {dbt/common => dbt_common}/events/format.py | 4 +- .../common => dbt_common}/events/functions.py | 18 ++++----- {dbt/common => dbt_common}/events/helpers.py | 0 .../events/interfaces.py | 0 {dbt/common => dbt_common}/events/logger.py | 8 ++-- {dbt/common => dbt_common}/events/types.proto | 0 {dbt/common => dbt_common}/events/types.py | 2 +- .../common => dbt_common}/events/types_pb2.py | 0 dbt_common/exceptions/__init__.py | 7 ++++ {dbt/common => dbt_common}/exceptions/base.py | 4 +- .../common => dbt_common}/exceptions/cache.py | 2 +- .../exceptions/connection.py | 0 .../exceptions/contracts.py | 2 +- .../exceptions/events.py | 2 +- .../common => dbt_common}/exceptions/jinja.py | 2 +- .../exceptions/macros.py | 2 +- .../exceptions/system.py | 2 +- {dbt/common => dbt_common}/helper_types.py | 2 +- {dbt/common => dbt_common}/invocation.py | 0 {dbt => dbt_common}/py.typed | 0 {dbt/common => dbt_common}/semver.py | 8 ++-- {dbt/common => dbt_common}/ui.py | 0 {dbt/common => dbt_common}/utils/__init__.py | 10 ++--- {dbt/common => dbt_common}/utils/casting.py | 0 .../common => dbt_common}/utils/connection.py | 6 +-- {dbt/common => dbt_common}/utils/dict.py | 6 +-- {dbt/common => dbt_common}/utils/encoding.py | 0 {dbt/common => dbt_common}/utils/executor.py | 0 .../common => dbt_common}/utils/formatting.py | 0 {dbt/common => dbt_common}/utils/jinja.py | 2 +- pyproject.toml | 2 +- tests/unit/test_agate_helper.py | 2 +- tests/unit/test_connection_retries.py | 4 +- tests/unit/test_core_dbt_utils.py | 4 +- tests/unit/test_event_handler.py | 6 +-- tests/unit/test_helper_types.py | 4 +- tests/unit/test_jinja.py | 4 +- tests/unit/test_model_config.py | 6 +-- tests/unit/test_system_client.py | 40 +++++++++---------- tests/unit/test_utils.py | 24 +++++------ 66 files changed, 152 insertions(+), 152 deletions(-) delete mode 100644 dbt/common/events/__init__.py delete mode 100644 dbt/common/exceptions/__init__.py rename {dbt/common => dbt_common}/__init__.py (100%) rename {dbt/common => dbt_common}/clients/__init__.py (100%) rename {dbt/common => dbt_common}/clients/_jinja_blocks.py (99%) rename {dbt/common => dbt_common}/clients/agate_helper.py (98%) rename {dbt/common => dbt_common}/clients/jinja.py (98%) rename {dbt/common => dbt_common}/clients/system.py (94%) rename {dbt/common => dbt_common}/constants.py (100%) rename {dbt/common => dbt_common}/contracts/__init__.py (100%) rename {dbt/common => dbt_common}/contracts/config/__init__.py (100%) rename {dbt/common => dbt_common}/contracts/config/base.py (97%) rename {dbt/common => dbt_common}/contracts/config/materialization.py (81%) rename {dbt/common => dbt_common}/contracts/config/metadata.py (97%) rename {dbt/common => dbt_common}/contracts/config/properties.py (97%) rename {dbt/common => dbt_common}/contracts/connection.py (100%) rename {dbt/common => dbt_common}/contracts/constraints.py (95%) rename {dbt/common => dbt_common}/contracts/util.py (67%) rename {dbt/common => dbt_common}/dataclass_schema.py (100%) rename {dbt/common => dbt_common}/events/README.md (100%) create mode 100644 dbt_common/events/__init__.py rename {dbt/common => dbt_common}/events/base_types.py (93%) rename {dbt/common => dbt_common}/events/contextvars.py (100%) rename {dbt/common => dbt_common}/events/event_handler.py (89%) rename {dbt/common => dbt_common}/events/event_manager.py (94%) rename {dbt/common => dbt_common}/events/event_manager_client.py (93%) rename {dbt/common => dbt_common}/events/format.py (94%) rename {dbt/common => dbt_common}/events/functions.py (89%) rename {dbt/common => dbt_common}/events/helpers.py (100%) rename {dbt/common => dbt_common}/events/interfaces.py (100%) rename {dbt/common => dbt_common}/events/logger.py (96%) rename {dbt/common => dbt_common}/events/types.proto (100%) rename {dbt/common => dbt_common}/events/types.py (98%) rename {dbt/common => dbt_common}/events/types_pb2.py (100%) create mode 100644 dbt_common/exceptions/__init__.py rename {dbt/common => dbt_common}/exceptions/base.py (98%) rename {dbt/common => dbt_common}/exceptions/cache.py (97%) rename {dbt/common => dbt_common}/exceptions/connection.py (100%) rename {dbt/common => dbt_common}/exceptions/contracts.py (90%) rename {dbt/common => dbt_common}/exceptions/events.py (79%) rename {dbt/common => dbt_common}/exceptions/jinja.py (98%) rename {dbt/common => dbt_common}/exceptions/macros.py (98%) rename {dbt/common => dbt_common}/exceptions/system.py (95%) rename {dbt/common => dbt_common}/helper_types.py (98%) rename {dbt/common => dbt_common}/invocation.py (100%) rename {dbt => dbt_common}/py.typed (100%) rename {dbt/common => dbt_common}/semver.py (98%) rename {dbt/common => dbt_common}/ui.py (100%) rename {dbt/common => dbt_common}/utils/__init__.py (59%) rename {dbt/common => dbt_common}/utils/casting.py (100%) rename {dbt/common => dbt_common}/utils/connection.py (86%) rename {dbt/common => dbt_common}/utils/dict.py (95%) rename {dbt/common => dbt_common}/utils/encoding.py (100%) rename {dbt/common => dbt_common}/utils/executor.py (100%) rename {dbt/common => dbt_common}/utils/formatting.py (100%) rename {dbt/common => dbt_common}/utils/jinja.py (94%) diff --git a/dbt/common/events/__init__.py b/dbt/common/events/__init__.py deleted file mode 100644 index e4d1acb9..00000000 --- a/dbt/common/events/__init__.py +++ /dev/null @@ -1,9 +0,0 @@ -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) -) diff --git a/dbt/common/exceptions/__init__.py b/dbt/common/exceptions/__init__.py deleted file mode 100644 index 1c0de8b1..00000000 --- a/dbt/common/exceptions/__init__.py +++ /dev/null @@ -1,7 +0,0 @@ -from dbt.common.exceptions.base import * # noqa -from dbt.common.exceptions.events import * # noqa -from dbt.common.exceptions.macros import * # noqa -from dbt.common.exceptions.contracts import * # noqa -from dbt.common.exceptions.connection import * # noqa -from dbt.common.exceptions.system import * # noqa -from dbt.common.exceptions.jinja import * # noqa diff --git a/dbt/common/__init__.py b/dbt_common/__init__.py similarity index 100% rename from dbt/common/__init__.py rename to dbt_common/__init__.py diff --git a/dbt/common/clients/__init__.py b/dbt_common/clients/__init__.py similarity index 100% rename from dbt/common/clients/__init__.py rename to dbt_common/clients/__init__.py diff --git a/dbt/common/clients/_jinja_blocks.py b/dbt_common/clients/_jinja_blocks.py similarity index 99% rename from dbt/common/clients/_jinja_blocks.py rename to dbt_common/clients/_jinja_blocks.py index 9eb85df1..88d498ea 100644 --- a/dbt/common/clients/_jinja_blocks.py +++ b/dbt_common/clients/_jinja_blocks.py @@ -1,7 +1,7 @@ import re from collections import namedtuple -from dbt.common.exceptions import ( +from dbt_common.exceptions import ( BlockDefinitionNotAtTopError, DbtInternalError, MissingCloseTagError, diff --git a/dbt/common/clients/agate_helper.py b/dbt_common/clients/agate_helper.py similarity index 98% rename from dbt/common/clients/agate_helper.py rename to dbt_common/clients/agate_helper.py index d7ac0916..fecd0f20 100644 --- a/dbt/common/clients/agate_helper.py +++ b/dbt_common/clients/agate_helper.py @@ -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' diff --git a/dbt/common/clients/jinja.py b/dbt_common/clients/jinja.py similarity index 98% rename from dbt/common/clients/jinja.py rename to dbt_common/clients/jinja.py index e01ad570..702c63db 100644 --- a/dbt/common/clients/jinja.py +++ b/dbt_common/clients/jinja.py @@ -15,15 +15,15 @@ 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, @@ -31,7 +31,7 @@ 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") diff --git a/dbt/common/clients/system.py b/dbt_common/clients/system.py similarity index 94% rename from dbt/common/clients/system.py rename to dbt_common/clients/system.py index 1b1b5eba..5a8db79c 100644 --- a/dbt/common/clients/system.py +++ b/dbt_common/clients/system.py @@ -1,4 +1,4 @@ -import dbt.common.exceptions.base +import dbt_common.exceptions.base import errno import fnmatch import functools @@ -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": @@ -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) @@ -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]): @@ -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: @@ -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: @@ -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, "") @@ -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": @@ -421,7 +421,7 @@ 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) ) @@ -429,7 +429,7 @@ def _interpret_oserror(exc: OSError, cwd: str, cmd: List[str]) -> NoReturn: 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. @@ -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 @@ -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): diff --git a/dbt/common/constants.py b/dbt_common/constants.py similarity index 100% rename from dbt/common/constants.py rename to dbt_common/constants.py diff --git a/dbt/common/contracts/__init__.py b/dbt_common/contracts/__init__.py similarity index 100% rename from dbt/common/contracts/__init__.py rename to dbt_common/contracts/__init__.py diff --git a/dbt/common/contracts/config/__init__.py b/dbt_common/contracts/config/__init__.py similarity index 100% rename from dbt/common/contracts/config/__init__.py rename to dbt_common/contracts/config/__init__.py diff --git a/dbt/common/contracts/config/base.py b/dbt_common/contracts/config/base.py similarity index 97% rename from dbt/common/contracts/config/base.py rename to dbt_common/contracts/config/base.py index accaf500..8fc4ccdf 100644 --- a/dbt/common/contracts/config/base.py +++ b/dbt_common/contracts/config/base.py @@ -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") diff --git a/dbt/common/contracts/config/materialization.py b/dbt_common/contracts/config/materialization.py similarity index 81% rename from dbt/common/contracts/config/materialization.py rename to dbt_common/contracts/config/materialization.py index 98975058..5f7f536b 100644 --- a/dbt/common/contracts/config/materialization.py +++ b/dbt_common/contracts/config/materialization.py @@ -1,4 +1,4 @@ -from dbt.common.dataclass_schema import StrEnum +from dbt_common.dataclass_schema import StrEnum class OnConfigurationChangeOption(StrEnum): diff --git a/dbt/common/contracts/config/metadata.py b/dbt_common/contracts/config/metadata.py similarity index 97% rename from dbt/common/contracts/config/metadata.py rename to dbt_common/contracts/config/metadata.py index 2f670649..83f3457e 100644 --- a/dbt/common/contracts/config/metadata.py +++ b/dbt_common/contracts/config/metadata.py @@ -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") diff --git a/dbt/common/contracts/config/properties.py b/dbt_common/contracts/config/properties.py similarity index 97% rename from dbt/common/contracts/config/properties.py rename to dbt_common/contracts/config/properties.py index 0b09d90a..ce669623 100644 --- a/dbt/common/contracts/config/properties.py +++ b/dbt_common/contracts/config/properties.py @@ -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: diff --git a/dbt/common/contracts/connection.py b/dbt_common/contracts/connection.py similarity index 100% rename from dbt/common/contracts/connection.py rename to dbt_common/contracts/connection.py diff --git a/dbt/common/contracts/constraints.py b/dbt_common/contracts/constraints.py similarity index 95% rename from dbt/common/contracts/constraints.py rename to dbt_common/contracts/constraints.py index 1c8643b8..c01ee6f8 100644 --- a/dbt/common/contracts/constraints.py +++ b/dbt_common/contracts/constraints.py @@ -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): diff --git a/dbt/common/contracts/util.py b/dbt_common/contracts/util.py similarity index 67% rename from dbt/common/contracts/util.py rename to dbt_common/contracts/util.py index d1d11b4a..1467e4d8 100644 --- a/dbt/common/contracts/util.py +++ b/dbt_common/contracts/util.py @@ -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) diff --git a/dbt/common/dataclass_schema.py b/dbt_common/dataclass_schema.py similarity index 100% rename from dbt/common/dataclass_schema.py rename to dbt_common/dataclass_schema.py diff --git a/dbt/common/events/README.md b/dbt_common/events/README.md similarity index 100% rename from dbt/common/events/README.md rename to dbt_common/events/README.md diff --git a/dbt_common/events/__init__.py b/dbt_common/events/__init__.py new file mode 100644 index 00000000..6ba789b1 --- /dev/null +++ b/dbt_common/events/__init__.py @@ -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) +) diff --git a/dbt/common/events/base_types.py b/dbt_common/events/base_types.py similarity index 93% rename from dbt/common/events/base_types.py rename to dbt_common/events/base_types.py index 2e385150..83f33535 100644 --- a/dbt/common/events/base_types.py +++ b/dbt_common/events/base_types.py @@ -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 @@ -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() @@ -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 diff --git a/dbt/common/events/contextvars.py b/dbt_common/events/contextvars.py similarity index 100% rename from dbt/common/events/contextvars.py rename to dbt_common/events/contextvars.py diff --git a/dbt/common/events/event_handler.py b/dbt_common/events/event_handler.py similarity index 89% rename from dbt/common/events/event_handler.py rename to dbt_common/events/event_handler.py index e6c934f9..58e23a13 100644 --- a/dbt/common/events/event_handler.py +++ b/dbt_common/events/event_handler.py @@ -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 = { diff --git a/dbt/common/events/event_manager.py b/dbt_common/events/event_manager.py similarity index 94% rename from dbt/common/events/event_manager.py rename to dbt_common/events/event_manager.py index df9c7f90..80ea9805 100644 --- a/dbt/common/events/event_manager.py +++ b/dbt_common/events/event_manager.py @@ -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: diff --git a/dbt/common/events/event_manager_client.py b/dbt_common/events/event_manager_client.py similarity index 93% rename from dbt/common/events/event_manager_client.py rename to dbt_common/events/event_manager_client.py index 294bbdef..1b674f6e 100644 --- a/dbt/common/events/event_manager_client.py +++ b/dbt_common/events/event_manager_client.py @@ -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() diff --git a/dbt/common/events/format.py b/dbt_common/events/format.py similarity index 94% rename from dbt/common/events/format.py rename to dbt_common/events/format.py index 90f7607d..fd32c129 100644 --- a/dbt/common/events/format.py +++ b/dbt_common/events/format.py @@ -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( diff --git a/dbt/common/events/functions.py b/dbt_common/events/functions.py similarity index 89% rename from dbt/common/events/functions.py rename to dbt_common/events/functions.py index 619d7462..ae029038 100644 --- a/dbt/common/events/functions.py +++ b/dbt_common/events/functions.py @@ -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 @@ -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: diff --git a/dbt/common/events/helpers.py b/dbt_common/events/helpers.py similarity index 100% rename from dbt/common/events/helpers.py rename to dbt_common/events/helpers.py diff --git a/dbt/common/events/interfaces.py b/dbt_common/events/interfaces.py similarity index 100% rename from dbt/common/events/interfaces.py rename to dbt_common/events/interfaces.py diff --git a/dbt/common/events/logger.py b/dbt_common/events/logger.py similarity index 96% rename from dbt/common/events/logger.py rename to dbt_common/events/logger.py index 679e711e..ba6f3e18 100644 --- a/dbt/common/events/logger.py +++ b/dbt_common/events/logger.py @@ -9,9 +9,9 @@ from colorama import Style -from dbt.common.events.base_types import EventLevel, EventMsg -from dbt.common.events.format import timestamp_to_datetime_string -from dbt.common.utils import ForgivingJSONEncoder +from dbt_common.events.base_types import EventLevel, EventMsg +from dbt_common.events.format import timestamp_to_datetime_string +from dbt_common.utils import ForgivingJSONEncoder # A Filter is a function which takes a BaseEvent and returns True if the event # should be logged, False otherwise. @@ -172,7 +172,7 @@ def _get_thread_name(self) -> str: class _JsonLogger(_Logger): def create_line(self, msg: EventMsg) -> str: - from dbt.common.events.functions import msg_to_dict + from dbt_common.events.functions import msg_to_dict msg_dict = msg_to_dict(msg) raw_log_line = json.dumps(msg_dict, sort_keys=True, cls=ForgivingJSONEncoder) diff --git a/dbt/common/events/types.proto b/dbt_common/events/types.proto similarity index 100% rename from dbt/common/events/types.proto rename to dbt_common/events/types.proto diff --git a/dbt/common/events/types.py b/dbt_common/events/types.py similarity index 98% rename from dbt/common/events/types.py rename to dbt_common/events/types.py index 26e4b268..0ee5cd00 100644 --- a/dbt/common/events/types.py +++ b/dbt_common/events/types.py @@ -1,4 +1,4 @@ -from dbt.common.events.base_types import ( +from dbt_common.events.base_types import ( DebugLevel, InfoLevel, ) diff --git a/dbt/common/events/types_pb2.py b/dbt_common/events/types_pb2.py similarity index 100% rename from dbt/common/events/types_pb2.py rename to dbt_common/events/types_pb2.py diff --git a/dbt_common/exceptions/__init__.py b/dbt_common/exceptions/__init__.py new file mode 100644 index 00000000..437ef6c0 --- /dev/null +++ b/dbt_common/exceptions/__init__.py @@ -0,0 +1,7 @@ +from dbt_common.exceptions.base import * # noqa +from dbt_common.exceptions.events import * # noqa +from dbt_common.exceptions.macros import * # noqa +from dbt_common.exceptions.contracts import * # noqa +from dbt_common.exceptions.connection import * # noqa +from dbt_common.exceptions.system import * # noqa +from dbt_common.exceptions.jinja import * # noqa diff --git a/dbt/common/exceptions/base.py b/dbt_common/exceptions/base.py similarity index 98% rename from dbt/common/exceptions/base.py rename to dbt_common/exceptions/base.py index 0a7d03d2..a44e3451 100644 --- a/dbt/common/exceptions/base.py +++ b/dbt_common/exceptions/base.py @@ -2,8 +2,8 @@ from typing import List, Any, Optional import os -from dbt.common.constants import SECRET_ENV_PREFIX -from dbt.common.dataclass_schema import ValidationError +from dbt_common.constants import SECRET_ENV_PREFIX +from dbt_common.dataclass_schema import ValidationError def env_secrets() -> List[str]: diff --git a/dbt/common/exceptions/cache.py b/dbt_common/exceptions/cache.py similarity index 97% rename from dbt/common/exceptions/cache.py rename to dbt_common/exceptions/cache.py index d557be07..9b51f26f 100644 --- a/dbt/common/exceptions/cache.py +++ b/dbt_common/exceptions/cache.py @@ -1,7 +1,7 @@ import re from typing import Dict -from dbt.common.exceptions import DbtInternalError +from dbt_common.exceptions import DbtInternalError class CacheInconsistencyError(DbtInternalError): diff --git a/dbt/common/exceptions/connection.py b/dbt_common/exceptions/connection.py similarity index 100% rename from dbt/common/exceptions/connection.py rename to dbt_common/exceptions/connection.py diff --git a/dbt/common/exceptions/contracts.py b/dbt_common/exceptions/contracts.py similarity index 90% rename from dbt/common/exceptions/contracts.py rename to dbt_common/exceptions/contracts.py index 6b32793d..2ea0053c 100644 --- a/dbt/common/exceptions/contracts.py +++ b/dbt_common/exceptions/contracts.py @@ -1,5 +1,5 @@ from typing import Any -from dbt.common.exceptions import CompilationError +from dbt_common.exceptions import CompilationError # this is part of the context and also raised in dbt.contracts.relation.py diff --git a/dbt/common/exceptions/events.py b/dbt_common/exceptions/events.py similarity index 79% rename from dbt/common/exceptions/events.py rename to dbt_common/exceptions/events.py index a7fd09c3..862922a1 100644 --- a/dbt/common/exceptions/events.py +++ b/dbt_common/exceptions/events.py @@ -1,4 +1,4 @@ -from dbt.common.exceptions import CompilationError, scrub_secrets, env_secrets +from dbt_common.exceptions import CompilationError, scrub_secrets, env_secrets # event level exception diff --git a/dbt/common/exceptions/jinja.py b/dbt_common/exceptions/jinja.py similarity index 98% rename from dbt/common/exceptions/jinja.py rename to dbt_common/exceptions/jinja.py index 30aa4d66..ced91362 100644 --- a/dbt/common/exceptions/jinja.py +++ b/dbt_common/exceptions/jinja.py @@ -1,4 +1,4 @@ -from dbt.common.exceptions import CompilationError +from dbt_common.exceptions import CompilationError class BlockDefinitionNotAtTopError(CompilationError): diff --git a/dbt/common/exceptions/macros.py b/dbt_common/exceptions/macros.py similarity index 98% rename from dbt/common/exceptions/macros.py rename to dbt_common/exceptions/macros.py index 45644f66..e2cea26c 100644 --- a/dbt/common/exceptions/macros.py +++ b/dbt_common/exceptions/macros.py @@ -1,6 +1,6 @@ from typing import Any -from dbt.common.exceptions import CompilationError, DbtBaseException +from dbt_common.exceptions import CompilationError, DbtBaseException class MacroReturn(DbtBaseException): diff --git a/dbt/common/exceptions/system.py b/dbt_common/exceptions/system.py similarity index 95% rename from dbt/common/exceptions/system.py rename to dbt_common/exceptions/system.py index 0e634ffb..b0062f63 100644 --- a/dbt/common/exceptions/system.py +++ b/dbt_common/exceptions/system.py @@ -1,6 +1,6 @@ from typing import List, Union, Any -from dbt.common.exceptions import CompilationError, CommandError, scrub_secrets, env_secrets +from dbt_common.exceptions import CompilationError, CommandError, scrub_secrets, env_secrets class SymbolicLinkError(CompilationError): diff --git a/dbt/common/helper_types.py b/dbt_common/helper_types.py similarity index 98% rename from dbt/common/helper_types.py rename to dbt_common/helper_types.py index 457b0222..359b407a 100644 --- a/dbt/common/helper_types.py +++ b/dbt_common/helper_types.py @@ -7,7 +7,7 @@ from typing import Tuple, AbstractSet, Union from typing import Callable, cast, Generic, Optional, TypeVar, List, NewType, Set -from dbt.common.dataclass_schema import ( +from dbt_common.dataclass_schema import ( dbtClassMixin, ValidationError, StrEnum, diff --git a/dbt/common/invocation.py b/dbt_common/invocation.py similarity index 100% rename from dbt/common/invocation.py rename to dbt_common/invocation.py diff --git a/dbt/py.typed b/dbt_common/py.typed similarity index 100% rename from dbt/py.typed rename to dbt_common/py.typed diff --git a/dbt/common/semver.py b/dbt_common/semver.py similarity index 98% rename from dbt/common/semver.py rename to dbt_common/semver.py index 0ffa8992..951f4e8e 100644 --- a/dbt/common/semver.py +++ b/dbt_common/semver.py @@ -2,10 +2,10 @@ import re from typing import List -import dbt.common.exceptions.base -from dbt.common.exceptions import VersionsNotCompatibleError +import dbt_common.exceptions.base +from dbt_common.exceptions import VersionsNotCompatibleError -from dbt.common.dataclass_schema import dbtClassMixin, StrEnum +from dbt_common.dataclass_schema import dbtClassMixin, StrEnum from typing import Optional @@ -96,7 +96,7 @@ def from_version_string(cls, version_string): match = _VERSION_REGEX.match(version_string) if not match: - raise dbt.common.exceptions.base.SemverError( + raise dbt_common.exceptions.base.SemverError( f'"{version_string}" is not a valid semantic version.' ) diff --git a/dbt/common/ui.py b/dbt_common/ui.py similarity index 100% rename from dbt/common/ui.py rename to dbt_common/ui.py diff --git a/dbt/common/utils/__init__.py b/dbt_common/utils/__init__.py similarity index 59% rename from dbt/common/utils/__init__.py rename to dbt_common/utils/__init__.py index 495b69fa..16523f5c 100644 --- a/dbt/common/utils/__init__.py +++ b/dbt_common/utils/__init__.py @@ -1,12 +1,12 @@ -from dbt.common.utils.encoding import md5, JSONEncoder, ForgivingJSONEncoder +from dbt_common.utils.encoding import md5, JSONEncoder, ForgivingJSONEncoder -from dbt.common.utils.casting import ( +from dbt_common.utils.casting import ( cast_to_str, cast_to_int, cast_dict_to_dict_of_strings, ) -from dbt.common.utils.dict import ( +from dbt_common.utils.dict import ( AttrDict, filter_null_values, merge, @@ -15,9 +15,9 @@ deep_map_render, ) -from dbt.common.utils.executor import executor +from dbt_common.utils.executor import executor -from dbt.common.utils.jinja import ( +from dbt_common.utils.jinja import ( get_dbt_macro_name, get_docs_macro_name, get_materialization_macro_name, diff --git a/dbt/common/utils/casting.py b/dbt_common/utils/casting.py similarity index 100% rename from dbt/common/utils/casting.py rename to dbt_common/utils/casting.py diff --git a/dbt/common/utils/connection.py b/dbt_common/utils/connection.py similarity index 86% rename from dbt/common/utils/connection.py rename to dbt_common/utils/connection.py index fa184d15..890c3e99 100644 --- a/dbt/common/utils/connection.py +++ b/dbt_common/utils/connection.py @@ -1,7 +1,7 @@ import time -from dbt.common.events.types import RecordRetryException, RetryExternalCall -from dbt.common.exceptions import ConnectionError +from dbt_common.events.types import RecordRetryException, RetryExternalCall +from dbt_common.exceptions import ConnectionError from tarfile import ReadError import requests @@ -23,7 +23,7 @@ def connection_exception_retry(fn, max_attempts: int, attempt: int = 0): ) 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 + from dbt_common.events.functions import fire_event fire_event(RecordRetryException(exc=str(exc))) fire_event(RetryExternalCall(attempt=attempt, max=max_attempts)) diff --git a/dbt/common/utils/dict.py b/dbt_common/utils/dict.py similarity index 95% rename from dbt/common/utils/dict.py rename to dbt_common/utils/dict.py index 6228c1c8..a00e331c 100644 --- a/dbt/common/utils/dict.py +++ b/dbt_common/utils/dict.py @@ -2,7 +2,7 @@ import datetime from typing import Dict, Optional, TypeVar, Callable, Any, Tuple, Union, Type -from dbt.common.exceptions import DbtConfigError, RecursionError +from dbt_common.exceptions import DbtConfigError, RecursionError K_T = TypeVar("K_T") V_T = TypeVar("V_T") @@ -40,7 +40,7 @@ def _merge(a, b): # http://stackoverflow.com/questions/20656135/python-deep-merge-dictionary-data def deep_merge(*args): """ - >>> dbt.common.utils.deep_merge({'a': 1, 'b': 2, 'c': 3}, {'a': 2}, {'a': 3, 'b': 1}) # noqa + >>> dbt_common.utils.deep_merge({'a': 1, 'b': 2, 'c': 3}, {'a': 2}, {'a': 3, 'b': 1}) # noqa {'a': 3, 'b': 1, 'c': 3} """ if len(args) == 0: @@ -118,7 +118,7 @@ def deep_map_render(func: Callable[[Any, Tuple[Union[str, int], ...]], Any], val iterable over the __getitem__ keys needed to get to it. :raises: If there are cycles in the value, raises a - dbt.common.exceptions.RecursionError + dbt_common.exceptions.RecursionError """ try: return _deep_map_render(func, value, ()) diff --git a/dbt/common/utils/encoding.py b/dbt_common/utils/encoding.py similarity index 100% rename from dbt/common/utils/encoding.py rename to dbt_common/utils/encoding.py diff --git a/dbt/common/utils/executor.py b/dbt_common/utils/executor.py similarity index 100% rename from dbt/common/utils/executor.py rename to dbt_common/utils/executor.py diff --git a/dbt/common/utils/formatting.py b/dbt_common/utils/formatting.py similarity index 100% rename from dbt/common/utils/formatting.py rename to dbt_common/utils/formatting.py diff --git a/dbt/common/utils/jinja.py b/dbt_common/utils/jinja.py similarity index 94% rename from dbt/common/utils/jinja.py rename to dbt_common/utils/jinja.py index 59bba34e..36464cbe 100644 --- a/dbt/common/utils/jinja.py +++ b/dbt_common/utils/jinja.py @@ -1,4 +1,4 @@ -from dbt.common.exceptions import DbtInternalError +from dbt_common.exceptions import DbtInternalError MACRO_PREFIX = "dbt_macro__" diff --git a/pyproject.toml b/pyproject.toml index 74e760a0..7a893549 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,7 +55,7 @@ exclude = [ ] [tool.hatch.build.targets.wheel] -packages = ["dbt"] +packages = ["dbt_common"] [tool.hatch.envs.dev-env.scripts] all = ["pre-commit run --all-files"] diff --git a/tests/unit/test_agate_helper.py b/tests/unit/test_agate_helper.py index 9e63aa47..2384c13e 100644 --- a/tests/unit/test_agate_helper.py +++ b/tests/unit/test_agate_helper.py @@ -8,7 +8,7 @@ import os from shutil import rmtree from tempfile import mkdtemp -from dbt.common.clients import agate_helper +from dbt_common.clients import agate_helper SAMPLE_CSV_DATA = """a,b,c,d,e,f,g 1,n,test,3.2,20180806T11:33:29.320Z,True,NULL diff --git a/tests/unit/test_connection_retries.py b/tests/unit/test_connection_retries.py index c135696b..817af7a2 100644 --- a/tests/unit/test_connection_retries.py +++ b/tests/unit/test_connection_retries.py @@ -1,8 +1,8 @@ import functools import pytest from requests.exceptions import RequestException -from dbt.common.exceptions import ConnectionError -from dbt.common.utils.connection import connection_exception_retry +from dbt_common.exceptions import ConnectionError +from dbt_common.utils.connection import connection_exception_retry def no_retry_fn(): diff --git a/tests/unit/test_core_dbt_utils.py b/tests/unit/test_core_dbt_utils.py index b3957f90..55f8cc5e 100644 --- a/tests/unit/test_core_dbt_utils.py +++ b/tests/unit/test_core_dbt_utils.py @@ -2,8 +2,8 @@ import tarfile import unittest -from dbt.common.exceptions import ConnectionError -from dbt.common.utils.connection import connection_exception_retry +from dbt_common.exceptions import ConnectionError +from dbt_common.utils.connection import connection_exception_retry class TestCoreDbtUtils(unittest.TestCase): diff --git a/tests/unit/test_event_handler.py b/tests/unit/test_event_handler.py index 7067e3bf..80d5ae2b 100644 --- a/tests/unit/test_event_handler.py +++ b/tests/unit/test_event_handler.py @@ -1,8 +1,8 @@ import logging -from dbt.common.events.base_types import EventLevel -from dbt.common.events.event_handler import DbtEventLoggingHandler, set_package_logging -from dbt.common.events.event_manager import TestEventManager +from dbt_common.events.base_types import EventLevel +from dbt_common.events.event_handler import DbtEventLoggingHandler, set_package_logging +from dbt_common.events.event_manager import TestEventManager def test_event_logging_handler_emits_records_correctly(): diff --git a/tests/unit/test_helper_types.py b/tests/unit/test_helper_types.py index 59b05d90..17ebbd8e 100644 --- a/tests/unit/test_helper_types.py +++ b/tests/unit/test_helper_types.py @@ -1,7 +1,7 @@ import pytest -from dbt.common.helper_types import IncludeExclude, WarnErrorOptions -from dbt.common.dataclass_schema import ValidationError +from dbt_common.helper_types import IncludeExclude, WarnErrorOptions +from dbt_common.dataclass_schema import ValidationError class TestIncludeExclude: diff --git a/tests/unit/test_jinja.py b/tests/unit/test_jinja.py index 65520743..9e2ccc82 100644 --- a/tests/unit/test_jinja.py +++ b/tests/unit/test_jinja.py @@ -1,7 +1,7 @@ import unittest -from dbt.common.clients.jinja import extract_toplevel_blocks -from dbt.common.exceptions import CompilationError +from dbt_common.clients.jinja import extract_toplevel_blocks +from dbt_common.exceptions import CompilationError class TestBlockLexer(unittest.TestCase): diff --git a/tests/unit/test_model_config.py b/tests/unit/test_model_config.py index 2c746408..0cc1e711 100644 --- a/tests/unit/test_model_config.py +++ b/tests/unit/test_model_config.py @@ -1,8 +1,8 @@ from dataclasses import dataclass, field -from dbt.common.dataclass_schema import dbtClassMixin +from dbt_common.dataclass_schema import dbtClassMixin from typing import List, Dict -from dbt.common.contracts.config.metadata import ShowBehavior -from dbt.common.contracts.config.base import MergeBehavior, CompareBehavior +from dbt_common.contracts.config.metadata import ShowBehavior +from dbt_common.contracts.config.base import MergeBehavior, CompareBehavior @dataclass diff --git a/tests/unit/test_system_client.py b/tests/unit/test_system_client.py index c54b98d4..0fde4913 100644 --- a/tests/unit/test_system_client.py +++ b/tests/unit/test_system_client.py @@ -7,8 +7,8 @@ from pathlib import Path from tempfile import mkdtemp, NamedTemporaryFile -from dbt.common.exceptions import ExecutableError, WorkingDirectoryError -import dbt.common.clients.system +from dbt_common.exceptions import ExecutableError, WorkingDirectoryError +import dbt_common.clients.system class SystemClient(unittest.TestCase): @@ -33,20 +33,20 @@ def tearDown(self): def test__make_file_when_exists(self): self.set_up_profile() - written = dbt.common.clients.system.make_file(self.profiles_path, contents="NEW_TEXT") + written = dbt_common.clients.system.make_file(self.profiles_path, contents="NEW_TEXT") self.assertFalse(written) self.assertEqual(self.get_profile_text(), "ORIGINAL_TEXT") def test__make_file_when_not_exists(self): - written = dbt.common.clients.system.make_file(self.profiles_path, contents="NEW_TEXT") + written = dbt_common.clients.system.make_file(self.profiles_path, contents="NEW_TEXT") self.assertTrue(written) self.assertEqual(self.get_profile_text(), "NEW_TEXT") def test__make_file_with_overwrite(self): self.set_up_profile() - written = dbt.common.clients.system.make_file( + written = dbt_common.clients.system.make_file( self.profiles_path, contents="NEW_TEXT", overwrite=True ) @@ -55,12 +55,12 @@ def test__make_file_with_overwrite(self): def test__make_dir_from_str(self): test_dir_str = self.tmp_dir + "/test_make_from_str/sub_dir" - dbt.common.clients.system.make_directory(test_dir_str) + dbt_common.clients.system.make_directory(test_dir_str) self.assertTrue(Path(test_dir_str).is_dir()) def test__make_dir_from_pathobj(self): test_dir_pathobj = Path(self.tmp_dir + "/test_make_from_pathobj/sub_dir") - dbt.common.clients.system.make_directory(test_dir_pathobj) + dbt_common.clients.system.make_directory(test_dir_pathobj) self.assertTrue(test_dir_pathobj.is_dir()) @@ -91,7 +91,7 @@ def tearDown(self): def test__executable_does_not_exist(self): with self.assertRaises(ExecutableError) as exc: - dbt.common.clients.system.run_cmd(self.run_dir, [self.does_not_exist]) + dbt_common.clients.system.run_cmd(self.run_dir, [self.does_not_exist]) msg = str(exc.exception).lower() @@ -101,7 +101,7 @@ def test__executable_does_not_exist(self): def test__not_exe(self): with self.assertRaises(ExecutableError) as exc: - dbt.common.clients.system.run_cmd(self.run_dir, [self.empty_file]) + dbt_common.clients.system.run_cmd(self.run_dir, [self.empty_file]) msg = str(exc.exception).lower() if os.name == "nt": @@ -114,14 +114,14 @@ def test__not_exe(self): def test__cwd_does_not_exist(self): with self.assertRaises(WorkingDirectoryError) as exc: - dbt.common.clients.system.run_cmd(self.does_not_exist, self.exists_cmd) + dbt_common.clients.system.run_cmd(self.does_not_exist, self.exists_cmd) msg = str(exc.exception).lower() self.assertIn("does not exist", msg) self.assertIn(self.does_not_exist.lower(), msg) def test__cwd_not_directory(self): with self.assertRaises(WorkingDirectoryError) as exc: - dbt.common.clients.system.run_cmd(self.empty_file, self.exists_cmd) + dbt_common.clients.system.run_cmd(self.empty_file, self.exists_cmd) msg = str(exc.exception).lower() self.assertIn("not a directory", msg) @@ -139,14 +139,14 @@ def test__cwd_no_permissions(self): os.chmod(self.run_dir, stat.S_IRUSR) with self.assertRaises(WorkingDirectoryError) as exc: - dbt.common.clients.system.run_cmd(self.run_dir, self.exists_cmd) + dbt_common.clients.system.run_cmd(self.run_dir, self.exists_cmd) msg = str(exc.exception).lower() self.assertIn("permissions", msg) self.assertIn(self.run_dir.lower(), msg) def test__ok(self): - out, err = dbt.common.clients.system.run_cmd(self.run_dir, self.exists_cmd) + out, err = dbt_common.clients.system.run_cmd(self.run_dir, self.exists_cmd) self.assertEqual(out.strip(), b"hello") self.assertEqual(err.strip(), b"") @@ -160,7 +160,7 @@ def test_find_matching_lowercase_file_pattern(self): with NamedTemporaryFile(prefix="sql-files", suffix=".sql", dir=self.tempdir) as named_file: file_path = os.path.dirname(named_file.name) relative_path = os.path.basename(file_path) - out = dbt.common.clients.system.find_matching( + out = dbt_common.clients.system.find_matching( self.base_dir, [relative_path], "*.sql", @@ -179,7 +179,7 @@ def test_find_matching_uppercase_file_pattern(self): with NamedTemporaryFile(prefix="sql-files", suffix=".SQL", dir=self.tempdir) as named_file: file_path = os.path.dirname(named_file.name) relative_path = os.path.basename(file_path) - out = dbt.common.clients.system.find_matching(self.base_dir, [relative_path], "*.sql") + out = dbt_common.clients.system.find_matching(self.base_dir, [relative_path], "*.sql") expected_output = [ { "searched_path": relative_path, @@ -192,12 +192,12 @@ def test_find_matching_uppercase_file_pattern(self): def test_find_matching_file_pattern_not_found(self): with NamedTemporaryFile(prefix="sql-files", suffix=".SQLT", dir=self.tempdir): - out = dbt.common.clients.system.find_matching(self.tempdir, [""], "*.sql") + out = dbt_common.clients.system.find_matching(self.tempdir, [""], "*.sql") self.assertEqual(out, []) def test_ignore_spec(self): with NamedTemporaryFile(prefix="sql-files", suffix=".sql", dir=self.tempdir): - out = dbt.common.clients.system.find_matching( + out = dbt_common.clients.system.find_matching( self.tempdir, [""], "*.sql", @@ -240,7 +240,7 @@ def test_untar_package_success(self): # now we test can test that we can untar the file successfully assert tarfile.is_tarfile(tar.name) - dbt.common.clients.system.untar_package(tar_file_full_path, self.tempdest) + dbt_common.clients.system.untar_package(tar_file_full_path, self.tempdest) path = Path(os.path.join(self.tempdest, relative_file_a)) assert path.is_file() @@ -257,7 +257,7 @@ def test_untar_package_failure(self): # now that we're set up, test that untarring the file fails with self.assertRaises(tarfile.ReadError) as exc: # noqa: [F841] - dbt.common.clients.system.untar_package(tar_file_path, self.tempdest) + dbt_common.clients.system.untar_package(tar_file_path, self.tempdest) def test_untar_package_empty(self): # create a tarball with nothing in it @@ -267,5 +267,5 @@ def test_untar_package_empty(self): # make sure we throw an error for the empty file with self.assertRaises(tarfile.ReadError) as exc: - dbt.common.clients.system.untar_package(named_file.name, self.tempdest) + dbt_common.clients.system.untar_package(named_file.name, self.tempdest) self.assertEqual("empty file", str(exc.exception)) diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 7b153b33..ac4772d4 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -1,7 +1,7 @@ import unittest -import dbt.common.exceptions -import dbt.common.utils +import dbt_common.exceptions +import dbt_common.utils class TestDeepMerge(unittest.TestCase): @@ -16,7 +16,7 @@ def test__simple_cases(self): ] for case in cases: - actual = dbt.common.utils.deep_merge(*case["args"]) + actual = dbt_common.utils.deep_merge(*case["args"]) self.assertEqual( case["expected"], actual, @@ -38,7 +38,7 @@ def test__simple_cases(self): ] for case in cases: - actual = dbt.common.utils.deep_merge(*case["args"]) + actual = dbt_common.utils.deep_merge(*case["args"]) self.assertEqual( case["expected"], actual, @@ -91,10 +91,10 @@ def test__simple_cases(self): }, ], } - actual = dbt.common.utils.deep_map_render(self.intify_all, self.input_value) + actual = dbt_common.utils.deep_map_render(self.intify_all, self.input_value) self.assertEqual(actual, expected) - actual = dbt.common.utils.deep_map_render(self.intify_all, expected) + actual = dbt_common.utils.deep_map_render(self.intify_all, expected) self.assertEqual(actual, expected) @staticmethod @@ -123,21 +123,21 @@ def test__keypath(self): }, ], } - actual = dbt.common.utils.deep_map_render(self.special_keypath, self.input_value) + actual = dbt_common.utils.deep_map_render(self.special_keypath, self.input_value) self.assertEqual(actual, expected) - actual = dbt.common.utils.deep_map_render(self.special_keypath, expected) + actual = dbt_common.utils.deep_map_render(self.special_keypath, expected) self.assertEqual(actual, expected) def test__noop(self): - actual = dbt.common.utils.deep_map_render(lambda x, _: x, self.input_value) + actual = dbt_common.utils.deep_map_render(lambda x, _: x, self.input_value) self.assertEqual(actual, self.input_value) def test_trivial(self): cases = [[], {}, 1, "abc", None, True] for case in cases: - result = dbt.common.utils.deep_map_render(lambda x, _: x, case) + result = dbt_common.utils.deep_map_render(lambda x, _: x, case) self.assertEqual(result, case) - with self.assertRaises(dbt.common.exceptions.DbtConfigError): - dbt.common.utils.deep_map_render(lambda x, _: x, {"foo": object()}) + with self.assertRaises(dbt_common.exceptions.DbtConfigError): + dbt_common.utils.deep_map_render(lambda x, _: x, {"foo": object()})