def compile_partitions(datapkg_settings):
    """
    Given a datapackage settings dictionary, extract dataset partitions.

    Iterates through all the datasets enumerated in the datapackage settings,
    and compiles a dictionary indicating which datasets should be partitioned
    and on what basis when they are output as tabular data resources. Currently
    this only applies to the epacems dataset. Datapackage settings must be
    validated because currently we inject EPA CEMS partitioning variables
    (epacems_years, epacems_states) during the validation process.

    Args:
        datapkg_settings (dict): a dictionary containing validated datapackage
            settings, mostly read in from a PUDL ETL settings file.

    Returns:
        dict: Uses table name (e.g. hourly_emissions_epacems)  as keys, and
        lists of partition variables (e.g. ["epacems_years", "epacems_states"])
        as the values. If no datasets within the datapackage are being
        partitioned, this is an empty dictionary.

    """
    partitions = {}
    for dataset in datapkg_settings['datasets']:
        for dataset_name in dataset:
            try:
                partitions.update(dataset[dataset_name]['partition'])
            except KeyError:
                pass
    return partitions