-
Notifications
You must be signed in to change notification settings - Fork 13
Remove dbt-core dependency #81
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
Merged
jochemvandooren
merged 12 commits into
master
from
jvandooren/remove-dbt-core-dependency
Oct 31, 2024
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
867ddd6
WIP Get rid of dbt-core dependency
jochemvandooren 82ad0a1
WIP Format
jochemvandooren 6fc1f68
Add changelog entry
jochemvandooren 98b4680
Add tests
jochemvandooren c00266e
Update CHANGELOG.md
jochemvandooren a48823d
Fix formatting
jochemvandooren b4b4a57
Add dbt-core as dev dependency and drop MultiOption selection
jochemvandooren 9b7fea6
Improve documentation
jochemvandooren 2ca9c98
Add dbt check as decorator
jochemvandooren 7573a93
Update docs/get_started.md
jochemvandooren 4dc8f93
Update docs/get_started.md
jochemvandooren 271dfbc
Improve wrapper
jochemvandooren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,18 @@ | |
import contextlib | ||
import os | ||
from pathlib import Path | ||
from typing import Iterable, Iterator, cast | ||
from typing import Any, Callable, Iterable, Iterator, cast | ||
|
||
from dbt.cli.main import dbtRunner, dbtRunnerResult | ||
# Conditionally import dbt objects. | ||
try: | ||
DBT_INSTALLED = True | ||
from dbt.cli.main import dbtRunner, dbtRunnerResult # type: ignore | ||
except ImportError: | ||
DBT_INSTALLED = False | ||
|
||
|
||
class DbtNotInstalledException(Exception): | ||
"""Raised when trying to run dbt when dbt is not installed.""" | ||
|
||
|
||
class DbtParseException(Exception): | ||
|
@@ -16,13 +25,27 @@ class DbtLsException(Exception): | |
"""Raised when dbt ls fails.""" | ||
|
||
|
||
def dbt_required(func: Callable[..., Any]) -> Callable[..., Any]: | ||
"""Decorator for methods that require dbt to be installed.""" | ||
|
||
def inner() -> None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can use https://docs.python.org/3/library/functools.html#functools.wraps to preserve docstrings, names etc of the original function 👌 |
||
if not DBT_INSTALLED: | ||
raise DbtNotInstalledException( | ||
"This option requires dbt to be installed in the same Python" | ||
"environment as dbt-score." | ||
) | ||
|
||
return inner | ||
|
||
|
||
@contextlib.contextmanager | ||
def _disable_dbt_stdout() -> Iterator[None]: | ||
with contextlib.redirect_stdout(None): | ||
yield | ||
|
||
|
||
def dbt_parse() -> dbtRunnerResult: | ||
@dbt_required | ||
def dbt_parse() -> "dbtRunnerResult": | ||
"""Parse a dbt project. | ||
|
||
Returns: | ||
|
@@ -32,22 +55,23 @@ def dbt_parse() -> dbtRunnerResult: | |
DbtParseException: dbt parse failed. | ||
""" | ||
with _disable_dbt_stdout(): | ||
result: dbtRunnerResult = dbtRunner().invoke(["parse"]) | ||
result: "dbtRunnerResult" = dbtRunner().invoke(["parse"]) | ||
|
||
if not result.success: | ||
raise DbtParseException("dbt parse failed.") from result.exception | ||
|
||
return result | ||
|
||
|
||
@dbt_required | ||
def dbt_ls(select: Iterable[str] | None) -> Iterable[str]: | ||
"""Run dbt ls.""" | ||
cmd = ["ls", "--resource-type", "model", "--output", "name"] | ||
if select: | ||
cmd += ["--select", *select] | ||
|
||
with _disable_dbt_stdout(): | ||
result: dbtRunnerResult = dbtRunner().invoke(cmd) | ||
result: "dbtRunnerResult" = dbtRunner().invoke(cmd) | ||
|
||
if not result.success: | ||
raise DbtLsException("dbt ls failed.") from result.exception | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.