Ejemplo n.º 1
0
def get_project(git_path):
    phony_profile = Profile.from_raw_profiles(raw_profiles=PHONY_PROFILE,
                                              profile_name='hubcap',
                                              renderer=ProfileRenderer({}))

    ctx = generate_target_context(phony_profile, cli_vars={})
    renderer = DbtProjectYamlRenderer(ctx)
    return Project.from_project_root(git_path, renderer)
Ejemplo n.º 2
0
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,
    )
Ejemplo n.º 3
0
    def _choose_target_name(self, profile_name: str):
        has_raw_profile = (self.raw_profile_data is not None
                           and profile_name in self.raw_profile_data)

        if not has_raw_profile:
            return None

        # mypy appeasement, we checked just above
        assert self.raw_profile_data is not None
        raw_profile = self.raw_profile_data[profile_name]

        renderer = ProfileRenderer(generate_base_context(self.cli_vars))

        target_name, _ = Profile.render_profile(raw_profile=raw_profile,
                                                profile_name=profile_name,
                                                target_override=getattr(
                                                    self.args, 'target', None),
                                                renderer=renderer)
        return target_name
Ejemplo n.º 4
0
 def validate_connection(cls, target_dict):
     """Validate a connection dictionary. On error, raises a DbtConfigError.
     """
     target_name = 'test'
     # make a fake profile that we can parse
     profile_data = {
         'outputs': {
             target_name: target_dict,
         },
     }
     # this will raise a DbtConfigError on failure
     profile = Profile.from_raw_profile_info(
         raw_profile=profile_data,
         profile_name='',
         target_override=target_name,
         renderer=ProfileRenderer(generate_base_context({})),
     )
     result = cls.attempt_connection(profile)
     if result is not None:
         raise dbt.exceptions.DbtProfileError(
             result, result_type='connection_failure')
Ejemplo n.º 5
0
    def _load_profile(self):
        if not os.path.exists(self.profile_path):
            self.profile_fail_details = FILE_NOT_FOUND
            self.messages.append(MISSING_PROFILE_MESSAGE.format(
                path=self.profile_path, url=ProfileConfigDocs
            ))
            return red('ERROR not found')

        try:
            raw_profile_data = load_yaml_text(
                dbt.clients.system.load_file_contents(self.profile_path)
            )
        except Exception:
            pass  # we'll report this when we try to load the profile for real
        else:
            if isinstance(raw_profile_data, dict):
                self.raw_profile_data = raw_profile_data

        profile_errors = []
        profile_names = self._choose_profile_names()
        renderer = ProfileRenderer(generate_base_context(self.cli_vars))
        for profile_name in profile_names:
            try:
                profile: Profile = QueryCommentedProfile.render_from_args(
                    self.args, renderer, profile_name
                )
            except dbt.exceptions.DbtConfigError as exc:
                profile_errors.append(str(exc))
            else:
                if len(profile_names) == 1:
                    # if a profile was specified, set it on the task
                    self.target_name = self._choose_target_name(profile_name)
                    self.profile = profile

        if profile_errors:
            self.profile_fail_details = '\n\n'.join(profile_errors)
            return red('ERROR invalid')
        return green('OK found and valid')
Ejemplo n.º 6
0
 def profile_renderer(self) -> ProfileRenderer:
     """Return a ProfileRenderer with this config's parsed vars."""
     profile_renderer = ProfileRenderer(self.parsed_vars)
     return profile_renderer