fix: check plugin if script is in same directory as __init__.py

This commit is contained in:
Jordan ⌨️ 2023-11-13 20:37:41 +01:00 committed by VAN BOSSUYT Nicolas
parent df7bfb7c3f
commit c2510da0ca

View file

@ -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