MCPcopy Index your code
hub / github.com/modelscope/modelscope / PluginsManager

Class PluginsManager

modelscope/utils/plugins.py:761–1207  ·  view source on GitHub ↗

plugins manager class

Source from the content-addressed store, hash-verified

759
760
761class PluginsManager(object):
762 """
763 plugins manager class
764 """
765
766 def __init__(self,
767 cache_dir=MODELSCOPE_FILE_DIR,
768 plugins_file=PLUGINS_FILENAME):
769 cache_dir = os.getenv('MODELSCOPE_CACHE', cache_dir)
770 plugins_file = os.getenv('MODELSCOPE_PLUGINS_FILE', plugins_file)
771 self._file_path = os.path.join(cache_dir, plugins_file)
772
773 @property
774 def file_path(self):
775 return self._file_path
776
777 @file_path.setter
778 def file_path(self, value):
779 self._file_path = value
780
781 @staticmethod
782 def check_plugin_installed(package):
783 """ Check if the plugin is installed, and if the version is valid
784
785 Args:
786 package: the package name need to be installed
787
788 Returns:
789 if_installed: True if installed
790 version: the version of installed or None if not installed
791
792 """
793
794 if package.split('.')[-1] == 'whl':
795 # install from whl should test package name instead of module name
796 _, module_version, package_name = get_modules_from_package(package)
797 local_installed, version = PluginsManager._check_plugin_installed(
798 package_name)
799 if local_installed and module_version != version:
800 return False, version
801 elif not local_installed:
802 return False, version
803 return True, module_version
804 else:
805 return PluginsManager._check_plugin_installed(package)
806
807 @staticmethod
808 def _check_plugin_installed(package, verified_version=None):
809 from packaging.requirements import Requirement
810 req = Requirement(package)
811
812 try:
813 # Ensure newly installed packages are discoverable
814 importlib.invalidate_caches()
815 dist = importlib.metadata.distribution(req.name)
816 version = dist.version
817
818 # To test if the package is installed

Callers 4

plugins.pyFile · 0.90
setUpMethod · 0.90
setUpMethod · 0.90

Calls

no outgoing calls

Tested by 2

setUpMethod · 0.72
setUpMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…