-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4374f88
commit 5c23660
Showing
2 changed files
with
32 additions
and
82 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,35 +1,21 @@ | ||
import click | ||
import os | ||
import sys | ||
from dbt.cli.main import dbtRunner | ||
from dbt.config.runtime import load_profile, load_project | ||
|
||
from dbt.cli import dbt_cli | ||
from dbt.cli.context import make_context | ||
from dbt.adapters.factory import adapter_management | ||
from dbt.profiler import profiler | ||
from dbt.config.runtime import load_project | ||
|
||
# python core/dbt/cli/example.py deps --project-dir <project-dir-path> | ||
# python core/dbt/cli/example.py run --project-dir <project-dir-path> | ||
if __name__ == "__main__": | ||
project_dir = "/Users/chenyuli/git/jaffle_shop" | ||
# Bypass cli group context configuration entirely and invoke deps directly | ||
cli_args = ["run", "--project-dir", project_dir] | ||
|
||
# currently this would not construct params properly | ||
# Use cli group to configure context + call arbitrary command | ||
# ctx = make_context(cli_args) | ||
# if ctx: | ||
# dbt.invoke(ctx) | ||
# initialize the dbt runner | ||
dbt = dbtRunner() | ||
# run the command | ||
res, success = dbt.invoke(cli_args) | ||
|
||
# Bypass cli group context configuration entirely and invoke deps directly | ||
# Note: This only really works because of the prior global initializations (logging, tracking) from dbt.invoke(ctx) | ||
input_args = sys.argv[1:] | ||
# we are not supporting --version, --help in this example for now. | ||
command = input_args[0] | ||
cli_args = input_args[1:] | ||
click.echo(f"\n`dbt {command}` called") | ||
ctx = make_context(cli_args, dbt_cli.commands[command]) | ||
assert ctx is not None | ||
# preload profile and project | ||
profile = load_profile(project_dir, {}, "testing-postgres") | ||
project = load_project(project_dir, False, profile, {}) | ||
|
||
ctx.with_resource(adapter_management()) | ||
ctx.with_resource(profiler(enable=True, outfile="output.profile")) | ||
project_dir = os.path.expanduser(ctx.params.get("project_dir")) # type: ignore | ||
ctx.obj["project"] = load_project(project_dir, True, None, None) # type: ignore | ||
dbt_cli.commands[command].invoke(ctx) | ||
# initialize the runner with pre-loaded profile and project, you can also pass in a preloaded manifest | ||
dbt = dbtRunner(profile=profile, project=project) | ||
# run the command, this will use the pre-loaded profile and project instead of loading | ||
res, success = dbt.invoke(cli_args) |
This file contains 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