Skip to content

Commit

Permalink
component_cli: support env
Browse files Browse the repository at this point in the history
Signed-off-by: Jat <jat@sinosky.org>
  • Loading branch information
jat001 committed Jan 17, 2023
1 parent 7a2692b commit 9e713fd
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions python/fate/components/entrypoint/component_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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


Expand All @@ -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")
Expand Down

0 comments on commit 9e713fd

Please sign in to comment.