Skip to content

Commit

Permalink
Modify to support dbt-core 1.6 and above (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
syou6162 authored May 17, 2024
1 parent e4962bf commit eadaff3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 56 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ repository = "https://github.com/z3z1ma/dbt-osmosis"
[tool.poetry.dependencies]
python = ">=3.8,<3.9.7 || >3.9.7,<3.12"
click = ">7"
dbt-core = ">=1"
dbt-core = ">=1.6,<1.9"
"ruamel.yaml" = ">=0.17"
rich = ">=10"
GitPython = ">3,<4"
Expand Down
60 changes: 5 additions & 55 deletions src/dbt_osmosis/vendored/dbt_core_interface/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,14 @@
from dbt.adapters.factory import get_adapter_class_by_name
from dbt.clients.system import make_directory
from dbt.config.runtime import RuntimeConfig
from dbt.contracts.graph.nodes import ColumnInfo, ManifestNode
from dbt.flags import set_from_args
from dbt.node_types import NodeType
from dbt.parser.manifest import PARTIAL_PARSE_FILE_NAME, ManifestLoader, process_node
from dbt.parser.sql import SqlBlockParser, SqlMacroParser
from dbt.task.sql import SqlCompileRunner
from dbt.tracking import disable_tracking

# brute force import for dbt 1.3 back-compat
# these are here for consumers of dbt-core-interface
try:
# dbt <= 1.3
from dbt.contracts.graph.compiled import ManifestNode # type: ignore
from dbt.contracts.graph.parsed import ColumnInfo # type: ignore
except Exception:
# dbt > 1.3
from dbt.contracts.graph.nodes import ColumnInfo, ManifestNode # type: ignore

if TYPE_CHECKING:
# These imports are only used for type checking
from agate import Table # type: ignore # No stubs for agate
Expand All @@ -119,22 +110,8 @@

urlunquote = functools.partial(urlunquote, encoding="latin1")

# Version specific dbt constants and overrides
__dbt_major_version__ = int(dbt.version.installed.major or 0)
__dbt_minor_version__ = int(dbt.version.installed.minor or 0)
__dbt_patch_version__ = int(dbt.version.installed.patch or 0)
if (__dbt_major_version__, __dbt_minor_version__, __dbt_patch_version__) > (1, 3, 0):
RAW_CODE = "raw_code"
COMPILED_CODE = "compiled_code"
else:
RAW_CODE = "raw_code"
COMPILED_CODE = "compiled_code"
if (__dbt_major_version__, __dbt_minor_version__, __dbt_patch_version__) < (1, 5, 0):
import dbt.events.functions

# I expect a change in dbt 1.5.0 that may make this monkey patch unnecessary
# but we can reduce the codepath since dbt is **loaded** with telemetry calls...
dbt.events.functions.fire_event = lambda *args, **kwargs: None
RAW_CODE = "raw_code"
COMPILED_CODE = "compiled_code"


def default_project_dir() -> Path:
Expand Down Expand Up @@ -173,22 +150,13 @@ def write_manifest_for_partial_parse(self: ManifestLoader):
raise


if (__dbt_major_version__, __dbt_minor_version__) < (1, 4):
# Patched so we write partial parse to correct directory
# https://github.com/dbt-labs/dbt-core/blob/v1.3.2/core/dbt/parser/manifest.py#L548
ManifestLoader.write_manifest_for_partial_parse = write_manifest_for_partial_parse


__all__ = [
"DbtProject",
"DbtProjectContainer",
"DbtAdapterExecutionResult",
"DbtAdapterCompilationResult",
"DbtManifestProxy",
"DbtConfiguration",
"__dbt_major_version__",
"__dbt_minor_version__",
"__dbt_patch_version__",
"DEFAULT_PROFILES_DIR",
"DEFAULT_PROJECT_DIR",
"ServerRunResult",
Expand Down Expand Up @@ -268,12 +236,8 @@ def vars(self, v: Union[str, Dict[str, Any]]) -> None:
If dict then it will be converted to a string which is what dbt expects.
"""
if (__dbt_major_version__, __dbt_minor_version__) >= (1, 5):
if isinstance(v, str):
v = yaml.safe_load(v)
else:
if isinstance(v, dict):
v = yaml.dump(v)
if isinstance(v, str):
v = yaml.safe_load(v)
self._vars = v


Expand Down Expand Up @@ -1161,20 +1125,6 @@ def _cli_parse(args): # pragma: no coverage
return cli_args, parser


def _cli_patch(cli_args): # pragma: no coverage
parsed_args, _ = _cli_parse(cli_args)
opts = parsed_args
if opts.server:
if opts.server.startswith("gevent"):
import gevent.monkey

gevent.monkey.patch_all()
elif opts.server.startswith("eventlet"):
import eventlet

eventlet.monkey_patch()


py = sys.version_info
py3k = py.major > 2

Expand Down

0 comments on commit eadaff3

Please sign in to comment.