Skip to content

Commit 54c2b3a

Browse files
committed
Update package
1 parent 8674168 commit 54c2b3a

File tree

9 files changed

+132
-81
lines changed

9 files changed

+132
-81
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ dev = [
1313
"pre-commit>=4.0.1",
1414
"pygments>=2.18.0",
1515
"ruff>=0.8.1",
16+
"python-dotenv>=1.0.1",
1617
]
1718

1819
[tool.uv.workspace]

text_2_sql/semantic_kernel/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ dev = [
1616
"jupyter>=1.1.1",
1717
"pre-commit>=4.0.1",
1818
"pygments>=2.18.0",
19-
"python-dotenv>=1.0.1",
2019
"ruff>=0.8.1",
20+
"python-dotenv>=1.0.1",
2121
]
2222

2323
[tool.uv.sources]

text_2_sql/text_2_sql_core/pyproject.toml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,25 @@ dependencies = [
2323
"typer>=0.14.0",
2424
]
2525

26+
[dependency-groups]
27+
dev = [
28+
"black>=24.10.0",
29+
"ipykernel>=6.29.5",
30+
"jupyter>=1.1.1",
31+
"pre-commit>=4.0.1",
32+
"pygments>=2.18.0",
33+
"ruff>=0.8.1",
34+
"python-dotenv>=1.0.1",
35+
]
36+
2637
[project.optional-dependencies]
2738
snowflake = [
2839
"snowflake-connector-python>=3.12.3",
2940
]
3041
databricks = [
31-
"databricks>=0.2",
42+
"databricks-sql-connector>=3.0.1",
3243
]
3344

3445
[build-system]
3546
requires = ["hatchling"]
3647
build-backend = "hatchling.build"
37-
38-
[dependency-groups]
39-
dev = [
40-
"python-dotenv>=1.0.1",
41-
]

text_2_sql/text_2_sql_core/src/text_2_sql_core/data_dictionary/cli.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,14 @@
11
import asyncio
2-
from importlib import metadata
32
from pathlib import Path
43
from typing import Annotated
54
from text_2_sql_core.utils.database import DatabaseEngine
6-
5+
import logging
76
import typer
87
from rich import print as rich_print
98

10-
cli = typer.Typer(pretty_exceptions_show_locals=False, no_args_is_help=True)
11-
12-
__version__ = metadata.version(__package__)
13-
9+
logging.basicConfig(level=logging.INFO)
1410

15-
def version_callback(value: bool) -> None:
16-
"""Print the version of the CLI."""
17-
if value:
18-
print(__version__)
19-
raise typer.Exit()
20-
21-
22-
@cli.callback()
23-
def callback(
24-
_: bool = typer.Option(None, "--version", "-v", callback=version_callback)
25-
) -> None:
26-
"""Text2SQL Data Dictionary Creator CLI."""
11+
cli = typer.Typer(pretty_exceptions_show_locals=False, no_args_is_help=True)
2712

2813

2914
@cli.command()
@@ -71,20 +56,27 @@ def create(
7156
DatabricksDataDictionaryCreator,
7257
)
7358

74-
data_dictionary_creator = DatabricksDataDictionaryCreator()
59+
data_dictionary_creator = DatabricksDataDictionaryCreator(
60+
single_file=single_file, output_directory=output_directory
61+
)
7562
elif engine == DatabaseEngine.SNOWFLAKE:
7663
from text_2_sql_core.data_dictionary.snowflake_data_dictionary_creator import (
7764
SnowflakeDataDictionaryCreator,
7865
)
7966

80-
data_dictionary_creator = SnowflakeDataDictionaryCreator()
67+
data_dictionary_creator = SnowflakeDataDictionaryCreator(
68+
single_file=single_file, output_directory=output_directory
69+
)
8170
elif engine == DatabaseEngine.TSQL:
8271
from text_2_sql_core.data_dictionary.tsql_data_dictionary_creator import (
8372
TSQLDataDictionaryCreator,
8473
)
8574

86-
data_dictionary_creator = TSQLDataDictionaryCreator()
87-
except ImportError:
75+
data_dictionary_creator = TSQLDataDictionaryCreator(
76+
single_file=single_file, output_directory=output_directory
77+
)
78+
except ImportError as e:
79+
print(e)
8880
detailed_error = f"""Failed to import {
8981
engine.value} Data Dictionary Creator. Check you have installed the optional dependencies for this database engine."""
9082
rich_print("Text2SQL Data Dictionary Creator Failed ❌")
@@ -102,3 +94,7 @@ def create(
10294
raise typer.Exit(code=1)
10395
else:
10496
rich_print("Text2SQL Data Dictionary Creator Completed Successfully ✅")
97+
98+
99+
if __name__ == "__main__":
100+
cli()

text_2_sql/text_2_sql_core/src/text_2_sql_core/data_dictionary/data_dictionary_creator.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ def __init__(
166166
excluded_schemas: list[str] = None,
167167
single_file: bool = False,
168168
generate_definitions: bool = True,
169+
output_directory: str = None,
169170
):
170171
"""A method to initialize the DataDictionaryCreator class.
171172
@@ -177,6 +178,9 @@ def __init__(
177178
generate_definitions (bool, optional): A flag to indicate if definitions should be generated. Defaults to True.
178179
"""
179180

181+
if excluded_entities is None:
182+
excluded_entities = []
183+
180184
self.entities = entities
181185
self.excluded_entities = excluded_entities
182186
self.excluded_schemas = excluded_schemas
@@ -192,6 +196,9 @@ def __init__(
192196

193197
self.database_engine = None
194198

199+
if output_directory is None:
200+
self.output_directory = "."
201+
195202
load_dotenv(find_dotenv())
196203

197204
@property
@@ -677,7 +684,9 @@ async def create_data_dictionary(self):
677684
# Save data dictionary to file
678685
if self.single_file:
679686
logging.info("Saving data dictionary to entities.json")
680-
with open("entities.json", "w", encoding="utf-8") as f:
687+
with open(
688+
f"{self.output_directory}/entities.json", "w", encoding="utf-8"
689+
) as f:
681690
data_dictionary_dump = [
682691
entity.model_dump(
683692
by_alias=True, exclude=self.excluded_fields_for_database_engine
@@ -693,7 +702,11 @@ async def create_data_dictionary(self):
693702
else:
694703
for entity in data_dictionary:
695704
logging.info(f"Saving data dictionary for {entity.entity}")
696-
with open(f"{entity.entity}.json", "w", encoding="utf-8") as f:
705+
with open(
706+
f"{self.output_directory}/{entity.entity}.json",
707+
"w",
708+
encoding="utf-8",
709+
) as f:
697710
json.dump(
698711
entity.model_dump(
699712
by_alias=True,

text_2_sql/text_2_sql_core/src/text_2_sql_core/data_dictionary/databricks_data_dictionary_creator.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,11 @@
99

1010

1111
class DatabricksDataDictionaryCreator(DataDictionaryCreator):
12-
def __init__(
13-
self,
14-
entities: list[str] = None,
15-
excluded_entities: list[str] = None,
16-
single_file: bool = False,
17-
):
18-
"""A method to initialize the DataDictionaryCreator class.
12+
def __init__(self, **kwargs):
13+
"""A method to initialize the DataDictionaryCreator class."""
1914

20-
Args:
21-
entities (list[str], optional): A list of entities to extract. Defaults to None. If None, all entities are extracted.
22-
excluded_entities (list[str], optional): A list of entities to exclude. Defaults to None.
23-
single_file (bool, optional): A flag to indicate if the data dictionary should be saved to a single file. Defaults to False.
24-
"""
25-
if excluded_entities is None:
26-
excluded_entities = []
27-
28-
excluded_schemas = []
29-
super().__init__(entities, excluded_entities, excluded_schemas, single_file)
15+
excluded_schemas = ["INFORMATION_SCHEMA"]
16+
super().__init__(excluded_schemas=excluded_schemas, **kwargs)
3017

3118
self.catalog = os.environ["Text2Sql__Databricks__Catalog"]
3219
self.database_engine = DatabaseEngine.DATABRICKS

text_2_sql/text_2_sql_core/src/text_2_sql_core/data_dictionary/snowflake_data_dictionary_creator.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,11 @@
1010

1111

1212
class SnowflakeDataDictionaryCreator(DataDictionaryCreator):
13-
def __init__(
14-
self,
15-
entities: list[str] = None,
16-
excluded_entities: list[str] = None,
17-
single_file: bool = False,
18-
):
19-
"""A method to initialize the DataDictionaryCreator class.
20-
21-
Args:
22-
entities (list[str], optional): A list of entities to extract. Defaults to None. If None, all entities are extracted.
23-
excluded_entities (list[str], optional): A list of entities to exclude. Defaults to None.
24-
single_file (bool, optional): A flag to indicate if the data dictionary should be saved to a single file. Defaults to False.
25-
"""
26-
if excluded_entities is None:
27-
excluded_entities = []
13+
def __init__(self, **kwargs):
14+
"""A method to initialize the DataDictionaryCreator class."""
2815

2916
excluded_schemas = ["INFORMATION_SCHEMA"]
30-
super().__init__(entities, excluded_entities, excluded_schemas, single_file)
17+
super().__init__(excluded_schemas=excluded_schemas, **kwargs)
3118

3219
self.database = os.environ["Text2Sql__DatabaseName"]
3320
self.warehouse = os.environ["Text2Sql__Snowflake__Warehouse"]

text_2_sql/text_2_sql_core/src/text_2_sql_core/data_dictionary/tsql_data_dictionary_creator.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,16 @@
77

88

99
class TSQLDataDictionaryCreator(DataDictionaryCreator):
10-
def __init__(
11-
self,
12-
entities: list[str] = None,
13-
excluded_entities: list[str] = None,
14-
single_file: bool = False,
15-
):
10+
def __init__(self, **kwargs):
1611
"""A method to initialize the DataDictionaryCreator class.
1712
1813
Args:
1914
entities (list[str], optional): A list of entities to extract. Defaults to None. If None, all entities are extracted.
2015
excluded_entities (list[str], optional): A list of entities to exclude. Defaults to None.
2116
single_file (bool, optional): A flag to indicate if the data dictionary should be saved to a single file. Defaults to False.
2217
"""
23-
if excluded_entities is None:
24-
excluded_entities = []
25-
2618
excluded_schemas = ["dbo", "sys"]
27-
super().__init__(entities, excluded_entities, excluded_schemas, single_file)
19+
super().__init__(excluded_schemas=excluded_schemas, **kwargs)
2820
self.database = os.environ["Text2Sql__DatabaseName"]
2921

3022
self.database_engine = DatabaseEngine.TSQL

0 commit comments

Comments
 (0)