# This file is generated by numpy's build process
# It contains system_info results at the time of building this package.
from enum import Enum
from numpy._core._multiarray_umath import (
    __cpu_features__,
    __cpu_baseline__,
    __cpu_dispatch__,
)

__all__ = ["show_config"]
_built_with_meson = True


class DisplayModes(Enum):
    stdout = "stdout"
    dicts = "dicts"


def _cleanup(d):
    """
    Removes empty values in a `dict` recursively
    This ensures we remove values that Meson could not provide to CONFIG
    """
    if isinstance(d, dict):
        return {k: _cleanup(v) for k, v in d.items() if v and _cleanup(v)}
    else:
        return d


CONFIG = _cleanup(
    {
        "Compilers": {
            "c": {
                "name": "@C_COMP@",
                "linker": r"@C_COMP_LINKER_ID@",
                "version": "@C_COMP_VERSION@",
                "commands": r"@C_COMP_CMD_ARRAY@",
                "args": r"@C_COMP_ARGS@",
                "linker args": r"@C_COMP_LINK_ARGS@",
            },
            "cython": {
                "name": "@CYTHON_COMP@",
                "linker": r"@CYTHON_COMP_LINKER_ID@",
                "version": "@CYTHON_COMP_VERSION@",
                "commands": r"@CYTHON_COMP_CMD_ARRAY@",
                "args": r"@CYTHON_COMP_ARGS@",
                "linker args": r"@CYTHON_COMP_LINK_ARGS@",
            },
            "c++": {
                "name": "@CPP_COMP@",
                "linker": r"@CPP_COMP_LINKER_ID@",
                "version": "@CPP_COMP_VERSION@",
                "commands": r"@CPP_COMP_CMD_ARRAY@",
                "args": r"@CPP_COMP_ARGS@",
                "linker args": r"@CPP_COMP_LINK_ARGS@",
            },
        },
        "Machine Information": {
            "host": {
                "cpu": "@HOST_CPU@",
                "family": "@HOST_CPU_FAMILY@",
                "endian": "@HOST_CPU_ENDIAN@",
                "system": "@HOST_CPU_SYSTEM@",
            },
            "build": {
                "cpu": "@BUILD_CPU@",
                "family": "@BUILD_CPU_FAMILY@",
                "endian": "@BUILD_CPU_ENDIAN@",
                "system": "@BUILD_CPU_SYSTEM@",
            },
            "cross-compiled": bool("@CROSS_COMPILED@".lower().replace("false", "")),
        },
        "Build Dependencies": {
            "blas": {
                "name": "@BLAS_NAME@",
                "found": bool("@BLAS_FOUND@".lower().replace("false", "")),
                "version": "@BLAS_VERSION@",
                "detection method": "@BLAS_TYPE_NAME@",
                "include directory": r"@BLAS_INCLUDEDIR@",
                "lib directory": r"@BLAS_LIBDIR@",
                "openblas configuration": r"@BLAS_OPENBLAS_CONFIG@",
                "pc file directory": r"@BLAS_PCFILEDIR@",
            },
            "lapack": {
                "name": "@LAPACK_NAME@",
                "found": bool("@LAPACK_FOUND@".lower().replace("false", "")),
                "version": "@LAPACK_VERSION@",
                "detection method": "@LAPACK_TYPE_NAME@",
                "include directory": r"@LAPACK_INCLUDEDIR@",
                "lib directory": r"@LAPACK_LIBDIR@",
                "openblas configuration": r"@LAPACK_OPENBLAS_CONFIG@",
                "pc file directory": r"@LAPACK_PCFILEDIR@",
            },
        },
        "Python Information": {
            "path": r"@PYTHON_PATH@",
            "version": "@PYTHON_VERSION@",
        },
        "SIMD Extensions": {
            "baseline": __cpu_baseline__,
            "found": [
                feature for feature in __cpu_dispatch__ if __cpu_features__[feature]
            ],
            "not found": [
                feature for feature in __cpu_dispatch__ if not __cpu_features__[feature]
            ],
        },
    }
)


def _check_pyyaml():
    import yaml

    return yaml


def show(mode=DisplayModes.stdout.value):
    """
    Show libraries and system information on which NumPy was built
    and is being used

    Parameters
    ----------
    mode : {`'stdout'`, `'dicts'`}, optional.
        Indicates how to display the config information.
        `'stdout'` prints to console, `'dicts'` returns a dictionary
        of the configuration.

    Returns
    -------
    out : {`dict`, `None`}
        If mode is `'dicts'`, a dict is returned, else None

    See Also
    --------
    get_include : Returns the directory containing NumPy C
                  header files.

    Notes
    -----
    1. The `'stdout'` mode will give more readable
       output if ``pyyaml`` is installed

    """
    if mode == DisplayModes.stdout.value:
        try:  # Non-standard library, check import
            yaml = _check_pyyaml()

            print(yaml.dump(CONFIG))
        except ModuleNotFoundError:
            import warnings
            import json

            warnings.warn("Install `pyyaml` for better output", stacklevel=1)
            print(json.dumps(CONFIG, indent=2))
    elif mode == DisplayModes.dicts.value:
        return CONFIG
    else:
        raise AttributeError(
            f"Invalid `mode`, use one of: {', '.join([e.value for e in DisplayModes])}"
        )


def show_config(mode=DisplayModes.stdout.value):
    return show(mode)


show_config.__doc__ = show.__doc__
show_config.__module__ = "numpy"
