Spaces:
Running
Running
Download src/core/plugins/entrypoints.py from Leon4gr45/brain: direct link, hf CLI and curl.
- Browser
- Download file 1.06 kB
-
https://huggingface.co/spaces/Leon4gr45/brain/resolve/main/src/core/plugins/entrypoints.py
- Command line
-
hf download hf://spaces/Leon4gr45/brain/src/core/plugins/entrypoints.py
-
curl -L -o entrypoints.py https://huggingface.co/spaces/Leon4gr45/brain/resolve/main/src/core/plugins/entrypoints.py
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 | |