fix: check plugin if script is in same directory as __init__.py
This commit is contained in:
		
							parent
							
								
									df7bfb7c3f
								
							
						
					
					
						commit
						c2510da0ca
					
				
					 1 changed files with 8 additions and 7 deletions
				
			
		|  | @ -1,6 +1,7 @@ | ||||||
| import inspect | import inspect | ||||||
| import sys | import sys | ||||||
| 
 | 
 | ||||||
|  | from pathlib import Path | ||||||
| from typing import Optional, Union, Callable | from typing import Optional, Union, Callable | ||||||
| from dataclasses import dataclass | from dataclasses import dataclass | ||||||
| 
 | 
 | ||||||
|  | @ -80,19 +81,19 @@ class Command: | ||||||
| commands: list[Command] = [] | commands: list[Command] = [] | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def append(command: Command): |  | ||||||
|     command.isPlugin = True |  | ||||||
|     commands.append(command) |  | ||||||
|     commands.sort(key=lambda c: c.shortName or c.longName) |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| def command(shortName: Optional[str], longName: str, helpText: str): | def command(shortName: Optional[str], longName: str, helpText: str): | ||||||
|     curframe = inspect.currentframe() |     curframe = inspect.currentframe() | ||||||
|     calframe = inspect.getouterframes(curframe, 2) |     calframe = inspect.getouterframes(curframe, 2) | ||||||
| 
 | 
 | ||||||
|     def wrap(fn: Callable[[Args], None]): |     def wrap(fn: Callable[[Args], None]): | ||||||
|         commands.append( |         commands.append( | ||||||
|             Command(shortName, longName, helpText, calframe[1].filename != __file__, fn) |             Command( | ||||||
|  |                 shortName, | ||||||
|  |                 longName, | ||||||
|  |                 helpText, | ||||||
|  |                 Path(calframe[1].filename).parent != Path(__file__).parent, | ||||||
|  |                 fn, | ||||||
|  |             ) | ||||||
|         ) |         ) | ||||||
|         return fn |         return fn | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue