Skip to content

Commit

Permalink
Remove unnecessary logging
Browse files Browse the repository at this point in the history
  • Loading branch information
PJUllrich committed Dec 15, 2023
1 parent 914ed8a commit f5b1199
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 42 deletions.
26 changes: 0 additions & 26 deletions dbt_coves/config/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Holds config for dbt-coves."""

import os
from pathlib import Path
from typing import Any, Dict, List, Optional

Expand All @@ -11,10 +10,6 @@
from dbt_coves.utils.log import LOGGER as logger
from dbt_coves.utils.yaml import open_yaml

from rich.console import Console

console = Console()


class GeneratePropertiesModel(BaseModel):
templates_folder: Optional[str] = ".dbt_coves/templates"
Expand Down Expand Up @@ -148,9 +143,6 @@ class RunDbtModel(BaseModel):
command: Optional[str] = ""
project_dir: Optional[str] = ""
virtualenv: Optional[str] = ""
upload_manifest: Optional[bool] = False
upload_manifest_url: Optional[str] = ""
upload_manifest_token: Optional[str] = ""
cleanup: Optional[bool] = False


Expand Down Expand Up @@ -228,7 +220,6 @@ class DbtCovesConfig:
"dbt.project_dir",
"dbt.virtualenv",
"dbt.cleanup",
"dbt.upload_manifest",
"extract.fivetran.path",
"extract.fivetran.api_key",
"extract.fivetran.api_secret",
Expand All @@ -255,26 +246,14 @@ def __init__(self, flags: DbtCovesFlags) -> None:
self._flags = flags
self._task = self._flags.task
self._config_path = self._flags.config_path
console.print(self._config_path)
self._config = ConfigModel()

@property
def integrated(self):
"""
Returns the values read from the config file plus the overrides from cli flags
"""
console.print(self._config_path)
config_path = Path().joinpath(self.DBT_COVES_CONFIG_FILEPATH)
apath = os.path.abspath(config_path)
cwd = os.getcwd()
console.print(
f"Integrated: Loading config at abs: {apath} relative: {config_path} cwd: {cwd} File exists? {config_path.exists()}"
)
config_copy = self._config.dict()
files = os.listdir()
files.sort()
for file in files:
console.print(file)

for value in self.CLI_OVERRIDE_FLAGS:
path_items = value.split(".")
Expand Down Expand Up @@ -306,14 +285,10 @@ def validate_dbt_project(self):

def locate_config(self) -> None:
# If path is relative to cwd
console.print("Loading the config")
if self._config_path == Path(str()):
logger.debug("Trying to find .dbt_coves in current folder")

config_path = Path().joinpath(self.DBT_COVES_CONFIG_FILEPATH)
console.print(
f"Looking for the config.yml at {config_path}. File exists? {config_path.exists()}"
)
logger.info(
f"Looking for the config.yml at {config_path}. File exists? {config_path.exists()}"
)
Expand All @@ -324,7 +299,6 @@ def locate_config(self) -> None:

def load_config(self) -> None:
is_project_valid = self.validate_dbt_project()
console.print(f"is_project_valid: {is_project_valid}")
if is_project_valid:
self.locate_config()
else:
Expand Down
1 change: 0 additions & 1 deletion dbt_coves/core/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ def handle(parser: argparse.ArgumentParser, cli_args: List[str] = list()) -> int
DbtCovesTraceback(main_parser)

coves_config = None
console.print(f"Task needs config: {task_cls.needs_config}")
if task_cls.needs_config:
coves_config = DbtCovesConfig(main_parser)
coves_config.load_config()
Expand Down
30 changes: 15 additions & 15 deletions dbt_coves/tasks/dbt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,9 @@ def run_dbt(self, args: list, cwd: str):

if self.get_env("DATACOVES__UPLOAD_MANIFEST") in ["True", "true", True]:
console.print("Upload manifest enabled. Uploading...")
print("print: Upload manifest enabled. Uploading...")
self.upload_manifest(cwd=cwd)
else:
console.print("Upload manifest disabled. Skipping.")
print("print: Upload manifest disabled. Skipping.")

def is_readonly(self, folder: str) -> bool:
"""Returns True if `folder` is readonly"""
Expand All @@ -127,28 +125,24 @@ def upload_manifest(self, cwd):
manifest_path = os.path.join(cwd, "target/manifest.json")

if os.path.isfile(manifest_path):
url = self.get_env("DATACOVES__UPLOAD_MANIFEST_URL")
bearer_token = self.get_env("DATACOVES__UPLOAD_MANIFEST_TOKEN")
env_slug = self.get_env("DATACOVES__ENVIRONMENT_SLUG")
url = self.get_env("DATACOVES__UPLOAD_MANIFEST_URL")
run_id = self.get_env("AIRFLOW_CTX_DAG_RUN_ID")

if not url:
console.print("[red]No dbt upload_manifest_url specified[/red].")
print("print: [red]No dbt upload_manifest_url specified[/red].")
return 0
return 1

if not bearer_token:
console.print("[red]No dbt upload_manifest_token specified[/red].")
print("print: [red]No dbt upload_manifest_token specified[/red].")
return 0
return 1

if not env_slug:
console.print("[red]No dbt env_slug specified[/red].")
print("print: [red]No dbt env_slug specified[/red].")
return 0
return 1

console.print(f"Uploading manifest for DAGRun {run_id} in Environment {env_slug}")
print(f"print: Uploading manifest for DAGRun {run_id} in Environment {env_slug}")

with open(manifest_path, "r") as file:
contents = file.read()
Expand All @@ -158,11 +152,17 @@ def upload_manifest(self, cwd):
"run_id": run_id,
}
files = {"file": contents}
req = requests.post(url, headers=headers, data=payload, files=files)
console.print(req.status_code)
print(req.status_code)
console.print(req.content)
print(req.content)
req = requests.post(url, headers=headers, data=payload, files=files, timeout=5.0)

if req.status_code == 200:
return 0
else:
console.print(
f"[red] Uploading the manifest failed with {req.status_code} [red]"
)
console.print(req.content)
return 1

else:
console.print("Upload manifest enabled but no manifest.json found. Skipping.")

Expand Down

0 comments on commit f5b1199

Please sign in to comment.