austial-config 0.1.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- austial_config-0.1.5/.gitignore +11 -0
- austial_config-0.1.5/PKG-INFO +8 -0
- austial_config-0.1.5/pyproject.toml +27 -0
- austial_config-0.1.5/src/austial/config/__init__.py +4 -0
- austial_config-0.1.5/src/austial/config/config_module.py +31 -0
- austial_config-0.1.5/src/austial/config/config_service.py +22 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: austial-config
|
|
3
|
+
Version: 0.1.5
|
|
4
|
+
Summary: ConfigModule/ConfigService for .env-backed configuration -- mirrors @nestjs/config (no main-monorepo equivalent).
|
|
5
|
+
Requires-Python: >=3.11
|
|
6
|
+
Requires-Dist: austial-common
|
|
7
|
+
Requires-Dist: austial-core
|
|
8
|
+
Requires-Dist: pydantic-settings>=2.4.0
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "austial-config"
|
|
3
|
+
dynamic = ["version"]
|
|
4
|
+
description = "ConfigModule/ConfigService for .env-backed configuration -- mirrors @nestjs/config (no main-monorepo equivalent)."
|
|
5
|
+
requires-python = ">=3.11"
|
|
6
|
+
dependencies = [
|
|
7
|
+
"austial-common",
|
|
8
|
+
"austial-core",
|
|
9
|
+
"pydantic-settings>=2.4.0",
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
[build-system]
|
|
13
|
+
requires = ["hatchling", "hatch-vcs"]
|
|
14
|
+
build-backend = "hatchling.build"
|
|
15
|
+
|
|
16
|
+
[tool.hatch.build.targets.wheel]
|
|
17
|
+
packages = ["src/austial"]
|
|
18
|
+
|
|
19
|
+
[tool.uv.sources]
|
|
20
|
+
austial-common = { workspace = true }
|
|
21
|
+
austial-core = { workspace = true }
|
|
22
|
+
|
|
23
|
+
[tool.hatch.version]
|
|
24
|
+
source = "vcs"
|
|
25
|
+
|
|
26
|
+
[tool.hatch.version.raw-options]
|
|
27
|
+
root = "../.."
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""``ConfigModule`` -- mirrors ``@nestjs/config``'s ``ConfigModule.forRoot()``."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
from austial.common.decorators.modules import Module
|
|
8
|
+
from austial.config.config_service import ConfigService
|
|
9
|
+
from austial.core.dynamic_module import DynamicModule
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@Module()
|
|
13
|
+
class ConfigModule:
|
|
14
|
+
"""Import via ``ConfigModule.for_root()`` in ``AppModule``'s ``imports=[...]``,
|
|
15
|
+
exactly like Nest's ``ConfigModule.forRoot()``."""
|
|
16
|
+
|
|
17
|
+
@staticmethod
|
|
18
|
+
def for_root(env_file: str = ".env", *, is_global: bool = True) -> DynamicModule:
|
|
19
|
+
try:
|
|
20
|
+
from dotenv import load_dotenv
|
|
21
|
+
|
|
22
|
+
load_dotenv(env_file, override=False)
|
|
23
|
+
except ImportError: # pragma: no cover - python-dotenv ships with pydantic-settings
|
|
24
|
+
pass
|
|
25
|
+
|
|
26
|
+
service = ConfigService(dict(os.environ))
|
|
27
|
+
return DynamicModule(
|
|
28
|
+
module=ConfigModule,
|
|
29
|
+
providers=[{"provide": ConfigService, "useValue": service}],
|
|
30
|
+
exports=[ConfigService],
|
|
31
|
+
)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""``ConfigService`` -- mirrors ``@nestjs/config``'s ``ConfigService``."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from austial.common.decorators.injectable import Injectable
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@Injectable()
|
|
12
|
+
class ConfigService:
|
|
13
|
+
def __init__(self, env: dict | None = None):
|
|
14
|
+
self._env = env if env is not None else dict(os.environ)
|
|
15
|
+
|
|
16
|
+
def get(self, key: str, default: Any = None) -> Any:
|
|
17
|
+
return self._env.get(key, default)
|
|
18
|
+
|
|
19
|
+
def get_or_throw(self, key: str) -> Any:
|
|
20
|
+
if key not in self._env:
|
|
21
|
+
raise KeyError(f"Configuration key '{key}' is not defined")
|
|
22
|
+
return self._env[key]
|