示例#1
0
def config(ctx, project, plugin_type, plugin_name, format):
    plugin_type = PluginType.from_cli_argument(
        plugin_type) if plugin_type else None

    config = ConfigService(project)
    plugin = config.find_plugin(plugin_name,
                                plugin_type=plugin_type,
                                configurable=True)

    _, Session = project_engine(project)
    session = Session()
    try:
        settings = PluginSettingsService(project).build(plugin)

        ctx.obj["settings"] = settings
        ctx.obj["session"] = session

        if ctx.invoked_subcommand is None:
            if format == "json":
                config = settings.as_config(session=session)
                print(json.dumps(config))
            elif format == "env":
                for env, value in settings.as_env(session=session).items():
                    print(f"{env}={value}")
    finally:
        session.close()
示例#2
0
def config(ctx, project, plugin_type, plugin_name, format, extras):
    plugin_type = PluginType.from_cli_argument(
        plugin_type) if plugin_type else None

    plugins_service = ProjectPluginsService(project)

    try:
        plugin = plugins_service.find_plugin(plugin_name,
                                             plugin_type=plugin_type,
                                             configurable=True)
    except PluginNotFoundError:
        if plugin_name == "meltano":
            plugin = None
        else:
            raise

    _, Session = project_engine(project)
    session = Session()
    try:
        if plugin:
            settings = PluginSettingsService(project,
                                             plugin,
                                             plugins_service=plugins_service)
        else:
            settings = ProjectSettingsService(
                project, config_service=plugins_service.config_service)

        ctx.obj["settings"] = settings
        ctx.obj["session"] = session

        if ctx.invoked_subcommand is None:
            if format == "json":
                process = extras is not True
                config = settings.as_dict(extras=extras,
                                          process=process,
                                          session=session)
                print(json.dumps(config, indent=2))
            elif format == "env":
                env = settings.as_env(extras=extras, session=session)

                with tempfile.NamedTemporaryFile() as temp_dotenv:
                    path = temp_dotenv.name
                    for key, value in env.items():
                        dotenv.set_key(path, key, value)

                    dotenv_content = Path(temp_dotenv.name).read_text()

                print(dotenv_content, end="")
    finally:
        session.close()
示例#3
0
    def run(self, session, dry_run=False, models=None):
        # we should probably refactor this part to have an ELTContext object already
        # filled with the each plugins' configuration so we don't have to query
        # multiple times for the same data.

        settings_service = PluginSettingsService(self.project)
        try:
            load = self.connection_service.load_params()
            analyze = self.connection_service.analyze_params()
            env = {
                # inject the inferred 'schemas' from the ELTContext
                "MELTANO_LOAD_SCHEMA": load["schema"],
                "MELTANO_ANALYZE_SCHEMA": analyze["schema"],
                "DBT_TARGET": self.connection_service.dialect,
                # inject the extractor & loader configuration as ENV variables.
                # that means dbt will have access to all the configuration of
                # the extractor and loader
                **settings_service.as_env(session, self.context.extractor.ref),
                **settings_service.as_env(session, self.context.loader.ref),
            }
        except Exception as e:
            logging.debug("Could not inject environment to dbt.")
            logging.debug(
                f"Could not hydrate ENV from the EltContext: {str(e)}")
            raise e

        # Get an asyncio event loop and use it to run the dbt commands
        loop = asyncio.get_event_loop()
        loop.run_until_complete(self.dbt_service.deps())

        if models is not None:
            models = models.replace("-", "_")

        if dry_run:
            loop.run_until_complete(self.dbt_service.compile(models, env=env))
        else:
            loop.run_until_complete(self.dbt_service.run(models, env=env))
示例#4
0
文件: config.py 项目: aroder/meltano
def config(ctx, project, plugin_name, format):
    config = ConfigService(project)
    plugin = config.find_plugin(plugin_name)

    _, Session = project_engine(project)
    session = Session()
    settings = PluginSettingsService(project)

    ctx.obj["settings"] = settings
    ctx.obj["plugin"] = plugin
    ctx.obj["session"] = session

    if ctx.invoked_subcommand is None:
        if format == "json":
            print(settings.as_config(session, plugin))

        if format == "env":
            for env, value in settings.as_env(session, plugin).items():
                print(f"{env}={value}")