mdbt 0.4.33__py3-none-any.whl → 0.4.36__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.
mdbt/ai_core.py CHANGED
@@ -16,7 +16,7 @@ from mdbt.prompts import Prompts
16
16
 
17
17
  class AiCore(Core):
18
18
 
19
- def __init__(self, model: str = "gpt-4.1", test_mode: bool = False):
19
+ def __init__(self, model: str = "gpt-5", test_mode: bool = False):
20
20
  super().__init__(test_mode=test_mode)
21
21
  self.model = model
22
22
  # Make sure you have OPENAI_API_KEY set in your environment variables.
mdbt/build_dbt_docs_ai.py CHANGED
@@ -19,9 +19,7 @@ class BuildDBTDocs(AiCore):
19
19
  def __init__(self):
20
20
  super().__init__()
21
21
 
22
- def main(self, model_name, sys_context, is_new=False):
23
- if model_name.endswith(".sql"):
24
- model_name = model_name[:-4]
22
+ def main(self, select, sys_context, is_new=False):
25
23
  if not is_new:
26
24
  print(
27
25
  """
@@ -33,80 +31,85 @@ class BuildDBTDocs(AiCore):
33
31
  else:
34
32
  mode = 1
35
33
  print("Getting file.")
36
- sql_file_path = self.get_file_path(model_name)
37
-
38
- if "l4" in sql_file_path.lower() or "l3" in sql_file_path.lower():
39
- system_instructions = Prompts().dbt_docs_gte_l3_prompt
40
- else:
41
- system_instructions = Prompts().dbt_docs_lte_l2_prompt
42
-
43
- if sys_context:
44
- system_instructions += f"\nContext about system docs are generated for: \n{sys_context}\n"
45
-
46
- sample_data = self._get_sample_data_from_snowflake([model_name])
47
-
48
- system_instructions = system_instructions + sample_data[model_name]
49
-
50
- # Might bring this back in the future.
51
- extra_info = ""
52
-
53
- if mode == 1:
54
- # Build new documentation
55
- user_input = self.build_user_msg_mode_1(sql_file_path, extra_info)
56
- yml_file_path = sql_file_path.replace(".sql", ".yml")
57
- elif mode == 2:
58
- # Check existing documentation
59
- yml_file_path = sql_file_path[:-4] + ".yml"
60
- user_input = self.build_user_msg_mode_2(
61
- sql_file_path, yml_file_path, extra_info
62
- )
63
- else:
64
- print(mode)
65
- raise ValueError("Invalid mode")
66
-
67
- messages = [
68
- {"role": "user", "content": system_instructions + "\n" + user_input}
69
- ]
70
-
71
- assistant_responses = []
72
- result = self.send_message(messages)
73
- assistant_responses.append(result)
74
-
75
- messages.append({"role": "assistant", "content": assistant_responses[0]})
76
- print(assistant_responses[0])
77
- output = assistant_responses[0]
78
- # Check for ``` at end of output (str) and remove
79
- # Remove trailing markdown code fences if present
80
- lines = output.split('\n')
81
- new_lines = []
82
- for line in lines:
83
- if '```' not in line:
84
- new_lines.append(line)
85
- output = '\n'.join(new_lines)
86
- if not is_new:
87
- clip_or_file = input(
88
- f"1. to copy to clipboard\n2, to write to file ({yml_file_path}\n:"
89
- )
90
- else:
91
- clip_or_file = "2"
92
-
93
- if clip_or_file == "1":
94
- print("Output copied to clipboard")
95
- pyperclip.copy(output)
96
- elif clip_or_file == "2":
97
- if mode == 2:
98
- # Make a backup of the current YML file.
99
- self.backup_existing_yml_file(yml_file_path)
100
- with open(yml_file_path, "w") as file:
101
- file.write(output)
102
- if not self.is_file_committed(yml_file_path):
103
- if not is_new:
104
- commit_file = input("Press 1 to add to git, any other key to byapss: ")
105
- else:
106
- commit_file = "1"
107
-
108
- if commit_file == "1":
109
- subprocess.run(["git", "add", yml_file_path])
34
+ models = self.get_models(select)
35
+ if not models:
36
+ raise ValueError(f"No models found for select '{select}'")
37
+
38
+ for model in models:
39
+ original_file_path = model["original_file_path"]
40
+ model_name = model["name"]
41
+ if "l4" in original_file_path.lower() or "l3" in original_file_path.lower():
42
+ system_instructions = Prompts().dbt_docs_gte_l3_prompt
43
+ else:
44
+ system_instructions = Prompts().dbt_docs_lte_l2_prompt
45
+
46
+ if sys_context:
47
+ system_instructions += f"\nContext about system docs are generated for: \n{sys_context}\n"
48
+
49
+ sample_data = self._get_sample_data_from_snowflake([model_name])
50
+
51
+ system_instructions = system_instructions + sample_data[model_name]
52
+
53
+ # Might bring this back in the future.
54
+ extra_info = ""
55
+
56
+ if mode == 1:
57
+ # Build new documentation
58
+ user_input = self.build_user_msg_mode_1(original_file_path, extra_info)
59
+ yml_file_path = original_file_path.replace(".sql", ".yml")
60
+ elif mode == 2:
61
+ # Check existing documentation
62
+ yml_file_path = original_file_path[:-4] + ".yml"
63
+ user_input = self.build_user_msg_mode_2(
64
+ original_file_path, yml_file_path, extra_info
65
+ )
66
+ else:
67
+ print(mode)
68
+ raise ValueError("Invalid mode")
69
+
70
+ messages = [
71
+ {"role": "user", "content": system_instructions + "\n" + user_input}
72
+ ]
73
+
74
+ assistant_responses = []
75
+ result = self.send_message(messages)
76
+ assistant_responses.append(result)
77
+
78
+ messages.append({"role": "assistant", "content": assistant_responses[0]})
79
+ print(assistant_responses[0])
80
+ output = assistant_responses[0]
81
+ # Check for ``` at end of output (str) and remove
82
+ # Remove trailing markdown code fences if present
83
+ lines = output.split('\n')
84
+ new_lines = []
85
+ for line in lines:
86
+ if '```' not in line:
87
+ new_lines.append(line)
88
+ output = '\n'.join(new_lines)
89
+ if not is_new:
90
+ clip_or_file = input(
91
+ f"1. to copy to clipboard\n2, to write to file ({yml_file_path}\n:"
92
+ )
93
+ else:
94
+ clip_or_file = "2"
95
+
96
+ if clip_or_file == "1":
97
+ print("Output copied to clipboard")
98
+ pyperclip.copy(output)
99
+ elif clip_or_file == "2":
100
+ if mode == 2:
101
+ # Make a backup of the current YML file.
102
+ self.backup_existing_yml_file(yml_file_path)
103
+ with open(yml_file_path, "w") as file:
104
+ file.write(output)
105
+ if not self.is_file_committed(yml_file_path):
106
+ if not is_new:
107
+ commit_file = input("Press 1 to add to git, any other key to byapss: ")
108
+ else:
109
+ commit_file = "1"
110
+
111
+ if commit_file == "1":
112
+ subprocess.run(["git", "add", yml_file_path])
110
113
 
111
114
  @staticmethod
112
115
  def backup_existing_yml_file(yml_file_path):
@@ -23,7 +23,7 @@ logging.getLogger("snowflake.connector").setLevel(logging.WARNING)
23
23
  class BuildUnitTestDataAI(AiCore):
24
24
 
25
25
  def __init__(self):
26
- super().__init__(model="o3-mini")
26
+ super().__init__(model="gpt-5")
27
27
 
28
28
  def main(self, model_name: str):
29
29
 
mdbt/core.py CHANGED
@@ -49,7 +49,7 @@ class Core:
49
49
  private_key=private_key,
50
50
  schema=os.getenv('MAIN__SCHEMA'),
51
51
  warehouse=os.getenv('MAIN__WAREHOUSE'),
52
- role=os.getenv('MAIN__ROLE'),
52
+ role='MDBT',
53
53
  )
54
54
 
55
55
  self._cur = self._conn.cursor()
@@ -122,3 +122,20 @@ class Core:
122
122
  print(e.stdout)
123
123
  raise Exception(f"Failure while running command: {' '.join(e.cmd)}")
124
124
  # sys.exit(e.returncode)
125
+
126
+ def get_models(self, select: str, all_files: bool = False) -> t.List[t.Dict[str, t.Any]]:
127
+ if not all_files:
128
+ args = [
129
+ "--select",
130
+ select,
131
+ "--exclude",
132
+ "resource_type:test resource_type:seed resource_type:snapshot resource_type:source",
133
+ ]
134
+ else:
135
+ args = [
136
+ "--exclude",
137
+ "resource_type:test resource_type:seed resource_type:snapshot resource_type:source",
138
+ ]
139
+ ls_json = self.dbt_ls_to_json(args)
140
+
141
+ return ls_json
mdbt/sort_yaml_fields.py CHANGED
@@ -35,7 +35,7 @@ class SortYAML(AiCore):
35
35
  all_files: Optional[bool] = False,
36
36
  overwrite: Optional[bool] = False,
37
37
  ):
38
- models = self._get_models(select, all_files)
38
+ models = self.get_models(select, all_files)
39
39
  if len(models) > 1 and not overwrite:
40
40
  raise ValueError(
41
41
  "Multiple models found. Default copy to clipboard only works with one model. Use the --overwrite flag "
@@ -66,23 +66,7 @@ class SortYAML(AiCore):
66
66
  else:
67
67
  self.save_yml_to_clipboard(updated_schema)
68
68
 
69
- def _get_models(self, select: str, all_files: bool) -> List[Dict[str, Any]]:
70
- mmw = MDBT()
71
- if not all_files:
72
- args = [
73
- "--select",
74
- select,
75
- "--exclude",
76
- "resource_type:test resource_type:seed resource_type:snapshot resource_type:source",
77
- ]
78
- else:
79
- args = [
80
- "--exclude",
81
- "resource_type:test resource_type:seed resource_type:snapshot resource_type:source",
82
- ]
83
- ls_json = mmw.dbt_ls_to_json(args)
84
-
85
- return ls_json
69
+
86
70
 
87
71
  @staticmethod
88
72
  def _get_schema_path_and_table(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mdbt
3
- Version: 0.4.33
3
+ Version: 0.4.36
4
4
  Summary: A CLI tool to manage dbt builds with state handling and manifest management
5
5
  Author: Craig Lathrop
6
6
  Author-email: info@markimicrowave.com
@@ -11,11 +11,11 @@ Requires-Python: >=3.9
11
11
  License-File: LICENSE
12
12
  Requires-Dist: click<9.0.0,>=8.0.0
13
13
  Requires-Dist: pyperclip<2.0.0,>=1.8.0
14
- Requires-Dist: snowflake-connector-python[pandas]<4.0.0,>=3.11.0
14
+ Requires-Dist: snowflake-connector-python[pandas]==3.18.0
15
15
  Requires-Dist: python-dotenv<1.2.0,>=1.0.0
16
- Requires-Dist: openai<2.0.0,>=1.35.0
17
- Requires-Dist: sqlfluff==3.4.0
18
- Requires-Dist: sqlfluff-templater-dbt==3.4.0
16
+ Requires-Dist: openai==2.6.1
17
+ Requires-Dist: sqlfluff==3.5.0
18
+ Requires-Dist: sqlfluff-templater-dbt==3.5.0
19
19
  Requires-Dist: wordninja==2.0.0
20
20
  Requires-Dist: ruamel.yaml<0.18.0
21
21
  Requires-Dist: recce<=0.44.3
@@ -1,20 +1,20 @@
1
1
  mdbt/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- mdbt/ai_core.py,sha256=diJFT35pGOEIQpUYOk6GFBgQgmK2sHj_F_kfkjeaEyQ,3963
3
- mdbt/build_dbt_docs_ai.py,sha256=ytTcZx43ulSpKivBpOR_3Q8mKRq9jkmdAW2vucL7enE,5041
4
- mdbt/build_unit_test_data_ai.py,sha256=OqJXDerhg54_QVIlVtXNxfk5TKVe68i6JnrV_8iEDrc,4292
2
+ mdbt/ai_core.py,sha256=EyuEciA6EIRfZ2vj4YxCLkdfmkke7tbZWPjBb_JOuNw,3961
3
+ mdbt/build_dbt_docs_ai.py,sha256=QMSxW0XzC4xPkx2HXgkkeZ0AiPri_PTS7oyUrOS6hQ8,5443
4
+ mdbt/build_unit_test_data_ai.py,sha256=SJlxEjwrH3zyXbZFLQFl3_BZYIM3WLdubA8eUEYRbQU,4290
5
5
  mdbt/cmdline.py,sha256=meNATu3BzP_4Htt5VcoT923mlh9NsfK8og0JQgn9PCE,10822
6
- mdbt/core.py,sha256=Y1K7ecJTZ9Bfkvk7Kk7-DRO1-QJs9GD6RP6m7sfQ-oY,4522
6
+ mdbt/core.py,sha256=XO6_KwMnVumtilj0OWZBcfPM7SwaUOba2lkw1apxx6w,5089
7
7
  mdbt/expectations_output_builder.py,sha256=AXKEM-WO7FecYzfMLwzsOnQnVf7AiHBi_khyidE2lJs,3195
8
8
  mdbt/lightdash.py,sha256=qJBJ-pc5mN8GBA1MZElRhtA8aldrX-AgvHtha4iOA-Y,2745
9
9
  mdbt/main.py,sha256=UO3r7zOXmVpjnAIz2eeZVeQMFmgXa698Gm42Wo2qhRU,16939
10
10
  mdbt/precommit_format.py,sha256=9HC10mh4QQIgaQSxdAwaCXbsiHT9cCrLdbc3PAQkotc,2845
11
11
  mdbt/prompts.py,sha256=2vCvh9hamgop92kGGaMKtap11F2MZiM7hHKjcwX4lhQ,13992
12
12
  mdbt/recce.py,sha256=P14CvWd7lRgTPUW7BVMLmcclSqby-_uSgpoI3r5VjTA,2327
13
- mdbt/sort_yaml_fields.py,sha256=1PROsrz8KubSr0bVmPq3oAw4V-eSiZh1uGRR5B-uaA4,5648
13
+ mdbt/sort_yaml_fields.py,sha256=QF-zwXgeZ4iuaV3CfLxz4w30EqC7y34uBuowO4DbYUA,5057
14
14
  mdbt/sql_sorter.py,sha256=8bd6svrtcXp7ePT2g4FTGLTW55qbsVjXgUmba7L-G-4,6467
15
- mdbt-0.4.33.dist-info/licenses/LICENSE,sha256=DrJpgQEYhttwpwcE56BzrGZ1aEfR_tqfaxsI5NlsYOE,1072
16
- mdbt-0.4.33.dist-info/METADATA,sha256=f_RoFgFRNmgFlYf2la7dwGK52Jcxhp0zZYdHPF2v5jU,920
17
- mdbt-0.4.33.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
18
- mdbt-0.4.33.dist-info/entry_points.txt,sha256=fVft1CYVP2MtZMMtsXN67S1T5RszfgKtAuaeoKLdCow,43
19
- mdbt-0.4.33.dist-info/top_level.txt,sha256=-PP7vAl9EgVjRTzBovElczsPNjOfja6kjZssNmv5vo0,5
20
- mdbt-0.4.33.dist-info/RECORD,,
15
+ mdbt-0.4.36.dist-info/licenses/LICENSE,sha256=DrJpgQEYhttwpwcE56BzrGZ1aEfR_tqfaxsI5NlsYOE,1072
16
+ mdbt-0.4.36.dist-info/METADATA,sha256=hmQdzRJl5BpH3rRyNtowpe-GZ5UmJD9AYRbhoj8eQps,905
17
+ mdbt-0.4.36.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
18
+ mdbt-0.4.36.dist-info/entry_points.txt,sha256=fVft1CYVP2MtZMMtsXN67S1T5RszfgKtAuaeoKLdCow,43
19
+ mdbt-0.4.36.dist-info/top_level.txt,sha256=-PP7vAl9EgVjRTzBovElczsPNjOfja6kjZssNmv5vo0,5
20
+ mdbt-0.4.36.dist-info/RECORD,,
File without changes