dbt-contracts 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dbt_contracts/__init__.py +12 -0
- dbt_contracts/cli.py +146 -0
- dbt_contracts/contracts/__init__.py +12 -0
- dbt_contracts/contracts/_core.py +688 -0
- dbt_contracts/contracts/_node.py +325 -0
- dbt_contracts/contracts/_properties.py +210 -0
- dbt_contracts/contracts/column.py +349 -0
- dbt_contracts/contracts/macro.py +65 -0
- dbt_contracts/contracts/model.py +47 -0
- dbt_contracts/contracts/source.py +80 -0
- dbt_contracts/dbt_cli.py +165 -0
- dbt_contracts/formatters/__init__.py +4 -0
- dbt_contracts/formatters/_core.py +58 -0
- dbt_contracts/formatters/table.py +208 -0
- dbt_contracts/main.py +34 -0
- dbt_contracts/result.py +355 -0
- dbt_contracts/runner.py +388 -0
- dbt_contracts/types.py +13 -0
- dbt_contracts-0.1.0.dist-info/METADATA +228 -0
- dbt_contracts-0.1.0.dist-info/RECORD +23 -0
- dbt_contracts-0.1.0.dist-info/WHEEL +4 -0
- dbt_contracts-0.1.0.dist-info/entry_points.txt +6 -0
- dbt_contracts-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""Welcome to dbt-contracts"""
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
PROGRAM_NAME = "dbt-contracts"
|
|
5
|
+
PROGRAM_OWNER_NAME = "George Martin Marino"
|
|
6
|
+
PROGRAM_OWNER_USER = "geo-martino"
|
|
7
|
+
PROGRAM_OWNER_EMAIL = f"gm.engineer+{PROGRAM_NAME.lower()}@pm.me"
|
|
8
|
+
PROGRAM_URL = f"https://github.com/{PROGRAM_OWNER_USER}/{PROGRAM_NAME.lower()}"
|
|
9
|
+
DOCUMENTATION_URL = f"https://{PROGRAM_OWNER_USER}.github.io/{PROGRAM_NAME.lower()}"
|
|
10
|
+
|
|
11
|
+
MODULE_ROOT: str = Path(__file__).parent.name
|
|
12
|
+
PACKAGE_ROOT: Path = Path(__file__).parent.parent
|
dbt_contracts/cli.py
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
from dbt.cli.resolvers import default_profiles_dir, default_project_dir
|
|
5
|
+
|
|
6
|
+
from dbt_contracts import PROGRAM_NAME
|
|
7
|
+
from dbt_contracts.contracts import CONTRACTS, ParentContract
|
|
8
|
+
|
|
9
|
+
DEFAULT_CONFIG_FILE_NAME: str = "contracts.yml"
|
|
10
|
+
DEFAULT_OUTPUT_FILE_NAME: str = "contracts_results"
|
|
11
|
+
|
|
12
|
+
CORE_PARSER = argparse.ArgumentParser(
|
|
13
|
+
prog=PROGRAM_NAME,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
################################################################################
|
|
17
|
+
## DBT args
|
|
18
|
+
################################################################################
|
|
19
|
+
profiles_dir = CORE_PARSER.add_argument(
|
|
20
|
+
"--profiles-dir",
|
|
21
|
+
help="Which directory to look in for the profiles.yml file. "
|
|
22
|
+
"If not set, dbt will look in the current working directory first, then HOME/.dbt/",
|
|
23
|
+
nargs="?",
|
|
24
|
+
default=os.getenv("DBT_PROFILES_DIR", default_profiles_dir()),
|
|
25
|
+
type=str,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
project_dir = CORE_PARSER.add_argument(
|
|
29
|
+
"--project-dir",
|
|
30
|
+
help="Which directory to look in for the dbt_project.yml file. "
|
|
31
|
+
"Default is the current working directory and its parents.",
|
|
32
|
+
nargs="?",
|
|
33
|
+
default=os.getenv("DBT_PROJECT_DIR", default_project_dir()),
|
|
34
|
+
type=str,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
profile = CORE_PARSER.add_argument(
|
|
38
|
+
"--profile",
|
|
39
|
+
help="Which existing profile to load. Overrides setting in dbt_project.yml.",
|
|
40
|
+
nargs="?",
|
|
41
|
+
default=os.getenv("DBT_PROFILE"),
|
|
42
|
+
type=str,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
target = CORE_PARSER.add_argument(
|
|
46
|
+
"--target",
|
|
47
|
+
"-t",
|
|
48
|
+
help="Which target to load for the given profile",
|
|
49
|
+
nargs="?",
|
|
50
|
+
default=os.getenv("DBT_TARGET"),
|
|
51
|
+
type=str,
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
threads = CORE_PARSER.add_argument(
|
|
55
|
+
"--threads",
|
|
56
|
+
help="Specify number of threads to use while executing models. Overrides settings in profiles.yml.",
|
|
57
|
+
nargs="?",
|
|
58
|
+
default=None,
|
|
59
|
+
type=int,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
################################################################################
|
|
63
|
+
## DBT commands
|
|
64
|
+
################################################################################
|
|
65
|
+
clean = CORE_PARSER.add_argument(
|
|
66
|
+
"--clean",
|
|
67
|
+
help="When this option is passed, run `dbt clean` before operations. "
|
|
68
|
+
"If not passed, will attempt to load artifacts from the target folder before operations.",
|
|
69
|
+
action='store_true'
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
install_deps = CORE_PARSER.add_argument(
|
|
73
|
+
"--deps",
|
|
74
|
+
help="When this option is passed, run `dbt deps` before operations.",
|
|
75
|
+
action='store_true'
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
################################################################################
|
|
79
|
+
## Runner args
|
|
80
|
+
################################################################################
|
|
81
|
+
config = CORE_PARSER.add_argument(
|
|
82
|
+
"--config",
|
|
83
|
+
help="Either the path to a contracts configuration file, "
|
|
84
|
+
f"or the directory to look in for the {DEFAULT_CONFIG_FILE_NAME!r} file. "
|
|
85
|
+
"Defaults to the project dir when not specified.",
|
|
86
|
+
nargs="?",
|
|
87
|
+
default=None,
|
|
88
|
+
type=str,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
output = CORE_PARSER.add_argument(
|
|
92
|
+
"--output",
|
|
93
|
+
help="Either the path to a file to write to when formatting results output, "
|
|
94
|
+
f"or the directory to write a file to with filename {DEFAULT_OUTPUT_FILE_NAME!r}. "
|
|
95
|
+
"Defaults to the project's target folder when not specified.",
|
|
96
|
+
nargs="?",
|
|
97
|
+
default=None,
|
|
98
|
+
type=str,
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
output_format = CORE_PARSER.add_argument(
|
|
102
|
+
"--format",
|
|
103
|
+
help="Specify the format of results output if desired. Output file will not be generated when not specified.",
|
|
104
|
+
nargs="?",
|
|
105
|
+
default=None,
|
|
106
|
+
choices=["text", "json", "jsonl", "github-annotations"],
|
|
107
|
+
type=str,
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
no_fail = CORE_PARSER.add_argument(
|
|
111
|
+
"--no-fail",
|
|
112
|
+
help="When this option is passed, do not fail when contracts do not pass.",
|
|
113
|
+
action='store_true'
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
contract = CORE_PARSER.add_argument(
|
|
117
|
+
"--contract",
|
|
118
|
+
help="Run only this contract. If none given, apply all configured contracts. "
|
|
119
|
+
"Specify granular contracts by separating keys by a '.' e.g. 'model', 'model.columns'",
|
|
120
|
+
nargs="?",
|
|
121
|
+
default=None,
|
|
122
|
+
choices=[
|
|
123
|
+
str(contract.config_key) for contract in CONTRACTS
|
|
124
|
+
] + [
|
|
125
|
+
f"{contract.config_key}.{contract.child_type.config_key}"
|
|
126
|
+
for contract in CONTRACTS if issubclass(contract, ParentContract)
|
|
127
|
+
],
|
|
128
|
+
type=str,
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
enforcements = CORE_PARSER.add_argument(
|
|
132
|
+
"--enforce",
|
|
133
|
+
help="Apply only these enforcements. If none given, apply all configured enforcements.",
|
|
134
|
+
nargs="+",
|
|
135
|
+
default=None,
|
|
136
|
+
type=str,
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
files = CORE_PARSER.add_argument(
|
|
140
|
+
"files",
|
|
141
|
+
help="Apply contract to only these files. "
|
|
142
|
+
"Must either be relative to the current folder, relative to the project folder, or absolute.",
|
|
143
|
+
nargs="*",
|
|
144
|
+
default=None,
|
|
145
|
+
type=str,
|
|
146
|
+
)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Implementations for dbt contracts according to the dbt object type.
|
|
3
|
+
"""
|
|
4
|
+
from ._core import Contract, ParentContract, ChildContract, ProcessorMethod
|
|
5
|
+
from ._properties import PatchT, MetaT, TagT
|
|
6
|
+
from ._node import NodeT, NodeContract, CompiledNodeT, CompiledNodeContract
|
|
7
|
+
from .macro import MacroContract
|
|
8
|
+
from .model import ModelContract
|
|
9
|
+
from .source import SourceContract
|
|
10
|
+
|
|
11
|
+
CONTRACTS: list[type[ParentContract]] = [ModelContract, SourceContract, MacroContract]
|
|
12
|
+
CONTRACTS_CONFIG_MAP = {str(cls.config_key): cls for cls in CONTRACTS}
|