Merge pull request #24706 from akhilnarang/hook-extend-conf

feat: allow extending site config with a hook
This commit is contained in:
mergify[bot] 2024-02-05 08:04:12 +00:00 committed by GitHub
commit a042b0da66
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -17,6 +17,7 @@ import inspect
import json
import os
import re
import traceback
import warnings
from collections.abc import Callable
from typing import TYPE_CHECKING, Any, Literal, Optional, TypeAlias, overload
@ -435,6 +436,18 @@ def get_site_config(sites_path: str | None = None, site_path: str | None = None)
os.environ.get("FRAPPE_DB_USER") or config.get("db_user") or config.get("db_name")
)
# Allow externally extending the config with hooks
if extra_config := config.get("extra_config"):
if isinstance(extra_config, str):
extra_config = [extra_config]
for hook in extra_config:
try:
module, method = hook.rsplit(".", 1)
config |= getattr(importlib.import_module(module), method)()
except Exception:
print(f"Config hook {hook} failed")
traceback.print_exc()
return config