@@ -10,9 +10,9 @@ pip install monkay
1010
1111### Usage
1212
13- Probably in the main ` __init__.py ` you define something like this:
13+ Probably you define something like this:
1414
15- ``` python
15+ ``` python title="foo/__init__.py"
1616from monkay import Monkay
1717
1818monkay = Monkay(
@@ -40,7 +40,18 @@ monkay = Monkay(
4040)
4141```
4242
43- When providing your own ` __all__ ` variable ** after** providing Monkay or you want more controll, you can provide
43+ ``` python title="foo/main.py"
44+ from foo import monkay
45+ def get_application ():
46+ # sys.path updates
47+ important_preloads = [... ]
48+ monkay.evaluate_preloads(important_preloads, ignore_import_errors = False )
49+ extra_preloads = [... ]
50+ monkay.evaluate_preloads(extra_preloads)
51+ monkay.evaluate_settings()
52+ ```
53+
54+ When providing your own ` __all__ ` variable ** after** providing Monkay or you want more control, you can provide
4455
4556` skip_all_update=True `
4657
@@ -49,8 +60,7 @@ and update the `__all__` value via `Monkay.update_all_var` if wanted.
4960!!! Warning
5061 There is a catch when using ` settings_preloads_name ` and/or ` settings_preloads_name ` .
5162 It is easy to run in circular dependency errors.
52- For fixing the initialization the errors are by default catched and ignored.
53- But this means, you have to apply them later via ` evaluate_settings_once ` later.
63+ But this means, you have to apply them later via ` evaluate_settings ` later.
5464 For more informations see [ Settings preloads and/or extensions] ( #settings-extensions-andor-preloads )
5565
5666
@@ -128,6 +138,17 @@ class Settings(BaseSettings):
128138 extensions: list[Any] = []
129139```
130140
141+ ``` python title="main.py"
142+
143+ def get_application ():
144+ # initialize the loaders/sys.path
145+ # add additional preloads
146+ monkay.evaluate_preloads(... )
147+ monkay.evaluate_settings()
148+
149+ app = get_application()
150+ ```
151+
131152And voila settings are now available from monkay.settings as well as settings. This works only when all settings arguments are
132153set via environment or defaults.
133154Note the ` uncached_imports ` . Because temporary overwrites should be possible, we should not cache this import. The settings
@@ -197,12 +218,11 @@ get_value_from_settings(monkay.settings, "foo")
197218```
198219#### Settings extensions and/or preloads
199220
200- When using ` settings_preloads_name ` and/or ` settings_extensions_name ` it is easy to run in circular dependency issues
201- especcially with ` pydantic_settings ` .
202- For mitigating this such import errors are catched and silenced in init.
221+ When using ` settings_preloads_name ` and/or ` settings_extensions_name ` we need to call in the setup of the application
222+ ` evaluate_settings() ` . Otherwise we may would end up with circular depdendencies, missing imports and wrong library versions.
203223
204224This means however the preloads are not loaded as well the extensions initialized.
205- For initializing it later, we need ` evaluate_settings_once ` .
225+ For initializing it later, we need ` evaluate_settings ` .
206226
207227Wherever the settings are expected we can add it.
208228
@@ -214,7 +234,7 @@ from functools import lru_cache
214234@lru_cache
215235def get_edgy ():
216236 import edgy
217- edgy.monkay.evaluate_settings_once( )
237+ edgy.monkay.evaluate_settings( ignore_import_errors = False )
218238 return edgy
219239
220240class SettingsForward :
228248``` python title="foo/main.py"
229249def get_application ():
230250 import foo
231- foo.monkay.evaluate_settings_once (ignore_import_errors = False )
251+ foo.monkay.evaluate_settings (ignore_import_errors = False )
232252 app = App()
233253
234254 foo.monkay.set_instance(app)
@@ -237,15 +257,11 @@ def get_application():
237257app = get_application()
238258```
239259
240- For performance reasons you may want to skip to try to import the settings in init:
241-
242- ` evaluate_settings=False ` will disable the evaluation.
243-
244260You may want to not silence the import error like in monkay ` <0.2.0 ` , then pass
245261
246262` ignore_settings_import_errors=False ` to the init.
247263
248- More information can be found in [ Settings ` evaluate_settings_once ` ] ( ./settings.md#evaluate_settings_once -method )
264+ More information can be found in [ Settings ` evaluate_settings ` ] ( ./settings.md#evaluate_settings -method )
249265
250266#### Pathes
251267
@@ -278,14 +294,18 @@ class Settings(BaseSettings):
278294 preloads: list[str ] = [" preloader:preloader" ]
279295```
280296
297+ !!! Warning
298+ Settings preloads are only executed after executing ` evaluate_settings() ` . Preloads given in the ` __init__ ` are evaluated instantly.
299+ You can however call ` evaluate_preloads ` directly.
300+
301+
281302#### Using the instance feature
282303
283304The instance feature is activated by providing a boolean (or a string for an explicit name) to the ` with_instance `
284305parameter.
285306
286307For entrypoints you can set now the instance via ` set_instance ` . A good entrypoint is the init and using the settings:
287308
288-
289309``` python title="__init__.py"
290310import os
291311from monkay import Monkay, load
@@ -299,6 +319,7 @@ monkay = Monkay(
299319 settings_extensions_name = " extensions" ,
300320)
301321
322+ monkay.evaluate_settings()
302323monkay.set_instance(load(settings.APP_PATH ))
303324```
304325
@@ -340,7 +361,6 @@ class Settings(BaseSettings):
340361 preloads: list[str ] = [" preloader:preloader" ]
341362 extensions: list[Any] = [Extension]
342363 APP_PATH : str = " settings.App"
343-
344364```
345365
346366##### Reordering extension order dynamically
@@ -358,7 +378,6 @@ via the parameter `extension_order_key_fn`. It takes a key function which is exp
358378
359379You can however intermix both.
360380
361-
362381## Tricks
363382
364383### Type-checker friendly lazy imports
@@ -385,15 +404,13 @@ monkay = Monkay(
385404)
386405```
387406
388-
389407### Static ` __all__ `
390408
391409For autocompletions it is helpful to have a static ` __all__ ` variable because many tools parse the sourcecode.
392410Handling the ` __all__ ` manually is for small imports easy but for bigger projects problematic.
393411
394412Let's extend the former example:
395413
396-
397414``` python
398415
399416import os
0 commit comments