Skip to content

Commit

Permalink
app: add init_functions_loader
Browse files Browse the repository at this point in the history
* allows to pass entry points to execute
  functions just after the app is instantiated
* closes inveniosoftware#171
  • Loading branch information
jrcastro2 committed Jan 13, 2023
1 parent 0495114 commit 193aabd
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions invenio_base/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def create_app_factory(
blueprints=None,
converter_entry_points=None,
converters=None,
init_functions_entry_points=None,
wsgi_factory=None,
**app_kwargs,
):
Expand Down Expand Up @@ -125,6 +126,13 @@ def _create_app(**kwargs):
entry_points=blueprint_entry_points,
modules=blueprints,
)

# Load init functions
init_functions_loader(
app,
entry_points=init_functions_entry_points,
)


app_loaded.send(_create_app, app=app)

Expand Down Expand Up @@ -178,6 +186,20 @@ def cli(**params):
return cli


def init_functions_loader(app, entry_points=None):
"""Run functions that should be executed after the application is instantiated.
:param entry_points: List of entry points providing to Flask extensions.
.. versionadded: 2.0.0
"""
def loader_init_func(func):
with app.app_context():
func(app)

_loader(app, loader_init_func, entry_points=entry_points)


def app_loader(app, entry_points=None, modules=None):
"""Run default application loader.
Expand Down

0 comments on commit 193aabd

Please sign in to comment.