@@ -0,0 +1,1602 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.%0A# Use of this source code is governed by a BSD-style license that can be%0A# found in the LICENSE file.%0A%0Aimport importlib%0A%0Afrom distutils import version%0A%0AMODULES = %7B%0A  'cv2': (version.StrictVersion('2.4.8'), version.StrictVersion('3.0.0')),%0A  'numpy': (version.StrictVersion('1.6.1'), None),%0A%7D%0A%0Adef ImportOptionalModule(module):%0A  %22%22%22Tries to import the desired module.%0A%0A  Raises:%0A    ImportError: The import failed.%22%22%22%0A  versions = MODULES.get(module)%0A  if versions is None:%0A    raise NotImplementedError('Please teach telemetry about module %25s.' %25%0A                              module)%0A  min_version, max_version = versions%0A%0A  module = importlib.import_module(module)%0A  try:%0A    if ((min_version is not None and%0A            version.StrictVersion(module.__version__) %3C min_version) or%0A        (max_version is not None and%0A            version.StrictVersion(module.__version__) %3E= max_version)):%0A      raise ImportError(('Incorrect %7B0%7D version found, expected %7B1%7D %3C= version '%0A                         '%3C %7B2%7D, found version %7B3%7D').format(%0A          module, min_version, max_version, module.__version__))%0A  except ValueError as e:%0A    # This error is raised when a module returns and incorrectly formatted%0A    # version string. ex. '$build 1456a'%0A    if 'invalid version number' in str(e):%0A      raise ImportError(('Incorrectly formatted %7B0%7D version found, expected '%0A                         '%7B1%7D %3C= version %3C %7B2%7D, found version %7B3%7D').format(%0A          module, min_version, max_version, module.__version__))%0A    else:%0A      raise%0A  return module%0A

Version checking code for optional dependencies.