コード例 #1
0
def run_from_args(parsed):
    log_cache_events(getattr(parsed, 'log_cache_events', False))
    flags.set_from_args(parsed)

    parsed.cls.pre_init_hook(parsed)
    # we can now use the logger for stdout

    logger.info("Running with dbt{}".format(dbt.version.installed))

    # this will convert DbtConfigErrors into RuntimeExceptions
    task = parsed.cls.from_args(args=parsed)
    logger.debug("running dbt with arguments {parsed}", parsed=str(parsed))

    log_path = None
    if task.config is not None:
        log_path = getattr(task.config, 'log_path', None)
    # we can finally set the file logger up
    log_manager.set_path(log_path)
    if dbt.tracking.active_user is not None:  # mypy appeasement, always true
        logger.debug("Tracking: {}".format(dbt.tracking.active_user.state()))

    results = None

    with track_run(task):
        results = task.run()

    return task, results
コード例 #2
0
ファイル: dbt.py プロジェクト: tomasfarias/airflow-dbt-python
    def create_runtime_config(
        self, extra_targets: Optional[dict[str, Any]]
    ) -> Optional[RuntimeConfig]:
        """Crete a dbt RuntimeConfig, if possible.

        If the given task's ConfigType is not RuntimeConfig, None will be returned
        instead.
        Flags are also initialized as configuration is created.

        Args:
            extra_targets: Additional targets for a dbt project's Profile.

        Returns:
            A RuntimeConfig instance.
        """
        project, profile = self.create_dbt_project_and_profile(extra_targets)
        initialize_from_flags()
        self.cls.set_log_format()
        flags.set_from_args(self, profile.user_config)

        cfg_type = self.dbt_task.ConfigType

        if issubclass(cfg_type, RuntimeConfig):
            return cfg_type.from_parts(project=project, profile=profile, args=self)
        return None
コード例 #3
0
 def dbt_config(self):
     """Loads the dbt config."""
     if self.dbt_version_tuple >= (1, 0):
         # Here, we read flags.PROFILE_DIR directly, prior to calling
         # set_from_args(). Apparently, set_from_args() sets PROFILES_DIR
         # to a lowercase version of the value, and the profile wouldn't be
         # found if the directory name contained uppercase letters. This fix
         # was suggested and described here:
         # https://github.com/sqlfluff/sqlfluff/issues/2253#issuecomment-1018722979
         user_config = read_user_config(flags.PROFILES_DIR)
         flags.set_from_args(
             DbtConfigArgs(
                 project_dir=self.project_dir,
                 profiles_dir=self.profiles_dir,
                 profile=self._get_profile(),
                 vars=self._get_cli_vars(),
             ),
             user_config,
         )
     self.dbt_config = DbtRuntimeConfig.from_args(
         DbtConfigArgs(
             project_dir=self.project_dir,
             profiles_dir=self.profiles_dir,
             profile=self._get_profile(),
             target=self._get_target(),
             vars=self._get_cli_vars(),
         )
     )
     register_adapter(self.dbt_config)
     return self.dbt_config
コード例 #4
0
def _nt_setup(config, args):
    """
    On windows, we have to do a some things that dbt does dynamically at
    process load.

    These things are inherited automatically on posix, where fork() keeps
    everything in memory.
    """
    # reset flags
    flags.set_from_args(args)
    # reload the active plugin
    load_plugin(config.credentials.type)

    # reset tracking, etc
    config.config.set_values(args.profiles_dir)
コード例 #5
0
ファイル: main.py プロジェクト: insurancezebra/dbt-core
def run_from_args(parsed):
    log_cache_events(getattr(parsed, 'log_cache_events', False))
    flags.set_from_args(parsed)

    parsed.cls.pre_init_hook()
    logger.info("Running with dbt{}".format(dbt.version.installed))

    # this will convert DbtConfigErrors into RuntimeExceptions
    task = parsed.cls.from_args(args=parsed)
    logger.debug("running dbt with arguments %s", parsed)

    log_path = None
    if task.config is not None:
        log_path = getattr(task.config, 'log_path', None)
    initialize_logger(parsed.debug, log_path)
    logger.debug("Tracking: {}".format(dbt.tracking.active_user.state()))

    results = None

    with track_run(task):
        results = task.run()

    return task, results