forked from dbt-checkpoint/dbt-checkpoint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbt_run.py
54 lines (45 loc) · 1.25 KB
/
dbt_run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import argparse
import os
import time
from typing import Any, Dict, List, Optional, Sequence
from dbt_checkpoint.utils import (
add_dbt_cmd_args,
add_dbt_cmd_model_args,
add_filenames_args,
get_flags,
paths_to_dbt_models,
run_dbt_cmd,
)
def prepare_cmd(
paths: Sequence[str],
global_flags: Optional[Sequence[str]] = None,
cmd_flags: Optional[Sequence[str]] = None,
prefix: str = "",
postfix: str = "",
models: Optional[Sequence[str]] = None,
) -> List[str]:
global_flags = get_flags(global_flags)
cmd_flags = get_flags(cmd_flags)
if models:
dbt_models = models
else:
dbt_models = paths_to_dbt_models(paths, prefix, postfix)
cmd = ["dbt", *global_flags, "run", "-m", *dbt_models, *cmd_flags]
return cmd
def main(argv: Optional[Sequence[str]] = None) -> int:
parser = argparse.ArgumentParser()
add_filenames_args(parser)
add_dbt_cmd_args(parser)
add_dbt_cmd_model_args(parser)
args = parser.parse_args(argv)
cmd = prepare_cmd(
args.filenames,
args.global_flags,
args.cmd_flags,
args.model_prefix,
args.model_postfix,
args.models,
)
return run_dbt_cmd(cmd)
if __name__ == "__main__":
exit(main())