Spaces:
Running
Running
File size: 1,058 Bytes
e70c280 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | 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
|