示例#1
0
def get_ops_from_suggestions(
    content: str,
    compiled_operation: V1CompiledOperation,
    suggestions: List[Dict],
) -> List[V1Operation]:
    def has_param(k: str):
        if not compiled_operation.matrix:
            return None
        return not compiled_operation.matrix.has_param(k)

    op_content = V1Operation.read(content)
    for suggestion in suggestions:
        params = {
            k: V1Param(value=Parser.parse_expression(v, {}),
                       context_only=has_param(k))
            for (k, v) in suggestion.items()
        }
        op_spec = copy.deepcopy(op_content)
        op_spec.matrix = None
        op_spec.conditions = None
        op_spec.schedule = None
        op_spec.events = None
        op_spec.dependencies = None
        op_spec.trigger = None
        op_spec.skip_on_upstream_skip = None
        op_spec.cache = compiled_operation.cache
        op_spec.queue = compiled_operation.queue
        op_spec.params = params
        op_spec.component.inputs = compiled_operation.inputs
        op_spec.component.outputs = compiled_operation.outputs
        op_spec.component.contexts = compiled_operation.contexts
        yield op_spec
示例#2
0
def get_ops_from_suggestions(
    content: str,
    compiled_operation: V1CompiledOperation,
    suggestions: List[Dict],
) -> List[V1Operation]:
    ops = []
    for suggestion in suggestions:
        params = {
            k: V1Param(value=Parser.parse_expression(v, {}))
            for (k, v) in suggestion.items()
        }
        op_spec = V1Operation.read(content)
        op_spec.matrix = None
        op_spec.conditions = None
        op_spec.schedule = None
        op_spec.events = None
        op_spec.dependencies = None
        op_spec.trigger = None
        op_spec.skip_on_upstream_skip = None
        op_spec.cache = compiled_operation.cache
        op_spec.queue = compiled_operation.queue
        op_spec.params = params
        op_spec.component.inputs = compiled_operation.inputs
        op_spec.component.outputs = compiled_operation.outputs
        op_spec.component.contexts = compiled_operation.contexts
        ops.append(op_spec)

    return ops
示例#3
0
def parse_params(params, is_cli: bool = True):
    if isinstance(params, Mapping):
        return {
            k: {
                "value": Parser.parse_expression(v, {})
            }
            for k, v in params.items()
        }

    parsed_params = {}
    for param in params:
        index = param.find("=")
        if index == -1:
            message = (
                "Invalid format for -P parameter: '%s'. Use -P name=value." %
                param)
            if is_cli:
                Printer.print_error(message, sys_exit=True)
            else:
                raise PolyaxonfileError(message)
        name = param[:index]
        value = param[index + 1:]
        if name in parsed_params:
            message = "Repeated parameter: '%s'" % name
            if is_cli:
                Printer.print_error(message, sys_exit=True)
            else:
                raise PolyaxonfileError(message)
        parsed_params[name] = {"value": value}

    return parsed_params
示例#4
0
    def as_arg(self):
        if self.arg_format:
            from polyaxon.polyaxonfile.specs.libs.parser import Parser

            return (Parser.parse_expression(self.arg_format,
                                            {self.name: self.param.value})
                    if self.param.value is not None else "")
        if self.iotype == types.BOOL:
            return "--{}".format(self.name) if self.param.value else ""
        return ("--{}={}".format(self.name.replace("_", "-"), self.as_str())
                if self.param.value is not None else "")
示例#5
0
    def test_parse_base_expressions(self):
        data = [
            1,
            10.0,
            [1, 1],
            (1, 1),
            "string",
            ["str1", "str2"],
            {1: 2, "a": "a", "dict": {1: 1}},
        ]

        parser = Parser()
        for d in data:
            assert d == parser.parse_expression(d, {})
示例#6
0
def get_ops_from_suggestions(
    content: str, compiled_operation: V1CompiledOperation, suggestions: List[Dict]
) -> List[V1Operation]:
    ops = []
    for suggestion in suggestions:
        params = {
            k: V1Param(value=Parser.parse_expression(v, {}))
            for (k, v) in suggestion.items()
        }
        op_spec = V1Operation.read(content)
        op_spec.matrix = None  # remove matrix
        op_spec.params = params
        op_spec.component.inputs = compiled_operation.inputs
        op_spec.component.outputs = compiled_operation.outputs
        ops.append(op_spec)

    return ops
示例#7
0
 def test_parse_context_expression(self):
     parser = Parser()
     assert parser.parse_expression("{{ something }}", {}) == ""
     assert parser.parse_expression("{{ something }}",
                                    {"something": 1}) == 1