"""Unified interface for importing C++ extensions."""

import os
import sys
import warnings

# Add path of tbplas-cpp extensions
# We decide to introduce a new environment variable rather than the default
# PYTHONPATH to enforce the user to explicitly specify the path of C++
# extensions.
try:
    sys.path.append(os.environ["TBPLAS_CORE_PATH"])
except KeyError:
    warnings.warn("TBPLAS_CORE_PATH not defined. Fall back to tbplas/cython.")

try:
    import atom
except ImportError:
    try:
        from . import atom
    except ImportError as err:
        raise ImportError("C++ atom extension not found. Check your installation.") from err

try:
    import orbital_map
except ImportError:
    try:
        from . import orbital_map
    except ImportError as err:
        raise ImportError("C++ orbital_map extension not found. Check your installation.") from err

try:
    import sample
except ImportError:
    try:
        from . import sample
    except ImportError as err:
        raise ImportError("C++ sample extension not found. Check your installation.") from err

try:
    import super
except ImportError:
    try:
        from . import super
    except ImportError as err:
        raise ImportError("C++ super extension not found. Check your installation.") from err

try:
    import interface_hdf5
except ImportError:
    try:
        from . import interface_hdf5
    except ImportError:
        warnings.warn("C++ hdf5 extension not found. HDF5 IO not usable.")
        interface_hdf5 = None

try:
    import interface_mpi
except ImportError:
    try:
        from . import interface_mpi
    except ImportError:
        warnings.warn("C++ MPI extension not found. MPI parallelization not usable.")
        from . import dummy_mpi as interface_mpi

try:
    import interface_diag
except ImportError:
    try:
        from . import interface_diag
    except ImportError:
        warnings.warn("C++ diag extension not found. Diagonalization methods not usable.")
        interface_diag = None

try:
    import interface_tbpm
except ImportError:
    try:
        from . import interface_tbpm
    except ImportError:
        warnings.warn("C++ tbpm extension not found. TBPM methods not usable.")
        interface_tbpm = None
