def __init__(self, args, config): super().__init__(args, config) self.profiles_dir = getattr(self.args, 'profiles_dir', PROFILES_DIR) self.profile_path = os.path.join(self.profiles_dir, 'profiles.yml') try: self.project_dir = get_nearest_project_dir(self.args) except dbt.exceptions.Exception: # we probably couldn't find a project directory. Set project dir # to whatever was given, or default to the current directory. if args.project_dir: self.project_dir = args.project_dir else: self.project_dir = os.getcwd() self.project_path = os.path.join(self.project_dir, 'dbt_project.yml') self.cli_vars = parse_cli_vars(getattr(self.args, 'vars', '{}')) # set by _load_* self.profile: Optional[Profile] = None self.profile_fail_details = '' self.raw_profile_data: Optional[Dict[str, Any]] = None self.profile_name: Optional[str] = None self.project: Optional[Project] = None self.project_fail_details = '' self.any_failure = False self.messages: List[str] = []
def profile_from_dict(profile, profile_name, cli_vars='{}'): from dbt.config import Profile from dbt.config.renderer import ProfileRenderer from dbt.context.base import generate_base_context from dbt.config.utils import parse_cli_vars if not isinstance(cli_vars, dict): cli_vars = parse_cli_vars(cli_vars) renderer = ProfileRenderer(generate_base_context(cli_vars)) return Profile.from_raw_profile_info( profile, profile_name, renderer, )
def project_from_dict(project, profile, packages=None, selectors=None, cli_vars='{}'): from dbt.context.target import generate_target_context from dbt.config import Project from dbt.config.renderer import DbtProjectYamlRenderer from dbt.config.utils import parse_cli_vars if not isinstance(cli_vars, dict): cli_vars = parse_cli_vars(cli_vars) renderer = DbtProjectYamlRenderer(generate_target_context(profile, cli_vars)) project_root = project.pop('project-root', os.getcwd()) return Project.render_from_dict( project_root, project, packages, selectors, renderer )
def handle_request(self) -> Result: if self.real_task is None: raise InternalException( 'CLI task is in a bad state: handle_request called with no ' 'real_task set!') # It's important to update cli_vars here, because set_config()'s # `self.config` is before the fork(), so it would alter the behavior of # future calls. # read any cli vars we got and use it to update cli_vars self.config.cli_vars.update( parse_cli_vars(getattr(self.args, 'vars', '{}'))) # If this changed the vars, rewrite args.vars to reflect our merged # vars and reload the manifest. dumped = yaml.safe_dump(self.config.cli_vars) if dumped != self.args.vars: self.real_task.args.vars = dumped if isinstance(self.real_task, RemoteManifestMethod): self.real_task.manifest = get_full_manifest(self.config, reset=True) # we parsed args from the cli, so we're set on that front return self.real_task.handle_request()
def _get_kwargs(self) -> Dict[str, Any]: return parse_cli_vars(self.args.args)