Skip to content

Commit

Permalink
More updates across the file
Browse files Browse the repository at this point in the history
Signed-off-by: BryceGattis <brycegattis@yahoo.com>
  • Loading branch information
BryceGattis committed May 6, 2024
1 parent 09058d4 commit 180920a
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/rez/plugin_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import os.path
import sys
from types import ModuleType
from typing import Dict, List, Optional, Type
from typing import Dict, ItemsView, List, KeysView, Optional, Type
from zipimport import zipimporter

from rez.config import config, expand_system_vars, _load_config_from_filepaths
Expand Down Expand Up @@ -209,15 +209,15 @@ def load_plugins(self):
data, _ = _load_config_from_filepaths([os.path.join(path, "rezconfig")])
deep_update(self.config_data, data)

def get_plugin_class(self, plugin_name):
def get_plugin_class(self, plugin_name: str) -> Type[object]:
"""Returns the class registered under the given plugin name."""
try:
return self.plugin_classes[plugin_name]
except KeyError:
raise RezPluginError("Unrecognised %s plugin: '%s'"
% (self.pretty_type_name, plugin_name))

def get_plugin_module(self, plugin_name):
def get_plugin_module(self, plugin_name: str) -> ModuleType:
"""Returns the module containing the plugin of the given name."""
try:
return self.plugin_modules[plugin_name]
Expand All @@ -239,9 +239,9 @@ def config_schema(self) -> Schema:
deep_update(d, d_)
return dict_to_schema(d, required=True, modifier=expand_system_vars)

def create_instance(self, plugin, **instance_kwargs) -> "RezPluginType":
def create_instance(self, plugin_name: str, **instance_kwargs) -> object:
"""Create and return an instance of the given plugin."""
return self.get_plugin_class(plugin)(**instance_kwargs)
return self.get_plugin_class(plugin_name)(**instance_kwargs)


class RezPluginManager(object):
Expand Down Expand Up @@ -340,31 +340,31 @@ def _get_plugin_type(self, plugin_type: str) -> RezPluginType:
raise RezPluginError("Unrecognised plugin type: '%s'"
% plugin_type)

def register_plugin_type(self, type_class):
def register_plugin_type(self, type_class: RezPluginType):
if not issubclass(type_class, RezPluginType):
raise TypeError("'type_class' must be a RezPluginType sub class")
if type_class.type_name is None:
raise TypeError("Subclasses of RezPluginType must provide a "
"'type_name' attribute")
self._plugin_types[type_class.type_name] = LazySingleton(type_class)

def get_plugin_types(self):
def get_plugin_types(self) -> KeysView[str]:
"""Return a list of the registered plugin types."""
return self._plugin_types.keys()

# -- plugins

def get_plugins(self, plugin_type):
def get_plugins(self, plugin_type: str) -> KeysView[str]:
"""Return a list of the registered names available for the given plugin
type."""
return self._get_plugin_type(plugin_type).plugin_classes.keys()

def get_plugin_class(self, plugin_type, plugin_name):
def get_plugin_class(self, plugin_type: str, plugin_name: str) -> Type[object]:
"""Return the class registered under the given plugin name."""
plugin = self._get_plugin_type(plugin_type)
return plugin.get_plugin_class(plugin_name)

def get_plugin_module(self, plugin_type, plugin_name):
def get_plugin_module(self, plugin_type: str, plugin_name: str) -> ModuleType:
"""Return the module defining the class registered under the given
plugin name."""
plugin = self._get_plugin_type(plugin_type)
Expand All @@ -375,11 +375,11 @@ def get_plugin_config_data(self, plugin_type: str) -> Dict[str, Dict]:
plugin = self._get_plugin_type(plugin_type)
return plugin.config_data

def get_plugin_config_schema(self, plugin_type):
def get_plugin_config_schema(self, plugin_type: str) -> Schema:
plugin = self._get_plugin_type(plugin_type)
return plugin.config_schema

def get_failed_plugins(self, plugin_type):
def get_failed_plugins(self, plugin_type: str) -> ItemsView[str, str]:
"""Return a list of plugins for the given type that failed to load.
Returns:
Expand All @@ -389,12 +389,12 @@ def get_failed_plugins(self, plugin_type):
"""
return self._get_plugin_type(plugin_type).failed_plugins.items()

def create_instance(self, plugin_type, plugin_name, **instance_kwargs):
def create_instance(self, plugin_type: str, plugin_name: str, **instance_kwargs) -> object:
"""Create and return an instance of the given plugin."""
plugin_type = self._get_plugin_type(plugin_type)
return plugin_type.create_instance(plugin_name, **instance_kwargs)

def get_summary_string(self):
def get_summary_string(self) -> str:
"""Get a formatted string summarising the plugins that were loaded."""
rows = [["PLUGIN TYPE", "NAME", "DESCRIPTION", "STATUS"],
["-----------", "----", "-----------", "------"]]
Expand Down

0 comments on commit 180920a

Please sign in to comment.