/
niceSOFT
/
python3-hatchling
Обзор
Документация
Войти
/
niceSOFT
/
python3-hatchling
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/hatch/env/collectors/custom.py
43 строки
1 KB
Dimitri Papadopoulos Orfanos
Upgrade Ruff to 0.13.2 (#1890)
28 сен 2025, 21:20
Не верифицирован
28 сен 2025, 21:20
aff6f39
Код
Авторство
О чём код?
from __future__ import annotations import os from typing import Any from hatch.env.collectors.plugin.interface import EnvironmentCollectorInterface from hatch.plugin.constants import DEFAULT_CUSTOM_SCRIPT from hatch.plugin.utils import load_plugin_from_script class CustomEnvironmentCollector: PLUGIN_NAME = "custom" def __new__( # type: ignore[misc] cls, root: str, config: dict[str, Any], *args: Any, **kwargs: Any, ) -> EnvironmentCollectorInterface: custom_script = config.get("path", DEFAULT_CUSTOM_SCRIPT) if not isinstance(custom_script, str): message = f"Option `path` for environment collector `{cls.PLUGIN_NAME}` must be a string" raise TypeError(message) if not custom_script: message = f"Option `path` for environment collector `{cls.PLUGIN_NAME}` must not be empty if defined" raise ValueError(message) path = os.path.normpath(os.path.join(root, custom_script)) if not os.path.isfile(path): message = f"Plugin script does not exist: {custom_script}" raise OSError(message) hook_class = load_plugin_from_script( path, custom_script, EnvironmentCollectorInterface, "environment_collector" ) hook = hook_class(root, config, *args, **kwargs) # Always keep the name to avoid confusion hook.PLUGIN_NAME = cls.PLUGIN_NAME return hook