otter-grader icon indicating copy to clipboard operation
otter-grader copied to clipboard

Allow users to directly specify kwargs in assignment config

Open chrispyles opened this issue 2 years ago • 0 comments

For assignment configurations in Otter Assign that are just used to generate kwargs for function calls (e.g. the keys under export_cell, instead of manually specifying each argument, have a single nested kwargs key that is used to generate the arguments.

For example, instead of

export_cell:
    run_tests: true
    filtering: false
    files:
        - data.csv

you would put

export_cell:
    kwargs:
        run_tests: true
        filtering: true
        files:
            - data.csv

and this would generate

grader.export(run_tests=True, filtering=True, files=['data.csv'])

For converting YAML-esque values to valid Python code, the function below should work.

def obj_to_args(o):
    if isinstance(o, str):
        return repr(o)
    elif isinstance(o, list):
        return "[" + ", ".join(obj_to_args(i) for i in o) + "]"
    elif isinstance(o, dict):
        return "{" + ", ".join(f"{obj_to_args(k)}: {obj_to_args(v)}" for k, v in o.items()) + "}"
    else:
        return str(o)

chrispyles avatar Oct 15 '22 22:10 chrispyles