Skip to content

Commit 80a3663

Browse files
committed
feat: improve api for chaining manifest/node transformers
1 parent 2118803 commit 80a3663

File tree

6 files changed

+206
-49
lines changed

6 files changed

+206
-49
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "dbt-osmosis"
7-
version = "1.1.5"
7+
version = "1.1.6"
88
description = "A dbt utility for managing YAML to make developing with dbt more delightful."
99
readme = "README.md"
1010
license = { text = "Apache-2.0" }

src/dbt_osmosis/cli/main.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
YamlRefactorContext,
1515
YamlRefactorSettings,
1616
apply_restructure_plan,
17-
commit_yamls,
1817
compile_sql_code,
1918
create_dbt_project_context,
2019
create_missing_source_yamls,
@@ -26,7 +25,6 @@
2625
inject_missing_columns,
2726
remove_columns_not_in_database,
2827
sort_columns_as_configured,
29-
sync_node_to_yaml,
3028
synchronize_data_types,
3129
synthesize_missing_documentation_with_openai,
3230
)
@@ -264,15 +262,18 @@ def refactor(
264262
apply_restructure_plan(
265263
context=context, plan=draft_restructure_delta_plan(context), confirm=not auto_apply
266264
)
267-
inject_missing_columns(context=context)
268-
remove_columns_not_in_database(context=context)
269-
inherit_upstream_column_knowledge(context=context)
270-
sort_columns_as_configured(context=context)
271-
synchronize_data_types(context=context)
265+
266+
transform = (
267+
inject_missing_columns
268+
>> remove_columns_not_in_database
269+
>> inherit_upstream_column_knowledge
270+
>> sort_columns_as_configured
271+
>> synchronize_data_types
272+
)
272273
if synthesize:
273-
synthesize_missing_documentation_with_openai(context=context)
274-
sync_node_to_yaml(context=context)
275-
commit_yamls(context=context)
274+
transform >>= synthesize_missing_documentation_with_openai
275+
276+
_ = transform(context=context)
276277

277278
if check and context.mutated:
278279
exit(1)
@@ -396,11 +397,6 @@ def organize(
396397
is_flag=True,
397398
help="Output yaml file columns and data types in lowercase if possible.",
398399
)
399-
@click.option(
400-
"--auto-apply",
401-
is_flag=True,
402-
help="Automatically apply the restructure plan without confirmation.",
403-
)
404400
@click.option(
405401
"--synthesize",
406402
is_flag=True,
@@ -442,13 +438,13 @@ def document(
442438
if vars:
443439
settings.vars = context.yaml_handler.load(io.StringIO(vars)) # pyright: ignore[reportUnknownMemberType]
444440

445-
inject_missing_columns(context=context)
446-
inherit_upstream_column_knowledge(context=context)
447-
sort_columns_as_configured(context=context)
441+
transform = (
442+
inject_missing_columns >> inherit_upstream_column_knowledge >> sort_columns_as_configured
443+
)
448444
if synthesize:
449-
synthesize_missing_documentation_with_openai(context=context)
450-
sync_node_to_yaml(context=context)
451-
commit_yamls(context=context)
445+
transform >>= synthesize_missing_documentation_with_openai
446+
447+
_ = transform(context=context)
452448

453449
if check and context.mutated:
454450
exit(1)
@@ -548,10 +544,14 @@ def run(
548544
project_dir: str | None = None,
549545
profiles_dir: str | None = None,
550546
target: str | None = None,
547+
**kwargs: t.Any,
551548
) -> None:
552549
"""Executes a dbt SQL statement writing results to stdout"""
553550
settings = DbtConfiguration(
554-
project_dir=t.cast(str, project_dir), profiles_dir=t.cast(str, profiles_dir), target=target
551+
project_dir=t.cast(str, project_dir),
552+
profiles_dir=t.cast(str, profiles_dir),
553+
target=target,
554+
**kwargs,
555555
)
556556
project = create_dbt_project_context(settings)
557557
_, table = execute_sql_code(project, sql)
@@ -574,10 +574,14 @@ def compile(
574574
project_dir: str | None = None,
575575
profiles_dir: str | None = None,
576576
target: str | None = None,
577+
**kwargs: t.Any,
577578
) -> None:
578579
"""Executes a dbt SQL statement writing results to stdout"""
579580
settings = DbtConfiguration(
580-
project_dir=t.cast(str, project_dir), profiles_dir=t.cast(str, profiles_dir), target=target
581+
project_dir=t.cast(str, project_dir),
582+
profiles_dir=t.cast(str, profiles_dir),
583+
target=target,
584+
**kwargs,
581585
)
582586
project = create_dbt_project_context(settings)
583587
node = compile_sql_code(project, sql)

src/dbt_osmosis/core/logger.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from logging.handlers import RotatingFileHandler
1010
from pathlib import Path
1111

12+
import rich
1213
from rich.logging import RichHandler
1314

1415
_LOG_FILE_FORMAT = "%(asctime)s — %(name)s — %(levelname)s — %(message)s"
@@ -57,6 +58,7 @@ def get_logger(
5758
logger.addHandler(
5859
RichHandler(
5960
level=level,
61+
console=rich.console.Console(stderr=True),
6062
rich_tracebacks=True,
6163
markup=True,
6264
show_time=False,

0 commit comments

Comments
 (0)