# CONFIDENTIAL. (C) 2022 Cadence Design Systems, Inc. (Cadence)
# All rights reserved.
# ALL SOFTWARE BELOW IS PROPRIETARY AND CONFIDENTIAL TO CADENCE
# AND IS SUBJECT TO THE FULL PROTECTION OF COPYRIGHT AND TRADE SECRET LAW.
# Copying or modifying this software is strictly prohibited and illegal.
# Using this software without a valid license from Cadence is strictly
# prohibited and illegal.  De-obfuscating, de-minimizing, or any other
# attempt to reverse engineer or discover the workings of this software,
# is strictly prohibited. Even if software is exposed or visible, it is
# still proprietary and confidential and the above prohibitions apply.
# This software is NOT "Sample Code". For purposes of customization or
# interoperation with other software you must use Sample Code
# specifically labeled as such.
# Please contact Cadence at eyesopen.com/legal if you have any questions
# about this warning.

# __init__.py file required to make the openeye directory a module

major = 3
min_minor = 7
import sys
if sys.version_info < (major, min_minor):
    raise ImportError(f"Python version {major}.{min_minor} or newer required for OpenEye Python Toolkits")

openeye_python_version_major = 3
openeye_python_version_minor = 9
openeye_python_abi = "x64"

if sys.version_info[0] != openeye_python_version_major:
    raise ImportError(
        "Unable to use Python %i with OpenEye Python Toolkits built for Python %i" %
        (sys.version_info[0], openeye_python_version_major))

if sys.version_info[0] < 3: # for python versions less than 3, minor versions must match
    if sys.version_info[1] != openeye_python_version_minor:
        raise ImportError(
            "Unable to use Python %i.%i with OpenEye Python Toolkits built for Python %i.%i" %
            (sys.version_info[0], sys.version_info[1],
             openeye_python_version_major, openeye_python_version_minor))

import platform
bits, linkage = platform.architecture()
machine = platform.machine()
if sys.platform == "darwin":
    if openeye_python_abi == "universal":
        pass
    elif machine == "x86_64" and openeye_python_abi == "x64":
        pass
    elif openeye_python_abi not in bits and openeye_python_abi != machine:
        raise ImportError("Unable to use %sbit compiled OpenEye Python Toolkits with %s %s Python" %
                        (openeye_python_abi, machine, bits))
elif sys.platform == "linux":
    if machine == "x86_64" and openeye_python_abi == "x64":
        pass
    elif machine == "aarch64" and openeye_python_abi == "aarch64":
        pass
    elif openeye_python_abi not in bits and openeye_python_abi != machine:
        raise ImportError("Unable to use %sbit compiled OpenEye Python Toolkits with %s Python" %
                        (openeye_python_abi, bits))
elif openeye_python_abi not in bits:
    raise ImportError("Unable to use %sbit compiled OpenEye Python Toolkits with %s Python" %
                      (openeye_python_abi, bits))

__version__ = "2023.1.1"

__doc__ = """
OpenEye Python Toolkits
=======================

Find out more by visiting http://docs.eyesopen.com
"""

import os
import types

default_swig_builds = "oechem oedepict oemolprop oeiupac oegraphsim oegrid oeff oeshape oespruce oequacpac oezap oespicoli oeszybki oedocking oegrapheme oemedchem oeomega oeszmap oestats oesitehopper oebioisostere oefastrocs"
assert default_swig_builds != "", "DEFAULT_SWIG_BUILDS is empty! The build system messed up."

openeye_modules_ordered = default_swig_builds.split()
openeye_modules_set = set(openeye_modules_ordered)
openeye_modules_set.add("tests")

class OpenEyeModule(types.ModuleType):
    __version__ = __version__
    __doc__ = __doc__
    __file__ = __file__
    __name__ = __name__
    __path__ = __path__
    __package__ = None
    _openeye_modules_ordered = openeye_modules_ordered
    _openeye_modules_set = openeye_modules_set
    _directory = os.path.dirname(__file__)

    def _get_openeye_module(self, modname):
        import sys
        fullname = "openeye." + modname
        if fullname in sys.modules:
            return sys.modules[fullname]

        import importlib.util
        import importlib.abc

        spec = importlib.util.spec_from_file_location(modname, self._directory)
        if spec is None:
            # if None returned, retry with a full path
            spec = importlib.util.spec_from_file_location(modname, '{}/{}.py'.format(self._directory, modname))
        mod = importlib.util.module_from_spec(spec)
        spec.loader.exec_module(mod)
        sys.modules[fullname] = mod
        sys.modules[modname] = mod
        return mod

    def _get_all(self):
        all = set()
        for modname in self._openeye_modules_ordered:
            all.add(modname)

            mod = self._get_openeye_module(modname)
            for name in dir(mod):
                if name.startswith("_"):
                    continue
                if "swig" in name:
                    continue

                all.add(name)
        return list(all)

    def _find_attr(self, name):
        if name == "__all__":
            return self._get_all()
        elif name in self._openeye_modules_set:
            return self._get_openeye_module(name)

        for modname in self._openeye_modules_ordered:
            mod = self._get_openeye_module(modname)
            if hasattr(mod, name):
                return getattr(mod, name)

        raise AttributeError("'%s' has no attribute '%s'" % (__name__, name))

    def __getattr__(self, name):
        obj = self._find_attr(name)
        setattr(self, name, obj)
        return obj

    def __dir__(self):
        return self.__all__

import sys
if not hasattr(sys, "frozen"):
    sys.modules[__name__] = OpenEyeModule(__name__)
