@@ -20,24 +20,54 @@ or `injectables`, because everything is not yet fully configured at this stage.
2020
2121** Instruction order matters** : each configuration step applies a decorator and returns a new ` Entrypoint ` instance.
2222
23+ Here's all you can do with an entrypoint:
24+
25+ _ Take only what you need._
26+
2327``` python
2428# src/entrypoint.py
2529
30+ from enum import StrEnum, auto
31+
2632import uvloop
27- from injection import adefine_scope
33+ from injection import adefine_scope, mod
2834from injection.entrypoint import AsyncEntrypoint, Entrypoint, entrypointmaker
29- from injection.loaders import PythonModuleLoader
35+ from injection.loaders import ProfileLoader, PythonModuleLoader
36+ from pydantic_settings import BaseSettings
37+
38+ class Profile (StrEnum ):
39+ DEFAULT = mod().name
40+ DEV = " dev"
41+ STAGING = " staging"
42+ PROD = " prod"
43+
44+ class SubProfile (StrEnum ):
45+ CONF = " conf"
46+
47+ class Scope (StrEnum ):
48+ LIFESPAN = auto()
3049
31- @entrypointmaker
32- def entrypoint[** P, T](self : AsyncEntrypoint[P, T]) -> Entrypoint[P, T]:
50+ @mod (SubProfile.CONF ).constant
51+ class Conf (BaseSettings ):
52+ profile: Profile = Profile.DEFAULT
53+
54+ @entrypointmaker (profile_loader = ProfileLoader({Profile.DEFAULT : [SubProfile.CONF ]}))
55+ def entrypoint[** P, T](self : AsyncEntrypoint[P, T], conf: Conf) -> Entrypoint[P, T]:
3356 import src
3457
35- loader = PythonModuleLoader.from_keywords(" # Auto-import" )
58+ profile = conf.profile
59+ keyword = " # auto-import"
60+ keywords = {
61+ f " { keyword} : { name} "
62+ for name in self .profile_loader.required_module_names(profile)
63+ }
64+ module_loader = PythonModuleLoader.from_keywords(keyword, * keywords)
3665 return (
3766 self .inject()
38- .decorate(adefine_scope(" lifespan " , kind = " shared" ))
67+ .decorate(adefine_scope(Scope. LIFESPAN , kind = " shared" ))
3968 .async_to_sync(uvloop.run)
40- .load_modules(loader, src)
69+ .load_modules(module_loader, src)
70+ .load_profile(profile)
4171 )
4272```
4373
0 commit comments