§
    ­¸jy  ã                  óD   — d Z ddlmZ ddlZddlZddœdd„Zdd„Zdd„ZdS )a  Shared output-filename stem resolution for the export backends.

Three of the five export backends (ONNX, CoreML, ExecuTorch) resolve their output-artifact stem entirely through
:func:`resolve_export_stem`, choosing between a user-supplied full override (``output_name``), a model variant
identifier (``variant_name``), and a generic default, with consistent path-traversal sanitization. The other two differ:
TFLite takes no ``output_name`` at all (it inherits its stem from the already-resolved ONNX filename), and TensorRT
delegates only the ``output_name`` sanitize step here while still building its own engine path and ``_fp16``/``_fp32``
precision suffix. Centralizing the precedence + sanitization keeps the backends that share it consistent instead of each
re-implementing it.
é    )ÚannotationsNÚinference_model)ÚdefaultÚvariant_nameú
str | NoneÚoutput_namer   ÚstrÚreturnútuple[str, bool]c               ó|   — |r$t          |¦  «        }|st          d¦  «        ‚|dfS | rt          | ¦  «        dfS |dfS )a  Resolve the output filename stem for an export backend.

    Precedence: ``output_name`` (verbatim custom filename) wins over ``variant_name``
    (model identifier, e.g. ``"rfdetr-small"``) wins over *default*. Both inputs are
    sanitized against path traversal by keeping only the basename and stripping any
    extension the caller may have included (e.g. ``"rfdetr-small.onnx"`` -> ``"rfdetr-small"``).

    Args:
        variant_name: Model variant identifier, or ``None``.
        output_name: User-supplied full filename override, or ``None``. When set, callers
            should suppress any load-bearing detail suffix (precision/backend/etc.) they
            would otherwise append, since the caller asked for this exact name.
        default: Stem to use when both *variant_name* and *output_name* are ``None``.

    Returns:
        A ``(stem, is_custom)`` tuple. ``is_custom`` is ``True`` only when *output_name*
        was used, signalling that detail suffixes should be omitted.

    Raises:
        ValueError: If *output_name* sanitizes to an empty filename stem.

    Examples:
        >>> resolve_export_stem("rfdetr-small", None)
        ('rfdetr-small', False)
        >>> resolve_export_stem("rfdetr-small", "my-model")
        ('my-model', True)
        >>> resolve_export_stem(None, None)
        ('inference_model', False)
        >>> resolve_export_stem(None, None, default="backbone_model")
        ('backbone_model', False)
        >>> resolve_export_stem("sub/dir/rfdetr-nano.onnx", None)
        ('rfdetr-nano', False)
    z5output_name must resolve to a non-empty filename stemTF)Ú	_sanitizeÚ
ValueError)r   r   r   Ústems       úe/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/rfdetr/export/_naming.pyÚresolve_export_stemr      sa   € ðN ð Ý˜Ñ%Ô%ˆØð 	VÝÐTÑUÔUÐUØ�TˆzÐØð .Ý˜Ñ&Ô&¨Ð-Ð-Ø�Eˆ>Ðó    Úexport_nameÚbackbone_onlyÚboolÚnamedc               ó   — |r|r| › d�n| S )uÊ  Append the structural ``-backbone`` marker to an artifact name when one is needed.

    ``-backbone`` marks a distinct model graph, not a precision or backend detail, so every backend appends it after
    whatever detail suffix it already added. It is appended whenever a name was supplied â€” custom or variant-derived â€”
    but never onto the bare ``backbone_model`` default, which already spells it out. Without the marker a backbone
    export silently overwrites a full-detector export of the same name.

    Args:
        export_name: The artifact name resolved so far, including any precision or backend suffix.
        backbone_only: Whether the artifact is a backbone-only export.
        named: Whether the caller supplied a ``variant_name`` or ``output_name``.

    Returns:
        *export_name*, with ``-backbone`` appended when the marker applies.

    Examples:
        >>> append_backbone_marker("rfdetr-small_fp16", backbone_only=True, named=True)
        'rfdetr-small_fp16-backbone'
        >>> append_backbone_marker("backbone_model", backbone_only=True, named=False)
        'backbone_model'
        >>> append_backbone_marker("rfdetr-small", backbone_only=False, named=True)
        'rfdetr-small'
    z	-backbone© )r   r   r   s      r   Úappend_backbone_markerr   H   s"   € ð0 )6ÐP¸%ÐPˆkÐ$Ð$Ð$Ð$À[ÐPr   Únamec                ó~   — t           j                             t          j        d| ¦  «        d         ¦  «        d         S )zEStrip directory components and extension from a caller-supplied name.z[\\/]éÿÿÿÿr   )ÚosÚpathÚsplitextÚreÚsplit)r   s    r   r   r   c   s.   € åŒ7×Ò�BœH X¨tÑ4Ô4°RÔ8Ñ9Ô9¸!Ô<Ð<r   )r   r   r   r   r   r	   r
   r   )r   r	   r   r   r   r   r
   r	   )r   r	   r
   r	   )Ú__doc__Ú
__future__r   r   r    r   r   r   r   r   r   ú<module>r$      s�   ðð	ð 	ð #Ð "Ð "Ð "Ð "Ð "à 	€	€	€	Ø 	€	€	€	ð %ð	.ð .ð .ð .ð .ð .ðbQð Qð Qð Qð6=ð =ð =ð =ð =ð =r   