brain / src /core /plugins /entrypoints.py
Leon4gr45's picture
Upload folder using huggingface_hub (part 2)
e70c280 verified
Raw History Blame Contribute Delete
1.06 kB
from __future__ import annotations
from pathlib import Path
class PluginEntryPointResolver:
def resolve(self, entry_point: str, plugin_dir: Path) -> str:
normalized = entry_point.strip().replace("\\", "/")
if normalized.endswith(".py"):
normalized = normalized[:-3]
normalized = normalized.lstrip("./").strip("/")
module_name = normalized.replace("/", ".")
if module_name.endswith(".__init__"):
module_name = module_name[: -len(".__init__")]
if module_name == "__init__" or module_name == "":
return plugin_dir.name
return module_name
def resolve_path(self, entry_point: str, plugin_dir: Path) -> Path:
normalized = entry_point.strip().replace("\\", "/")
normalized = normalized.lstrip("./").strip("/")
if normalized == "":
return plugin_dir / "__init__.py"
candidate = plugin_dir / normalized
if candidate.suffix != ".py":
candidate = candidate.with_suffix(".py")
return candidate