"""Available direction methods and their canonical identifiers.""" import warnings DIRECTION_METHODS = { "diff_means": "diff_means", "svd": "svd", "fisher_lda": "fisher_lda", "leace": "fisher_lda", "leace_exact": "leace_exact", } LEACE_ALIAS_NOTICE = ( "leace is a deprecated alias for the Fisher LDA direction (fisher_lda); " "exact erasure is leace_exact. The leace alias will be removed in a future minor release. " "The pipeline uses the leace_exact removal direction, not the full affine eraser." ) def available_direction_methods() -> tuple[str, ...]: """Return available CLI/API ids, including compatibility aliases.""" return tuple(DIRECTION_METHODS) def effective_direction_method( requested: str, *, warn_alias: bool = True, stacklevel: int = 2, ) -> str: """Resolve an id, warning at public entry points only for the legacy alias. Internal validation and repeated resolution pass ``warn_alias=False`` so a single user selection does not produce warnings for every layer or fold. """ if requested == "leace" and warn_alias: warnings.warn(LEACE_ALIAS_NOTICE, DeprecationWarning, stacklevel=stacklevel) if requested == "som": raise ValueError( "direction method 'som' is not available: " "obliteratus.analysis.som_directions is not shipped; " f"choose from {', '.join(available_direction_methods())}." ) try: return DIRECTION_METHODS[requested] except KeyError: raise ValueError( f"Unknown direction method {requested!r}. " f"Choose from: {', '.join(available_direction_methods())}" ) from None