from pathlib import Path
from typing import List
import re


def get_amici_base_sources(
        base_dir: Path,
        with_hdf5: bool = True
) -> List[str]:
    """Get list of source files for the amici base library

    Expects that we are inside $AMICI_ROOT/python/sdist

    Arguments:
        base_dir: AMICI base dir containing ``src/`` and ``include/``
        with_hdf5: compile with HDF5 support
    """
    amici_base_sources = (base_dir / 'src').glob('*.cpp')
    amici_base_sources = [
        str(src) for src in amici_base_sources
        if not re.search(r'(matlab)|(\.(ODE_)?template\.)', str(src))
    ]

    if not with_hdf5:
        hdf5_cpp = base_dir / 'src' / 'hdf5.cpp'
        try:
            # sometimes this fails for unknown reasons...
            amici_base_sources.remove(str(hdf5_cpp))
        except ValueError:
            print(f'Warning: could not find {hdf5_cpp} in '
                  f'{amici_base_sources}')

    return amici_base_sources