feat: Plugins system allows __init__.py for relative imports
This commit is contained in:
		
							parent
							
								
									d8b7a1630c
								
							
						
					
					
						commit
						fafcfbca48
					
				
					 1 changed files with 10 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -1,5 +1,6 @@
 | 
			
		|||
import os
 | 
			
		||||
import logging
 | 
			
		||||
import os
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
from . import shell, model, const
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -17,6 +18,7 @@ def load(path: str):
 | 
			
		|||
        return None
 | 
			
		||||
 | 
			
		||||
    module = importlib.module_from_spec(spec)
 | 
			
		||||
    sys.modules["plugin"] = module
 | 
			
		||||
    spec.loader.exec_module(module)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -33,7 +35,11 @@ def loadAll():
 | 
			
		|||
 | 
			
		||||
    for dirname in paths:
 | 
			
		||||
        pluginDir = os.path.join(project.dirname(), dirname, const.META_DIR, "plugins")
 | 
			
		||||
        initFile = os.path.join(pluginDir, "__init__.py")
 | 
			
		||||
 | 
			
		||||
        if os.path.isfile(initFile):
 | 
			
		||||
            load(initFile)
 | 
			
		||||
        else:
 | 
			
		||||
            for files in shell.readdir(pluginDir):
 | 
			
		||||
                if files.endswith(".py"):
 | 
			
		||||
                    load(os.path.join(pluginDir, files))
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue