Coverage for .nox/test-3-9/lib/python3.9/site-packages/nskit/mixer/components/hook.py: 100%
13 statements
« prev ^ index » next coverage.py v7.4.2, created at 2024-02-25 17:38 +0000
« prev ^ index » next coverage.py v7.4.2, created at 2024-02-25 17:38 +0000
1"""Hook component."""
2from abc import ABC, abstractmethod
3from pathlib import Path
4from typing import Any, Dict, Optional, Tuple
6from pydantic import BaseModel
9class Hook(ABC, BaseModel):
10 """Hook component."""
12 @abstractmethod
13 def call(self, recipe_path: Path, context: Dict[str, Any]) -> Optional[Tuple[str, Path, Dict]]:
14 """Return None or tuple (recipe_path, context)."""
15 raise NotImplementedError()
17 def __call__(self, recipe_path: Path, context: Dict[str, Any]) -> Tuple[str, Path, Dict]:
18 """Call the hook and return tuple (recipe_path, context)."""
19 hook_result = self.call(recipe_path, context)
20 if hook_result:
21 recipe_path, context = hook_result
22 return recipe_path, context