importosimportsysfromimportlib.utilimportfind_specfrom.manifestimportload_plugin_manifestdef_get_project_root():"""Get the absolute path to the project root directory. Returns: str: Absolute path to project root """current_dir=os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))returncurrent_dirdef_find_core_plugin_path(plugin_name):"""Find the correct path for a core plugin, checking both development and installed locations. Args: plugin_name (str): Name of the core plugin Returns: str: Absolute path to the plugin directory or None if not found """# Try development path firstdev_path=os.path.join(_get_project_root(),'coreplugins',plugin_name)ifos.path.exists(dev_path):#print(f"Found core plugin {plugin_name} in development path: {dev_path}")returndev_path# Try to find installed packagetry:importmindrootpkg_path=os.path.dirname(mindroot.__file__)installed_path=os.path.join(pkg_path,'coreplugins',plugin_name)ifos.path.exists(installed_path):print(f"Found core plugin {plugin_name} in installed path: {installed_path}")returninstalled_pathexceptImportError:pass# Try site-packages directlyforpathinsys.path:if'site-packages'inpathor'dist-packages'inpath:potential_path=os.path.join(path,'mindroot','coreplugins',plugin_name)ifos.path.exists(potential_path):print(f"Found core plugin {plugin_name} in site-packages: {potential_path}")returnpotential_pathprint(f"Warning: Could not find core plugin {plugin_name} in any location")returnNone
[docs]defget_plugin_path(plugin_name):"""Get the filesystem path for a plugin. Args: plugin_name (str): Name of the plugin Returns: str: Absolute path to the plugin directory or None if not found """#print(f"Get plugin path: {plugin_name}")manifest=load_plugin_manifest()forcategoryinmanifest['plugins']:ifplugin_nameinmanifest['plugins'][category]:plugin_info=manifest['plugins'][category][plugin_name]ifplugin_info['source']=='core':return_find_core_plugin_path(plugin_name)elifplugin_info['source']in['local','github']:# source_path should already be absoluteifos.path.exists(plugin_info['source_path']):returnplugin_info['source_path']print(f"Warning: Plugin path does not exist: {plugin_info['source_path']}")else:print(f"Calling find_spec to get plugin path for {plugin_name}")spec=find_spec(plugin_name)ifspec:returnspec.originprint(f"Warning: Could not find spec for plugin: {plugin_name}")returnNone
[docs]defget_plugin_import_path(plugin_name):"""Get the Python import path for a plugin. Args: plugin_name (str): Name of the plugin Returns: str: Import path for the plugin or None if not found """manifest=load_plugin_manifest()forcategoryinmanifest['plugins']:ifplugin_nameinmanifest['plugins'][category]:plugin_info=manifest['plugins'][category][plugin_name]ifplugin_info['source']=='core':returnf"coreplugins.{plugin_name}"elifplugin_info['source']in['local','github']:source_path=plugin_info['source_path']ifnotos.path.exists(source_path):print(f"Warning: Plugin path does not exist: {source_path}")returnNoneparent_dir=os.path.dirname(source_path)ifparent_dirnotinsys.path:sys.path.insert(0,parent_dir)returnos.path.basename(source_path)else:spec=find_spec(plugin_name)returnspec.originifspecelseNonereturnNone