def parse(self, cls: type, data: Dict, runtime_args: Optional[Dict[str, Any]] = None) -> 'Flow': """ :param cls: the class registered for dumping/loading :param data: flow yaml file loaded as python dict :param runtime_args: Optional runtime_args to be directly passed without being parsed into a yaml config :return: the Flow YAML parser given the syntax version number """ p = data.get('with', {}) # type: Dict[str, Any] a = p.pop('args') if 'args' in p else () k = p.pop('kwargs') if 'kwargs' in p else {} # maybe there are some hanging kwargs in "parameters" tmp_a = (expand_env_var(v) for v in a) tmp_p = {kk: expand_env_var(vv) for kk, vv in {**k, **p}.items()} obj = cls(*tmp_a, **tmp_p) pp = data.get('executors', data.get('deployments', [])) for deployments in pp: p_deployment_attr = { kk: expand_env_var(vv) for kk, vv in deployments.items() } # in v1 YAML, flow is an optional argument if p_deployment_attr.get('name', None) != 'gateway': # ignore gateway when reading, it will be added during build() method = p_deployment_attr.get('method', 'add') # support methods: add, needs, inspect getattr(obj, method)(**p_deployment_attr, copy_flow=False) return obj
def test_expand_env(): assert expand_env_var('$PATH-${AA}') != '$PATH-${AA}'
def test_expand_env(self): print(expand_env_var('${PATH}-${AA}')) default_logger.info('aa') default_logger.success('aa')