Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a versioned spec for makim and a function that will check if the .makim.yaml file is correct according to the spec #23

Open
xmnlab opened this issue Mar 7, 2023 · 0 comments

Comments

@xmnlab
Copy link
Member

xmnlab commented Mar 7, 2023

I am sharing below some very naive code from chatgpt. I am not suggesting that. just adding here as reference. Myabe it would be good to have a class for each version of spec, where we will define the structure for the spec and a function that will check if the config is in the correct structure .. otherwise it should return an error point where the problem is located.

import yaml

def verify_makim_yaml(file_path):
    with open(file_path) as f:
        makim_data = yaml.safe_load(f)

    version = makim_data.get('version')
    if version != '1.0.0':
        raise ValueError('Incorrect version')

    env_file = makim_data.get('env-file')
    if env_file is not None and not isinstance(env_file, str):
        raise TypeError('env-file must be a string')

    groups = makim_data.get('groups')
    if not isinstance(groups, list):
        raise TypeError('groups must be a list')

    for group in groups:
        name = group.get('name')
        if name is None or not isinstance(name, str):
            raise ValueError('Group name must be a non-empty string')

        targets = group.get('targets')
        if targets is None or not isinstance(targets, dict):
            raise ValueError(f'{name}: targets must be a dictionary')

        for target_name, target in targets.items():
            if not isinstance(target, dict):
                raise ValueError(f'{name}/{target_name}: target definition must be a dictionary')

            help_text = target.get('help')
            if help_text is not None and not isinstance(help_text, str):
                raise ValueError(f'{name}/{target_name}: help text must be a string')

            run_command = target.get('run')
            if not isinstance(run_command, str):
                raise ValueError(f'{name}/{target_name}: run command must be a string')

            dependencies = target.get('dependencies')
            if dependencies is not None and not isinstance(dependencies, list):
                raise ValueError(f'{name}/{target_name}: dependencies must be a list')

            env_vars = target.get('env')
            if env_vars is not None and not isinstance(env_vars, dict):
                raise ValueError(f'{name}/{target_name}: env must be a dictionary')

            args = target.get('args')
            if args is not None and not isinstance(args, dict):
                raise ValueError(f'{name}/{target_name}: args must be a dictionary')

            if args is not None:
                for arg_name, arg_data in args.items():
                    if not isinstance(arg_data, dict):
                        raise ValueError(f'{name}/{target_name}/{arg_name}: arg definition must be a dictionary')
                    arg_help_text = arg_data.get('help')
                    if arg_help_text is not None and not isinstance(arg_help_text, str):
                        raise ValueError(f'{name}/{target_name}/{arg_name}: arg help text must be a string')
                    arg_type = arg_data.get('type')
                    if arg_type is not None and not isinstance(arg_type, str):
                        raise ValueError(f'{name}/{target_name}/{arg_name}: arg type must be a string')
                    arg_default = arg_data.get('default')
                    if arg_default is not None and not isinstance(arg_default, (str, bool, int, float)):
                        raise ValueError(f'{name}/{target_name}/{arg_name}: arg default value must be a string, boolean, integer, or float')
                    arg_action = arg_data.get('action')
                    if arg_action is not None and not isinstance(arg_action, str):
                        raise ValueError(f'{name}/{target_name}/{arg_name}: arg action must be a string')
                    
                    # check if arg dependencies are valid
                    arg_deps = arg_data.get('dependencies')
                    if arg_deps is not None and not isinstance(arg_deps, list):
                        raise ValueError(f'{

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant