Skip to content

Commit 02cc693

Browse files
committed
add support for dynamic configuration via a function call
1 parent a49b097 commit 02cc693

3 files changed

Lines changed: 22 additions & 9 deletions

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
repos:
44
- repo: https://github.com/astral-sh/ruff-pre-commit
55
# Ruff version.
6-
rev: v0.14.8
6+
rev: v0.14.10
77
hooks:
88
# Run the linter.
99
- id: ruff-check
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from .config import configure
1+
from .config import configure, set_config_provider
22

3-
__all__ = ["configure"]
3+
__all__ = ["configure", "set_config_provider"]
Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
import typing
2+
from collections.abc import Callable
23

3-
_config: dict[str, typing.Any] = {
4+
_static_config: dict[str, str | None] = {
45
"data_api_root_url": None,
56
"api_key": None,
67
}
78

9+
_config_provider: Callable[[], dict[str, str | None]] | None = None
10+
811

912
def configure(data_api_root_url: str, api_key: str) -> None:
10-
"""Configure the Bubble Data API client."""
11-
_config["data_api_root_url"] = data_api_root_url
12-
_config["api_key"] = api_key
13+
"""Configure the Bubble Data API client with static values."""
14+
global _config_provider
15+
_config_provider = None
16+
_static_config["data_api_root_url"] = data_api_root_url
17+
_static_config["api_key"] = api_key
18+
19+
20+
def set_config_provider(provider: Callable[[], dict[str, str | None]]) -> None:
21+
"""Set a provider function for dynamic configuration."""
22+
global _config_provider
23+
_config_provider = provider
1324

1425

1526
def get_config() -> typing.Mapping[str, str | None]:
16-
"""Get the current configuration."""
17-
return _config
27+
"""Get current configuration from provider if set, otherwise static config."""
28+
if _config_provider is not None:
29+
return _config_provider()
30+
return _static_config

0 commit comments

Comments
 (0)