code: def _check_soft_dependencies(
      *packages,
      package_import_alias=None,
      severity="error",
      obj=None,
      msg=None,
      suppress_import_stdout=False,
  ):
      """Check if required soft dependencies are installed and raise error or warning.
  
      Parameters
      ----------
      packages : str or list/tuple of str, or length-1-tuple containing list/tuple of str
          str should be package names and/or package version specifications to check.
          Each str must be a PEP 440 compatibe specifier string, for a single package.
          For instance, the PEP 440 compatible package name such as "pandas";
          or a package requirement specifier string such as "pandas>1.2.3".
          arg can be str, kwargs tuple, or tuple/list of str, following calls are valid:
          `_check_soft_dependencies("package1")`
          `_check_soft_dependencies("package1", "package2")`
          `_check_soft_dependencies(("package1", "package2"))`
          `_check_soft_dependencies(["package1", "package2"])`
      package_import_alias : dict with str keys and values, optional, default=empty
          key-value pairs are package name, import name
          import name is str used in python import, i.e., from import_name import ...
          should be provided if import name differs from package name
      severity : str, "error" (default), "warning", "none"
          behaviour for raising errors or warnings
          "error" - raises a `ModuleNotFoundError` if one of packages is not installed
          "warning" - raises a warning if one of packages is not installed
              function returns False if one of packages is not installed, otherwise True
          "none" - does not raise exception or warning
              function returns False if one of packages is not installed, otherwise True
      obj : python class, object, str, or None, default=None
          if self is passed here when _check_soft_dependencies is called within __init__,
          or a class is passed when it is called at the start of a single-class module,
          the error message is more informative and will refer to the class/object;
          if str is passed, will be used as name of the class/object or module
      msg : str, or None, default=None
          if str, will override the error message or warning shown with msg
      suppress_import_stdout : bool, optional. Default=False
          whether to suppress stdout printout upon import.
  
      Raises
      ------
      ModuleNotFoundError
          error with informative message, asking to install required soft dependencies
  
      Returns
      -------
      boolean - whether all packages are installed, only if no exception is raised
      """
      if len(packages) == 1 and isinstance(packages[0], (tuple, list)):
          packages = packages[0]
      if not all(isinstance(x, str) for x in packages):
          raise TypeError(
              "packages argument of _check_soft_dependencies must be str or tuple of "
              f"str, but found packages argument of type {type(packages)}"
          )
  
      if package_import_alias is None:
          package_import_alias = {}
      msg_pkg_import_alias = (
          "package_import_alias argument of _check_soft_dependencies must "
          "be a dict with str keys and values, but found "
          f"package_import_alias of type {type(package_import_alias)}"
      )
      if not isinstance(package_import_alias, dict):
          raise TypeError(msg_pkg_import_alias)
      if not all(
          isinstance(x, str) for x in package_import_alias.keys()
      ):
          raise TypeError(msg_pkg_import_alias)
      if not all(
          isinstance(x, str) for x in package_import_alias.values()
      ):
          raise TypeError(msg_pkg_import_alias)
  
      if obj is None:
          class_name = "This functionality"
      elif not isclass(obj):
          class_name = type(obj).__name__
      elif isclass(obj):
          class_name = obj.__name__
      elif isinstance(obj, str):
          class_name = obj
      else:
          raise TypeError(
              "obj argument of _check_soft_dependencies must be a class, an object,"
              " a str, or None, but found obj of type"
              f" {type(obj)}"
          )
  
      if msg is not None and not isinstance(msg, str):
          raise TypeError(
              "msg argument of _check_soft_dependencies must be a str, "
              f"or None, but found msg of type {type(msg)}"
          )
  
      for package in packages:
          try:
              req = Requirement(package)
          except InvalidRequirement:
              msg_version = (
                  f"wrong format for package requirement string "
                  f"passed via packages argument of _check_soft_dependencies, "
                  f'must be PEP 440 compatible requirement string, e.g., "pandas"'
                  f' or "pandas>1.1", but found "{package}"'
              )
              raise InvalidRequirement(msg_version)
  
          package_name = req.name
          package_version_req = req.specifier
  
          # determine the package import
          if package_name in package_import_alias.keys():
              package_import_name = package_import_alias[package_name]
          else:
              package_import_name = package_name
          # attempt import - if not possible, we know we need to raise warning/exception
          try:
              if suppress_import_stdout:
                  # setup text trap, import, then restore
                  sys.stdout = io.StringIO()
                  pkg_ref = import_module(package_import_name)
                  sys.stdout = sys.__stdout__
              else:
                  pkg_ref = import_module(package_import_name)
          # if package cannot be imported, make the user aware of installation requirement
          except ModuleNotFoundError as e:
              if obj is None and msg is None:
                  msg = (
                      f"{e}. '{package}' is a soft dependency and not included in the "
                      f"base sktime installation. Please run: `pip install {package}` to "
                      f"install the {package} package. "
                      f"To install all soft dependencies, run: `pip install "
                      f"sktime[all_extras]`"
                  )
              elif msg is None:  # obj is not None, msg is None
                  msg = (
                      f"{class_name} requires package '{package}' to be present "
                      f"in the python environment, but '{package}' was not found. "
                      f"'{package}' is a soft dependency and not included in the base "
                      f"sktime installation. Please run: `pip install {package}` to "
                      f"install the {package} package. "
                      f"To install all soft dependencies, run: `pip install "
                      f"sktime[all_extras]`"
                  )
              # if msg is not None, none of the above is executed,
              # so if msg is passed it overrides the default messages
  
              if severity == "error":
                  raise ModuleNotFoundError(msg) from e
              elif severity == "warning":
                  warnings.warn(msg, stacklevel=2)
                  return False
              elif severity == "none":
                  return False
              else:
                  raise RuntimeError(
                      "Error in calling _check_soft_dependencies, severity "
                      'argument must be "error", "warning", or "none",'
                      f'found "{severity}".'
                  )
  
          # now we check compatibility with the version specifier if non-empty
          if package_version_req != SpecifierSet(""):
              pkg_env_version = pkg_ref.__version__
  
              msg = (
                  f"{class_name} requires package '{package}' to be present "
                  f"in the python environment, with version {package_version_req}, "
                  f"but incompatible version {pkg_env_version} was found. "
              )
              if obj is not None:
                  msg = msg + (
                      f"This version requirement is not one by sktime, but specific "
                      f"to the module, class or object with name {obj}."
                  )
  
              # raise error/warning or return False if version is incompatible
              if pkg_env_version not in package_version_req:
                  if severity == "error":
                      raise ModuleNotFoundError(msg)
                  elif severity == "warning":
                      warnings.warn(msg, stacklevel=2)
                  elif severity == "none":
                      return False
                  else:
                      raise RuntimeError(
                          "Error in calling _check_soft_dependencies, severity argument"
                          f' must be "error", "warning", or "none", found "{severity}".'
                      )
  
      # if package can be imported and no version issue was caught for any string,
      # then obj is compatible with the requirements and we should return True
      return True
  
file_path: sktime/sktime/utils/validation/_dependencies.py
imports: import io
  import sys
  import warnings
  from importlib import import_module
  from inspect import isclass
  from packaging.requirements import InvalidRequirement, Requirement
  from packaging.specifiers import InvalidSpecifier, SpecifierSet
label_desc: Use image node_id 1 for calling a global function with example usage: _check_soft_dependencies() and returns: True, False, False, False