Skip to content

Commit

Permalink
Merge pull request #34 from dbt-labs/feature/improve-logging-and-display
Browse files Browse the repository at this point in the history
[Feature] Improve logging and display of information
  • Loading branch information
b-per authored Dec 9, 2022
2 parents df5e2bd + 8c7bb9e commit fc8ae1b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ requests==2.28.1
tomli==2.0.1
typing_extensions==4.4.0
urllib3==1.26.12
croniter==1.3.7
croniter==1.3.7
rich==12.6.0
27 changes: 23 additions & 4 deletions src/changeset/change_set.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from typing import Optional
from pydantic import BaseModel
import string
from rich.table import Table


class Change(BaseModel):
"""Describes what a given change is and hot to apply it."""

identifier: str
type: str
action: str
Expand All @@ -20,21 +22,38 @@ def apply(self):

class ChangeSet(BaseModel):
"""Store the set of changes to be displayed or applied."""

__root__: Optional[list[Change]] = []

def __iter__(self):
return iter(self.__root__)

def append(self, change: Change):
self.__root__.append(change)

def __str__(self):
list_str = [str(change) for change in self.__root__]
return "\n".join(list_str)


def to_table(self) -> Table:
"""Return a table representation of the changeset."""

table = Table(title="Changes detected")

table.add_column("Action", style="cyan", no_wrap=True)
table.add_column("Type", style="magenta")
table.add_column("ID", style="green")

for change in self.__root__:
table.add_row(
change.action.upper(), string.capwords(change.type), change.identifier
)

return table

def __len__(self):
return len(self.__root__)

def apply(self):
for change in self.__root__:
change.apply()
change.apply()
13 changes: 8 additions & 5 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from schemas import check_job_mapping_same
from changeset.change_set import Change, ChangeSet
from schemas import check_env_var_same
from rich.console import Console


def build_change_set(config):
Expand Down Expand Up @@ -68,7 +69,7 @@ def build_change_set(config):
dbt_cloud_change_set.append(dbt_cloud_change)

# Remove Deleted Jobs
logger.warning("Detected {count} deleted jobs.", count=len(deleted_jobs))
logger.info("Detected {count} deleted jobs.", count=len(deleted_jobs))
for identifier in deleted_jobs:
dbt_cloud_change = Change(
identifier=identifier,
Expand Down Expand Up @@ -183,8 +184,9 @@ def sync(config):
if len(change_set) == 0:
logger.success("-- PLAN -- No changes detected.")
else:
logger.warning("-- PLAN -- {count} changes detected.", count=len(change_set))
print(change_set)
logger.info("-- PLAN -- {count} changes detected.", count=len(change_set))
console = Console()
console.log(change_set.to_table())
logger.info("-- SYNC --")
change_set.apply()

Expand All @@ -200,8 +202,9 @@ def plan(config):
if len(change_set) == 0:
logger.success("-- PLAN -- No changes detected.")
else:
logger.warning("-- PLAN -- {count} changes detected.", count=len(change_set))
print(change_set)
logger.info("-- PLAN -- {count} changes detected.", count=len(change_set))
console = Console()
console.log(change_set.to_table())


@cli.command()
Expand Down
4 changes: 2 additions & 2 deletions src/schemas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def check_job_mapping_same(source_job: JobDefinition, dest_job: JobDefinition) -
logger.success("✅ Jobs identical")
return True
else:
logger.warning(f"❌ Jobs are different - Diff: {diffs}")
logger.info(f"❌ Jobs are different - Diff: {diffs}")
return False


Expand All @@ -58,5 +58,5 @@ def check_env_var_same(source_env_var: CustomEnvironmentVariable, dest_env_vars:
)
return (True, env_var_id)
else:
logger.warning(f"❌ The env var overwrite for {source_env_var.name} is different")
logger.info(f"❌ The env var overwrite for {source_env_var.name} is different")
return (False, env_var_id)

0 comments on commit fc8ae1b

Please sign in to comment.