code: def detect():
      
  
      # Load plugins and config
      plugins = load()
      config = Config()
  
      # Make sure that all sections have a valid plugin type defined
      for section in config.sections():
          if section == 'general':
              continue
          try:
              type_ = config.item(section, 'type')
          except ConfigError:
              raise ConfigError(
                  "Plugin type not defined in section '{0}'.".format(section))
          if type_ not in plugins:
              raise ConfigError(
                  "Invalid plugin type '{0}' in section '{1}'.".format(
                      type_, section))
  
      # Detect classes inherited from StatsGroup and return them sorted
      stats = []
      for plugin in plugins:
          module = getattr(PLUGINS, plugin)
          for object_name in dir(module):
              statsgroup = getattr(module, object_name)
              # Filter out anything except for StatsGroup descendants
              if (not isinstance(statsgroup, (type, types.ClassType))
                      or not issubclass(statsgroup, StatsGroup)
                      or statsgroup is StatsGroup
                      or statsgroup is EmptyStatsGroup):
                  continue
              # Search config for sections with type matching the plugin,
              # use order provided there or class default otherwise
              for section in config.sections(kind=plugin):
                  try:
                      order = int(config.item(section, "order"))
                  except ConfigError:
                      order = statsgroup.order
                  except ValueError:
                      log.warn("Invalid {0} stats order: '{1}'".format(
                          section, config.item(section, "order")))
                      order = statsgroup.order
                  stats.append((section, statsgroup, order))
                  log.info("Found {0}, an instance of {1}, order {2}".format(
                      section, statsgroup.__name__, order))
                  # Custom stats are handled with a single instance
                  if statsgroup.__name__ == "CustomStats":
                      break
      for section, statsgroup, _ in sorted(stats, key=lambda x: x[2]):
          yield section, statsgroup
docs: Detect available plugins and return enabled/configured stats
  
      Yields tuples of the form (section, statsgroup) sorted by the
      default StatsGroup order which maybe overriden in the config
      file. The 'section' is the name of the configuration section
      as well as the option used to enable those particular stats.