Beispiel #1
0
def read(config_values):
    """Reads an ordered list of configuration values and deep merge the values in reverse order."""
    if not config_values:
        raise RheaError('Cannot read config_value: `{}`'.format(config_values))

    config_values = to_list(config_values)

    config = {}
    for config_value in config_values:
        if not isinstance(config_value, (Mapping, six.string_types)):
            raise RheaError(
                "Expects Mapping, string, or list of Mapping/string instances, "
                "received {} instead".format(type(config_value)))

        if isinstance(config_value, Mapping):
            config_results = config_value
        elif os.path.isfile(config_value):
            config_results = _read_from_file(config_value)
        else:
            # try reading a stream of yaml or json
            try:
                config_results = _read_from_stream(config_value)
            except ScannerError:
                raise RheaError('Received non valid yaml stream: `{}`'.format(
                    config_value))

        if config_results and isinstance(config_results, Mapping):
            config = deep_update(config, config_results)
        else:
            raise RheaError(
                'Cannot read config_value: `{}`'.format(config_value))

    return config
Beispiel #2
0
    def parse(cls, spec, data, matrix_declarations=None):  # pylint:disable=too-many-branches
        declarations = copy.copy(data.get(spec.DECLARATIONS, {}))
        matrix_declarations = copy.copy(matrix_declarations)
        if matrix_declarations:
            declarations = deep_update(matrix_declarations, declarations)

        parsed_data = {
            spec.VERSION: data[spec.VERSION],
            spec.KIND: data[spec.KIND],
        }

        if declarations:
            declarations = cls.parse_expression(spec, declarations, declarations)
            parsed_data[spec.DECLARATIONS] = declarations

        for section in spec.STD_PARSING_SECTIONS:
            if section in data:
                parsed_data[section] = cls.parse_expression(spec, data[section], declarations)

        for section in spec.OP_PARSING_SECTIONS:
            if section in data:
                parsed_data[section] = cls.parse_expression(
                    spec, data[section], declarations, True, False)

        if spec.RUN in data:
            parsed_data[spec.RUN] = cls.parse_expression(
                spec, data[spec.RUN], declarations, True, False)

        for section in spec.GRAPH_SECTIONS:
            if section in data:
                parsed_data[section] = cls.parse_expression(
                    spec, data[section], declarations, True, True)

        return parsed_data
Beispiel #3
0
    def parse(cls, spec, config, params):  # pylint:disable=too-many-branches
        params = params or {}
        parsed_params = {param: params[param].display_value for param in params}

        parsed_data = {spec.VERSION: config.version, spec.KIND: config.kind}

        if config.name:
            parsed_data[spec.NAME] = config.name
        if config.description:
            parsed_data[spec.DESCRIPTION] = config.description
        if config.tags:
            parsed_data[spec.TAGS] = config.tags
        inputs = getattr(config, spec.INPUTS)
        if inputs:
            parsed_data[spec.INPUTS] = [io.to_dict() for io in inputs]
        outputs = getattr(config, spec.OUTPUTS)
        if outputs:
            parsed_data[spec.OUTPUTS] = [
                cls.parse_expression(spec, io.to_dict(), parsed_params)
                for io in outputs
            ]

        # Check workflow
        workflow_section = cls._get_section(config, spec.WORKFLOW)
        if workflow_section:
            parsed_data[spec.WORKFLOW] = cls.parse_expression(
                spec, workflow_section, parsed_params
            )
            workflow_params = copy.copy(parsed_data[spec.WORKFLOW])
            if workflow_params:
                parsed_params = deep_update(workflow_params, parsed_params)

        for section in spec.PARSING_SECTIONS:
            config_section = cls._get_section(config, section)
            if config_section:
                parsed_data[section] = cls.parse_expression(
                    spec, config_section, parsed_params
                )

        for section in spec.OP_PARSING_SECTIONS:
            config_section = cls._get_section(config, section)
            if config_section:
                parsed_data[section] = cls.parse_expression(
                    spec, config_section, parsed_params
                )

        config_section = cls._get_section(config, spec.CONTAINER)
        if config_section:
            parsed_data[spec.CONTAINER] = config_section

        return parsed_data
Beispiel #4
0
def read(config_values):
    """Reads an ordered list of configuration values and deep merge the values in reverse order."""
    if not config_values:
        raise RheaError('Cannot read config_value: `{}`'.format(config_values))

    config_values = to_list(config_values)

    config = {}
    for config_value in config_values:
        config_value = ConfigSpec.get_from(value=config_value)
        config_value.check_type()
        config_results = config_value.read()
        if config_results and isinstance(config_results, Mapping):
            config = deep_update(config, config_results)
        elif config_value.check_if_exists:
            raise RheaError(
                'Cannot read config_value: `{}`'.format(config_value))

    return config
Beispiel #5
0
    def parse(cls, spec, config, params, matrix_params=None):  # pylint:disable=too-many-branches
        params = params or {}
        matrix_params = copy.copy(matrix_params)
        if matrix_params:
            params = deep_update(matrix_params, params)

        parsed_data = {
            spec.VERSION: config.version,
            spec.KIND: config.kind,
        }

        if params:
            params = cls.parse_expression(spec, params, params)
            parsed_data[spec.PARAMS] = params

        for section in spec.STD_PARSING_SECTIONS:
            config_section = cls._get_section(config, section)
            if config_section:
                parsed_data[section] = cls.parse_expression(
                    spec, config_section, params)

        for section in spec.OP_PARSING_SECTIONS:
            config_section = cls._get_section(config, section)
            if config_section:
                parsed_data[section] = cls.parse_expression(
                    spec, config_section, params, True, False)

        config_section = cls._get_section(config, spec.RUN)
        if config_section:
            parsed_data[spec.RUN] = cls.parse_expression(
                spec, config_section, params, True, False)

        for section in spec.GRAPH_SECTIONS:
            config_section = cls._get_section(config, section)
            if config_section:
                parsed_data[section] = cls.parse_expression(
                    spec, config_section, params, True, True)

        return parsed_data