import yaml


def get_model_tracer_lists(spec):
    """Return the `model_tracer_list` specified in the emergent constraint
    input file: EC-input.yaml.
    
    Parameters
    ----------
    
    spec : string
      Specification of the constraint option in EC-input.yaml.  
      Options include: 'ocean_constraint', 'total_constraint'
      
    Returns
    -------
    
    model_tracer_list: list of tuples
      The models and their tracers to use, i.e. [(CT2017, "CO2_OCN"), (CT2019B, "CO2_OCN"), ...]
      
    """
    
    
    with open('EC-input.yaml', 'r') as fid:
        input_dict = yaml.safe_load(fid)['model_input_lists']

    assert spec in input_dict, f'unknown spec: {spec}'
    kwargs = input_dict[spec]
    for list_i in ['model_tracer_list', 'model_tracer_ext_list',]:
        if list_i in kwargs:
            kwargs[list_i] = [tuple(mt) for mt in kwargs[list_i]]
        else:
            kwargs[list_i] = []

    if 'model_list_sfco2_lnd' not in kwargs:
        kwargs['model_list_sfco2_lnd'] = []

    return kwargs