# Path: clouddq/utils.py
# def assert_not_none_or_empty(value: typing.Any, error_msg: str) -> None:
#     """
# 
#     Args:
#       value: typing.Any:
#       error_msg: str:
# 
#     Returns:
# 
#     """
#     if not value:
#         raise ValueError(error_msg)
# 
# Path: clouddq/utils.py
# def load_yaml(file_path: Path, key: str = None) -> typing.Any:
#     with file_path.open() as f:
#         yaml_configs = yaml.safe_load(f)
#     if not yaml_configs:
#         return dict()
#     output = yaml_configs.get(key, dict())
#     if type(output) == dict:
#         return {key.upper(): value for key, value in output.items()}
#     elif type(output) == list:
#         return [item.upper() for item in output]
#     elif type(output) == str:
#         return output
#     else:
#         raise RuntimeError(
#             f"CloudDQ configs file `{file_path}` has empty config node type `{key}:`. "
#             "Please remove the node if it is not being used."
#         )
# 
# Path: clouddq/utils.py
# @contextlib.contextmanager
# def working_directory(path):
#     """Changes working directory and returns to previous on exit."""
#     prev_cwd = Path.cwd()
#     os.chdir(path)
#     try:
#         yield
#     finally:
#         os.chdir(prev_cwd)


from pathlib import Path
from pprint import pformat
from typing import Dict
from typing import Optional
from dbt.main import main as dbt
from clouddq.utils import assert_not_none_or_empty
from clouddq.utils import load_yaml
from clouddq.utils import working_directory
import json
import logging
import os
import re
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.






logger = logging.getLogger(__name__)

ENV_VAR_PATTERN = re.compile(r".*env_var\((.+?)\).*", re.IGNORECASE)


def run_dbt(
    dbt_path: Path,
    dbt_profile_dir: Path,
    configs: Optional[Dict] = None,
    environment: str = "clouddq",
    debug: bool = False,
    dry_run: bool = False,

# Path: clouddq/utils.py
# def assert_not_none_or_empty(value: typing.Any, error_msg: str) -> None:
#     """
# 
#     Args:
#       value: typing.Any:
#       error_msg: str:
# 
#     Returns:
# 
#     """
#     if not value:
#         raise ValueError(error_msg)
# 
# Path: clouddq/utils.py
# def load_yaml(file_path: Path, key: str = None) -> typing.Any:
#     with file_path.open() as f:
#         yaml_configs = yaml.safe_load(f)
#     if not yaml_configs:
#         return dict()
#     output = yaml_configs.get(key, dict())
#     if type(output) == dict:
#         return {key.upper(): value for key, value in output.items()}
#     elif type(output) == list:
#         return [item.upper() for item in output]
#     elif type(output) == str:
#         return output
#     else:
#         raise RuntimeError(
#             f"CloudDQ configs file `{file_path}` has empty config node type `{key}:`. "
#             "Please remove the node if it is not being used."
#         )
# 
# Path: clouddq/utils.py
# @contextlib.contextmanager
# def working_directory(path):
#     """Changes working directory and returns to previous on exit."""
#     prev_cwd = Path.cwd()
#     os.chdir(path)
#     try:
#         yield
#     finally:
#         os.chdir(prev_cwd)


# Path: clouddq/runners/dbt/dbt_utils.py
from pathlib import Path
from pprint import pformat
from typing import Dict
from typing import Optional
from dbt.main import main as dbt
from clouddq.utils import assert_not_none_or_empty
from clouddq.utils import load_yaml
from clouddq.utils import working_directory
import json
import logging
import os
import re

#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.






logger = logging.getLogger(__name__)

ENV_VAR_PATTERN = re.compile(r".*env_var\((.+?)\).*", re.IGNORECASE)


def run_dbt(
    dbt_path: Path,
    dbt_profile_dir: Path,
    configs: Optional[Dict] = None,
    environment: str = "clouddq",
    debug: bool = False,
    dry_run: bool = False,

) -> None: