You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/service-library/src/servicelib/aiohttp/application_setup.py
+28-18Lines changed: 28 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,6 @@
1
1
importfunctools
2
2
importinspect
3
3
importlogging
4
-
importwarnings
5
4
fromcollections.abcimportCallable
6
5
fromcontextlibimportContextDecorator
7
6
fromcopyimportdeepcopy
@@ -258,27 +257,42 @@ def app_module_setup(
258
257
config_section: str|None=None,
259
258
config_enabled: str|None=None,
260
259
) ->Callable:
261
-
"""Decorator marking a function as a module setup for an application.
262
-
263
-
Ensures one-time execution (idempotent) and tracks setup completion. For addons, setup can be
264
-
toggled via config [deprecated] or settings.
265
-
266
-
:param settings_name: Field name in app settings for this module
267
-
:raises DependencyError: If required dependent modules are not initialized
268
-
:raises ApplicationSetupError: If setup fails
269
-
:return: True if setup completed, False if skipped
260
+
"""Decorator that marks a function as 'a setup function' for a given module in an application
261
+
262
+
- Marks a function as 'setup' of a given module in an application
263
+
- Ensures setup executed ONLY ONCE per app
264
+
- Addon modules:
265
+
- toggles run using 'enabled' entry in config file
266
+
- logs execution
267
+
268
+
See packages/service-library/tests/test_application_setup.py
269
+
270
+
:param module_name: typically __name__
271
+
:param depends: list of module_names that must be called first, defaults to None
272
+
:param config_section: explicit configuration section, defaults to None (i.e. the name of the module, or last entry of the name if dotted)
273
+
:param config_enabled: option in config to enable, defaults to None which is '$(module-section).enabled' (config_section and config_enabled are mutually exclusive)
274
+
:param settings_name: field name in the app's settings that corresponds to this module. Defaults to the name of the module with app prefix.
275
+
:raises DependencyError
276
+
:raises ApplicationSetupError
277
+
:return: True if setup was completed or False if setup was skipped
270
278
:rtype: bool
271
279
272
280
:Example:
281
+
from servicelib.aiohttp.application_setup import app_module_setup
0 commit comments