def _load_plugin_config(self, plugin):
        # Initialize variable to hold plugin config
        json_config = False
        yaml_config = False

        # Attempt to load and parse JSON config file
        file = os.path.join(
            os.path.dirname(os.path.realpath(sys.argv[0])),
            'plugins',
            plugin,
            'config.json'
        )
        try:
            f = open(file, 'r')
            json_config = json.load(f)
            f.close()
        # File did not exist or we can't open it for another reason
        except IOError:
            self.logger.debug(
                "Can't open %s - maybe it doesn't exist?" % file
            )
        # Thrown by json.load() when the content isn't valid JSON
        except ValueError:
            self.logger.warning(
                "Invalid JSON in %s, skipping it" % file
            )

        # Attempt to load and parse YAML config file
        file = os.path.join(
            os.path.dirname(os.path.realpath(sys.argv[0])),
            'plugins',
            plugin,
            'config.yaml'
        )
        try:
            f = open(file, 'r')
            yaml_config = yaml.load(f)
            f.close()
        except IOError:
            self.logger.debug(
                "Can't open %s - maybe it doesn't exist?" % file
            )
        except ValueError:
            self.logger.warning(
                "Invalid YAML in %s, skipping it" % file
            )
        # Loaded YAML successfully
        else:
            # If we already loaded JSON, this is a problem because we won't
            # know which config to use.
            if json_config:
                raise AmbiguousConfigError(
                    "Found both a JSON and YAML config for plugin"
                )

            # No JSON config, found YAML config, return it
            return yaml_config

        # If neither config was found, raise an exception
        if not yaml_config and not json_config:
            raise ConfigNotFoundError(
                "No config found for plugin: %s" % plugin
            )

        # Return JSON config, since YAML config wasn't found
        return json_config
Loads a JSON or YAML config for a given plugin
dataset/ETHPy150Open JohnMaguire/Cardinal/cardinal/plugins.py/PluginManager._load_plugin_config