#!/usr/bin/python3
# -*- coding: utf-8 -*-

import configparser
import logging
from pathlib import Path

logger = logging.getLogger(__name__)

_BLACKLIST_FILE: Path = Path('/etc/sun/blacklist.conf')


def load_blacklist() -> set[str]:
    """Returns the set of package names to exclude from pending checks.

    Reads /etc/sun/blacklist.conf using configparser. Returns an empty set
    if the file is missing or the PACKAGES key is not set.

    Returns:
        set[str]: Package names to exclude (e.g. {'rust', 'tigervnc'}).
    """
    parser = configparser.ConfigParser()
    parser.read(_BLACKLIST_FILE, encoding='utf-8')
    raw = parser.get('BLACKLIST', 'PACKAGES', fallback='')
    packages = {name.strip() for name in raw.splitlines() if name.strip()}
    if packages:
        logger.debug('Blacklist loaded: %s', packages)
    return packages
