File size: 1,379 Bytes
d91766b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""Diffulex strategy package that imports built-in strategies to trigger registration."""

from __future__ import annotations
import importlib
from pathlib import Path

# Import built-in strategies so their registrations run at import time.
# Automatically import all subdirectory packages in the current directory
_excluded_dirs = {"__pycache__", "__init__"}
_strategy_modules = []

_current_dir = Path(__file__).parent
for item in _current_dir.iterdir():
    if item.is_dir() and not item.name.startswith("_") and item.name not in _excluded_dirs:
        # Check if it's a Python package (has __init__.py)
        init_file = item / "__init__.py"
        if init_file.exists():
            try:
                importlib.import_module(f".{item.name}", __name__)
                _strategy_modules.append(item.name)
            except Exception as e:
                # Skip packages that fail to import
                import warnings

                warnings.warn(f"Failed to import strategy {item.name}: {e}", ImportWarning)

__all__ = _strategy_modules.copy()

DECODING_STRATEGY = None


def fetch_decoding_strategy() -> str | None:
    return DECODING_STRATEGY


def set_decoding_strategy(strategy: str) -> None:
    global DECODING_STRATEGY
    DECODING_STRATEGY = strategy


def reset_decoding_strategy() -> None:
    global DECODING_STRATEGY
    DECODING_STRATEGY = None