###############################################################################
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
###############################################################################
import os
import onnx
from distutils.version import StrictVersion

# Rather than using ONNX protobuf definition throughout our codebase, we import ONNX protobuf definition here so that
# we can conduct quick fixes by overwriting ONNX functions without changing any lines elsewhere.
from onnx import onnx_pb as onnx_proto
from onnx import helper


def get_opset_number_from_onnx():
    return onnx.defs.onnx_opset_version()

def _check_onnx_version():
    import pkg_resources
    min_required_version = pkg_resources.parse_version('1.0.1')
    current_version = pkg_resources.get_distribution('onnx').parsed_version
    assert current_version >= min_required_version , 'Keras2ONNX requires ONNX version 1.0.1 or a newer one'


_check_onnx_version()
is_tf_keras = False
if os.environ.get('TF_KERAS', '0') != '0':
    is_tf_keras = True

if is_tf_keras:
    from tensorflow.python import keras
else:
    try:
        import keras
    except ImportError:
        is_tf_keras = True
        from tensorflow.python import keras


def is_keras_older_than(version_str):
    return StrictVersion(keras.__version__.split('-')[0]) < StrictVersion(version_str)


def is_keras_later_than(version_str):
    return StrictVersion(keras.__version__.split('-')[0]) > StrictVersion(version_str)

[((17, 11, 17, 41), 'onnx.defs.onnx_opset_version', 'onnx.defs.onnx_opset_version', ({}, {}), '()', False, 'import onnx\n'), ((21, 27, 21, 63), 'pkg_resources.parse_version', 'pkg_resources.parse_version', ({(21, 55, 21, 62): '"""1.0.1"""'}, {}), "('1.0.1')", False, 'import pkg_resources\n'), ((28, 3, 28, 34), 'os.environ.get', 'os.environ.get', ({(28, 18, 28, 28): '"""TF_KERAS"""', (28, 30, 28, 33): '"""0"""'}, {}), "('TF_KERAS', '0')", False, 'import os\n'), ((22, 22, 22, 60), 'pkg_resources.get_distribution', 'pkg_resources.get_distribution', ({(22, 53, 22, 59): '"""onnx"""'}, {}), "('onnx')", False, 'import pkg_resources\n'), ((42, 60, 42, 86), 'distutils.version.StrictVersion', 'StrictVersion', ({(42, 74, 42, 85): 'version_str'}, {}), '(version_str)', False, 'from distutils.version import StrictVersion\n'), ((46, 60, 46, 86), 'distutils.version.StrictVersion', 'StrictVersion', ({(46, 74, 46, 85): 'version_str'}, {}), '(version_str)', False, 'from distutils.version import StrictVersion\n'), ((42, 25, 42, 53), 'tensorflow.python.keras.__version__.split', 'keras.__version__.split', ({(42, 49, 42, 52): '"""-"""'}, {}), "('-')", False, 'from tensorflow.python import keras\n'), ((46, 25, 46, 53), 'tensorflow.python.keras.__version__.split', 'keras.__version__.split', ({(46, 49, 46, 52): '"""-"""'}, {}), "('-')", False, 'from tensorflow.python import keras\n')]