diff --git a/invenio_vocabularies/ext.py b/invenio_vocabularies/ext.py index 4c34513c..4e7ab481 100644 --- a/invenio_vocabularies/ext.py +++ b/invenio_vocabularies/ext.py @@ -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 @@ -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") diff --git a/invenio_vocabularies/views.py b/invenio_vocabularies/views.py index be150406..fcc20b78 100644 --- a/invenio_vocabularies/views.py +++ b/invenio_vocabularies/views.py @@ -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 @@ -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() diff --git a/setup.cfg b/setup.cfg index 7eb90223..d9196202 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 @@ -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 @@ -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 = @@ -95,6 +99,7 @@ invenio_assets.webpack = invenio_i18n.translations = invenio_vocabularies = invenio_vocabularies + [build_sphinx] source-dir = docs/ build-dir = docs/_build