简体   繁体   English

如何在kedro管道中访问环境名称

[英]How to access environment name in kedro pipeline

Is there any way to access the kedro pipeline environment name?有没有办法访问kedro管道环境名称? Actually below is my problem.其实下面是我的问题。

I am loading the config paths as below我正在加载配置路径,如下所示

conf_paths = ["conf/base", "conf/local"]  
conf_loader = ConfigLoader(conf_paths)
parameters = conf_loader.get("parameters*", "parameters*/**")
catalog = conf_loader.get("catalog*")

But I have few environments like "conf/server" , "conf/test" etc, So if I have env name available I can add it to conf_paths as "conf/<env_name>" so that kedro will read the files from the respective env folder.但是我的环境很少,例如"conf/server""conf/test"等,所以如果我有可用的环境名称,我可以将它作为"conf/<env_name>"添加到 conf_paths,这样 kedro 就会从相应的文件中读取文件环境文件夹。 But now if the env path is not added to conf_paths, the files are not being read by kedro even if i specify the env name while I run kedro like kedro run --env=server I searched for all the docs but was not able to find any solution.但是现在如果未将 env 路径添加到 conf_paths,即使我在运行 kedro 时指定了 env 名称,文件也不会被 kedro 读取,比如kedro run --env=server我搜索了所有文档但无法找到任何解决方案。

EDIT: Elaborating more on the problem.编辑:详细说明这个问题。 I am using the above-given parameters and catalog dicts in the nodes.我在节点中使用上面给出的参数和目录字典。 I only have keys that are common for all runs in conf/base/parameters.yml and the environment specific keys in conf/server/parameters.yml but when i do kedro run --env=server I am getting keyerror which means the keys in conf/server/parameters.yml is not available in the parameters dict.我只有conf/base/parameters.yml中所有运行通用的键和conf/server/parameters.yml中的环境特定键,但是当我执行kedro run --env=server时,我得到keyerror这意味着键conf/server/parameters.yml在参数字典中不可用。 If I add conf/server to config_paths kedro is running well without keyerror.如果我将conf/server添加到 config_paths,kedro 运行良好,没有 keyerror。

You don't need to define config paths, config loader etc unless you are trying to override something.你不需要定义配置路径、配置加载器等,除非你试图覆盖某些东西。

If you are using kedro 0.17.x, the hooks.py will look something like this.如果您使用 kedro 0.17.x,则 hooks.py 看起来像这样。

Kedro will pass, base, local and the env you specified during runtime in conf_paths into ConfigLoader . Kedro 会将您在运行时在conf_paths中指定的 base、local 和 env 传递到ConfigLoader中。

class ProjectHooks:
    @hook_impl
    def register_config_loader(
        self, conf_paths: Iterable[str], env: str, extra_params: Dict[str, Any]
    ) -> ConfigLoader:
        return ConfigLoader(conf_paths)

    @hook_impl
    def register_catalog(
        self,
        catalog: Optional[Dict[str, Dict[str, Any]]],
        credentials: Dict[str, Dict[str, Any]],
        load_versions: Dict[str, str],
        save_version: str,
        journal: Journal,
    ) -> DataCatalog:
        return DataCatalog.from_config(
            catalog, credentials, load_versions, save_version, journal
        )

In question, I can see you have defined conf_paths and conf_loader and the env path is not present.有问题,我可以看到您已经定义conf_pathsconf_loader并且 env 路径不存在。 So kedro will ignore the env passed during runtime.所以 kedro 会忽略运行时传递的 env。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM