From 9e713fdf52913e4dca1fd0f10ca3cade8c69e3dc Mon Sep 17 00:00:00 2001 From: Jat Date: Tue, 17 Jan 2023 16:22:42 +0800 Subject: [PATCH] component_cli: support env Signed-off-by: Jat --- .../fate/components/entrypoint/component_cli.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/python/fate/components/entrypoint/component_cli.py b/python/fate/components/entrypoint/component_cli.py index f699698a2b..49b67bd94e 100644 --- a/python/fate/components/entrypoint/component_cli.py +++ b/python/fate/components/entrypoint/component_cli.py @@ -28,7 +28,8 @@ def component(): @click.option("--config-entrypoint", required=False, help="enctypoint to get config") @click.option("--properties", "-p", multiple=True, help="properties config") @click.option("--env-prefix", "-e", type=str, default="runtime.component.", help="prefix for env config") -def execute(process_tag, config, config_entrypoint, properties, env_prefix): +@click.option("--env-name", required=False, type=str, help="env name for config") +def execute(process_tag, config, config_entrypoint, properties, env_prefix, env_name): "execute component" import logging @@ -41,6 +42,7 @@ def execute(process_tag, config, config_entrypoint, properties, env_prefix): # parse config configs = {} + load_config_from_env(configs, env_name) load_config_from_entrypoint(configs, config_entrypoint) load_config_from_file(configs, config) load_config_from_properties(configs, properties_items) @@ -115,10 +117,10 @@ def _set(v): def load_config_from_file(configs, config_file): - from ruamel import yaml + import json if config_file is not None: - configs.update(yaml.safe_load(config_file)) + configs.update(json.load(config_file)) return configs @@ -134,6 +136,15 @@ def load_config_from_entrypoint(configs, config_entrypoint): return configs +def load_config_from_env(configs, env_name): + import os + import json + + if env_name is not None and os.environ.get(env_name): + configs.update(json.loads(os.environ[env_name])) + return configs + + @component.command() @click.option("--name", required=True, help="name of component") @click.option("--save", type=click.File(mode="w", lazy=True), help="save desc output to specified file in yaml format")