Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init: move record_once to finalize_app #258

Merged
merged 3 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions invenio_vocabularies/ext.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2020-2022 CERN.
# Copyright (C) 2023 Graz University of Technology.
#
# Invenio-Vocabularies is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
Expand Down Expand Up @@ -123,3 +124,41 @@ def init_resource(self, app):
service=self.service,
config=app.config["VOCABULARIES_RESOURCE_CONFIG"],
)


def finalize_app(app):
"""Finalize app.

NOTE: replace former @record_once decorator
"""
init(app)


def api_finalize_app(app):
"""Api Finalize app.

NOTE: replace former @record_once decorator
"""
init(app)


def init(app):
"""Init app."""
# Register services - cannot be done in extension because
# Invenio-Records-Resources might not have been initialized.
sregistry = app.extensions["invenio-records-resources"].registry
ext = app.extensions["invenio-vocabularies"]
sregistry.register(ext.affiliations_service, service_id="affiliations")
sregistry.register(ext.awards_service, service_id="awards")
sregistry.register(ext.funders_service, service_id="funders")
sregistry.register(ext.names_service, service_id="names")
sregistry.register(ext.subjects_service, service_id="subjects")
sregistry.register(ext.service, service_id="vocabularies")
# Register indexers
iregistry = app.extensions["invenio-indexer"].registry
iregistry.register(ext.affiliations_service.indexer, indexer_id="affiliations")
iregistry.register(ext.awards_service.indexer, indexer_id="awards")
iregistry.register(ext.funders_service.indexer, indexer_id="funders")
iregistry.register(ext.names_service.indexer, indexer_id="names")
iregistry.register(ext.subjects_service.indexer, indexer_id="subjects")
iregistry.register(ext.service.indexer, indexer_id="vocabularies")
25 changes: 1 addition & 24 deletions invenio_vocabularies/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2020-2022 CERN.
# Copyright (C) 2023 Graz University of Technology.
#
# Invenio-Vocabularies is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
Expand All @@ -13,30 +14,6 @@
blueprint = Blueprint("invenio_vocabularies_ext", __name__)


@blueprint.record_once
def init(state):
"""Init app."""
app = state.app
# Register services - cannot be done in extension because
# Invenio-Records-Resources might not have been initialized.
sregistry = app.extensions["invenio-records-resources"].registry
ext = app.extensions["invenio-vocabularies"]
sregistry.register(ext.affiliations_service, service_id="affiliations")
sregistry.register(ext.awards_service, service_id="awards")
sregistry.register(ext.funders_service, service_id="funders")
sregistry.register(ext.names_service, service_id="names")
sregistry.register(ext.subjects_service, service_id="subjects")
sregistry.register(ext.service, service_id="vocabularies")
# Register indexers
iregistry = app.extensions["invenio-indexer"].registry
iregistry.register(ext.affiliations_service.indexer, indexer_id="affiliations")
iregistry.register(ext.awards_service.indexer, indexer_id="awards")
iregistry.register(ext.funders_service.indexer, indexer_id="funders")
iregistry.register(ext.names_service.indexer, indexer_id="names")
iregistry.register(ext.subjects_service.indexer, indexer_id="subjects")
iregistry.register(ext.service.indexer, indexer_id="vocabularies")


def create_blueprint_from_app(app):
"""Create app blueprint."""
return app.extensions["invenio-vocabularies"].resource.as_blueprint()
Expand Down
11 changes: 8 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2020-2024 CERN.
# Copyright (C) 2022 Graz University of Technology.
# Copyright (C) 2022-2024 Graz University of Technology.
#
# Invenio-Vocabularies is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
Expand Down Expand Up @@ -34,8 +34,8 @@ install_requires =

[options.extras_require]
tests =
pytest-black>=0.3.0
invenio-app>=1.3.3,<2.0.0
pytest-black-ng>=0.4.0
invenio-app>=1.4.0,<2.0.0
invenio-db[postgresql,mysql]>=1.0.14,<2.0.0
pytest-invenio>=2.1.0,<3.0.0
Sphinx>=4.5
Expand Down Expand Up @@ -67,6 +67,10 @@ invenio_base.api_blueprints =
invenio_vocabularies_names = invenio_vocabularies.views:create_names_blueprint_from_app
invenio_vocabularies_subjects = invenio_vocabularies.views:create_subjects_blueprint_from_app
invenio_vocabularies_ext = invenio_vocabularies.views:blueprint
invenio_base.api_finalize_app =
invenio_vocabularies = invenio_vocabularies.ext:api_finalize_app
invenio_base.finalize_app =
invenio_vocabularies = invenio_vocabularies.ext:finalize_app
invenio_db.alembic =
invenio_vocabularies = invenio_vocabularies:alembic
invenio_db.models =
Expand Down Expand Up @@ -95,6 +99,7 @@ invenio_assets.webpack =
invenio_i18n.translations =
invenio_vocabularies = invenio_vocabularies


[build_sphinx]
source-dir = docs/
build-dir = docs/_build
Expand Down