simonw--llm
7ca0a9a0b9
Test / test (==1.10.2, 3.10) (push) Has been cancelled
Test / test (==1.10.2, 3.11) (push) Has been cancelled
Test / test (==1.10.2, 3.7) (push) Has been cancelled
Test / test (==1.10.2, 3.8) (push) Has been cancelled
Test / test (==1.10.2, 3.9) (push) Has been cancelled
Test / test (>=2.0.0, 3.10) (push) Has been cancelled
Test / test (>=2.0.0, 3.11) (push) Has been cancelled
Test / test (>=2.0.0, 3.7) (push) Has been cancelled
Test / test (>=2.0.0, 3.8) (push) Has been cancelled
Test / test (>=2.0.0, 3.9) (push) Has been cancelled
32 行
1.2 KiB
Python
32 行
1.2 KiB
Python
import importlib
|
|
import os
|
|
import pkg_resources
|
|
import pluggy
|
|
import sys
|
|
from . import hookspecs
|
|
|
|
pm = pluggy.PluginManager("llm")
|
|
pm.add_hookspecs(hookspecs)
|
|
|
|
LLM_LOAD_PLUGINS = os.environ.get("LLM_LOAD_PLUGINS", None)
|
|
|
|
if not hasattr(sys, "_called_from_test") and LLM_LOAD_PLUGINS is None:
|
|
# Only load plugins if not running tests
|
|
pm.load_setuptools_entrypoints("llm")
|
|
|
|
|
|
# Load any plugins specified in LLM_LOAD_PLUGINS")
|
|
if LLM_LOAD_PLUGINS is not None:
|
|
for package_name in [name for name in LLM_LOAD_PLUGINS.split(",") if name.strip()]:
|
|
try:
|
|
distribution = pkg_resources.get_distribution(package_name)
|
|
entry_map = distribution.get_entry_map()
|
|
if "llm" in entry_map:
|
|
for plugin_name, entry_point in entry_map["llm"].items():
|
|
mod = entry_point.load()
|
|
pm.register(mod, name=entry_point.name)
|
|
# Ensure name can be found in plugin_to_distinfo later:
|
|
pm._plugin_distinfo.append((mod, distribution)) # type: ignore
|
|
except pkg_resources.DistributionNotFound:
|
|
sys.stderr.write("Plugin {} could not be found\n".format(package_name))
|