Source code for radioviz.tools.naming_utils

#  Copyright 2026 European Union
#  Author: Bulgheroni Antonio (antonio.bulgheroni@ec.europa.eu)
#  SPDX-License-Identifier: EUPL-1.2
"""
Helpers for consistent derived image naming.

This module provides utility functions to build user-friendly derived labels,
ensuring tool suffixes appear before file extensions when present.
"""

from __future__ import annotations

from pathlib import Path


[docs] def append_suffix_before_extension(label: str, suffix: str) -> str: """ Append a suffix to a label, inserting it before a file extension when present. :param label: Base label to extend. :type label: str :param suffix: Suffix to insert (including any leading separator). :type suffix: str :return: The label with the suffix appended before the extension if any. :rtype: str """ if not suffix: return label path = Path(label) if path.suffix: return f'{path.with_suffix("")}{suffix}{path.suffix}' return f'{label}{suffix}'