# Copyright (c) 2021 Graphcore Ltd. All rights reserved.
import os, sys
import pathlib

__version__ = "@VERSION@"

# Add the DSO library path. Look for the LIBDIR in a parent directory. Note that
# we iterate over parent directories because `gen_popart_supported_ops.py` imports
# popart from the build directory, which has a slightly different directory
# structure to the install directory.
parent_path = pathlib.Path(os.path.dirname(os.path.abspath(__file__)))
for parent_dir in parent_path.parents:
    candidate_libdir = os.path.join(parent_dir, "@CMAKE_INSTALL_LIBDIR@")
    if os.path.exists(candidate_libdir):
        lp = os.path.join(candidate_libdir)
        lp = os.path.abspath(lp)
        sys.path.insert(0, lp)
        break

_import_exc = None
try:
    # Import all symbols into our namespace
    from popart_internal_ir import *
except ModuleNotFoundError as exc:
    _import_exc = exc

if _import_exc:
    msg = (
        f"{_import_exc}.\n"
        "Hint: You might be running a Python version that popart._internal.ir doesn't support."
    )
    raise RuntimeError(msg)
