feat: project can loads plugins from external deps
This commit is contained in:
		
							parent
							
								
									0f7a5f6502
								
							
						
					
					
						commit
						0396c8165a
					
				
					 1 changed files with 14 additions and 9 deletions
				
			
		| 
						 | 
				
			
			@ -1,7 +1,7 @@
 | 
			
		|||
import os
 | 
			
		||||
import logging
 | 
			
		||||
 | 
			
		||||
from cutekit import shell, project
 | 
			
		||||
from cutekit import shell, project, const, context
 | 
			
		||||
 | 
			
		||||
import importlib.util as importlib
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -23,16 +23,21 @@ def loadAll():
 | 
			
		|||
    logger.info("Loading plugins...")
 | 
			
		||||
 | 
			
		||||
    projectRoot = project.root()
 | 
			
		||||
    pj = context.loadProject(projectRoot)
 | 
			
		||||
    paths = list(map(lambda e: os.path.join(const.EXTERN_DIR, e),  pj.extern.keys())) + ["."]
 | 
			
		||||
 | 
			
		||||
    if projectRoot is None:
 | 
			
		||||
        logger.info("Not in project, skipping plugin loading")
 | 
			
		||||
        return
 | 
			
		||||
    
 | 
			
		||||
    pluginDir = os.path.join(projectRoot, "meta/plugins")
 | 
			
		||||
 | 
			
		||||
    for files in shell.readdir(pluginDir):
 | 
			
		||||
        if files.endswith(".py"):
 | 
			
		||||
            plugin = load(os.path.join(pluginDir, files))
 | 
			
		||||
    for dirname in paths:
 | 
			
		||||
        pluginDir = os.path.join(projectRoot, dirname, const.META_DIR, "plugins")
 | 
			
		||||
 | 
			
		||||
        for files in shell.readdir(pluginDir):
 | 
			
		||||
            if files.endswith(".py"):
 | 
			
		||||
                plugin = load(os.path.join(pluginDir, files))
 | 
			
		||||
 | 
			
		||||
                if plugin:
 | 
			
		||||
                    logger.info(f"Loaded plugin {plugin.name}")
 | 
			
		||||
                    plugin.init()
 | 
			
		||||
 | 
			
		||||
            if plugin:
 | 
			
		||||
                print(f"Loaded plugin {plugin.name}")
 | 
			
		||||
                plugin.init()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue