refactor: add static source provider seam
This commit is contained in:
@@ -1,9 +1,15 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from .loader import PythonSourceConfigLike, load_python_source, python_capability_source
|
||||
from .loader import (
|
||||
PythonSourceConfigLike,
|
||||
PythonSourceProvider,
|
||||
load_python_source,
|
||||
python_capability_source,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"PythonSourceConfigLike",
|
||||
"PythonSourceProvider",
|
||||
"load_python_source",
|
||||
"python_capability_source",
|
||||
]
|
||||
|
||||
@@ -2,6 +2,7 @@ from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from collections.abc import Mapping, Sequence
|
||||
from dataclasses import dataclass
|
||||
from importlib import import_module
|
||||
from pathlib import Path
|
||||
from typing import Any, Protocol
|
||||
@@ -23,6 +24,16 @@ class PythonSourceConfigLike(Protocol):
|
||||
enabled: bool
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class PythonSourceProvider:
|
||||
"""Static source provider for trusted Python source config entries."""
|
||||
|
||||
configs: Sequence[PythonSourceConfigLike]
|
||||
|
||||
def load_sources(self) -> Mapping[str, CapabilitySource]:
|
||||
return {config.id: python_capability_source(config) for config in self.configs}
|
||||
|
||||
|
||||
def load_python_source(
|
||||
*,
|
||||
source_id: str,
|
||||
|
||||
Reference in New Issue
Block a user