Example #1
0
    def run(self) -> CatalogResults:
        compile_results = None
        if self.args.compile:
            compile_results = CompileTask.run(self)
            if any(r.error is not None for r in compile_results):
                dbt.ui.printer.print_timestamped_line(
                    'compile failed, cannot generate docs')
                return CatalogResults(nodes={},
                                      sources={},
                                      generated_at=datetime.utcnow(),
                                      errors=None,
                                      _compile_results=compile_results)
        else:
            self.manifest = get_full_manifest(self.config)

        shutil.copyfile(DOCS_INDEX_FILE_PATH,
                        os.path.join(self.config.target_path, 'index.html'))

        if self.manifest is None:
            raise InternalException('self.manifest was None in run!')

        adapter = get_adapter(self.config)
        with adapter.connection_named('generate_catalog'):
            dbt.ui.printer.print_timestamped_line("Building catalog")
            catalog_table, exceptions = adapter.get_catalog(self.manifest)

        catalog_data: List[PrimitiveDict] = [
            dict(zip(catalog_table.column_names, map(_coerce_decimal, row)))
            for row in catalog_table
        ]

        catalog = Catalog(catalog_data)

        errors: Optional[List[str]] = None
        if exceptions:
            errors = [str(e) for e in exceptions]

        nodes, sources = catalog.make_unique_id_map(self.manifest)
        results = self.get_catalog_results(
            nodes=nodes,
            sources=sources,
            generated_at=datetime.utcnow(),
            compile_results=compile_results,
            errors=errors,
        )

        path = os.path.join(self.config.target_path, CATALOG_FILENAME)
        results.write(path)
        if self.args.compile:
            write_manifest(self.config, self.manifest)

        if exceptions:
            logger.error(
                'dbt encountered {} failure{} while writing the catalog'.
                format(len(exceptions), (len(exceptions) != 1) * 's'))

        dbt.ui.printer.print_timestamped_line('Catalog written to {}'.format(
            os.path.abspath(path)))

        return results
Example #2
0
    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)

        # we parsed args from the cli, so we're set on that front
        return self.real_task.handle_request()
Example #3
0
 def parse_manifest(self) -> None:
     self.manifest = get_full_manifest(self.config)
Example #4
0
 def load_manifest(self):
     self.manifest = get_full_manifest(self.config)
     write_manifest(self.config, self.manifest)
Example #5
0
 def parse_manifest(self) -> None:
     self.manifest = get_full_manifest(self.config, reset=True)