feat: referentiel projets dynamique + validation nommage by design
Durcit la convention de nommage des projets (dérive constatée : 'Sliding Automation', 'code_versioning'... au lieu des formes canoniques). - trilium_api.py : projets_canoniques() lit le référentiel = valeurs du label projet sur les notes de type=projet (source unique, pas de constante en dur). Note-projet CodeVersioning créée (manquait). - mcp_server.py : _valider_projet() branché dans les 6 tools de création (add_decision/history/backlog, new_conversation, create_entite, add_skill). Refuse un projet non canonique (suggestion si faute) ou inconnu (renvoi au processus de création de projet). Ne verrouille pas si référentiel illisible. - lint_audit.py : VAL-nommage aligné sur le référentiel (attrape casse, espace ET snake_case ; l'ancien 'contient un espace' ratait code_versioning). - Données : 79 notes ré-étiquetées vers les 3 formes canoniques. Quality by design : l'erreur de nommage devient impossible à l'écriture, le Lint n'est plus que le filet de sécurité.
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.metadata as importlib_metadata
|
||||
import os
|
||||
import warnings
|
||||
from collections.abc import Iterable
|
||||
from typing import TYPE_CHECKING, Final
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from . import PydanticPluginProtocol
|
||||
|
||||
|
||||
PYDANTIC_ENTRY_POINT_GROUP: Final[str] = 'pydantic'
|
||||
|
||||
# cache of plugins
|
||||
_plugins: dict[str, PydanticPluginProtocol] | None = None
|
||||
# return no plugins while loading plugins to avoid recursion and errors while importing plugins
|
||||
# this means that if plugins use pydantic
|
||||
_loading_plugins: bool = False
|
||||
|
||||
|
||||
def get_plugins() -> Iterable[PydanticPluginProtocol]:
|
||||
"""Load plugins for Pydantic.
|
||||
|
||||
Inspired by: https://github.com/pytest-dev/pluggy/blob/1.3.0/src/pluggy/_manager.py#L376-L402
|
||||
"""
|
||||
disabled_plugins = os.getenv('PYDANTIC_DISABLE_PLUGINS')
|
||||
global _plugins, _loading_plugins
|
||||
if _loading_plugins:
|
||||
# this happens when plugins themselves use pydantic, we return no plugins
|
||||
return ()
|
||||
elif disabled_plugins in ('__all__', '1', 'true'):
|
||||
return ()
|
||||
elif _plugins is None:
|
||||
_plugins = {}
|
||||
# set _loading_plugins so any plugins that use pydantic don't themselves use plugins
|
||||
_loading_plugins = True
|
||||
try:
|
||||
for dist in importlib_metadata.distributions():
|
||||
for entry_point in dist.entry_points:
|
||||
if entry_point.group != PYDANTIC_ENTRY_POINT_GROUP:
|
||||
continue
|
||||
if entry_point.value in _plugins:
|
||||
continue
|
||||
if disabled_plugins is not None and entry_point.name in disabled_plugins.split(','):
|
||||
continue
|
||||
try:
|
||||
_plugins[entry_point.value] = entry_point.load()
|
||||
except (ImportError, AttributeError) as e:
|
||||
warnings.warn(
|
||||
f'{e.__class__.__name__} while loading the `{entry_point.name}` Pydantic plugin, '
|
||||
f'this plugin will not be installed.\n\n{e!r}',
|
||||
stacklevel=2,
|
||||
)
|
||||
finally:
|
||||
_loading_plugins = False
|
||||
|
||||
return _plugins.values()
|
||||
Reference in New Issue
Block a user