From ea9987215d18cd5c9cb05c81c30af1ed1463b040 Mon Sep 17 00:00:00 2001 From: Ronald Krist Date: Tue, 20 Feb 2024 13:10:50 +0100 Subject: [PATCH] additonal service args --- oarepo_model_builder/datatypes/__init__.py | 1 - .../datatypes/components/model/resource.py | 18 ++++++++++++++++++ .../datatypes/components/model/service.py | 18 ++++++++++++++++++ .../invenio/templates/ext_resource.py.jinja2 | 13 +++++++++++-- oarepo_model_builder/merger.py | 8 +++++--- setup.cfg | 18 +----------------- 6 files changed, 53 insertions(+), 23 deletions(-) diff --git a/oarepo_model_builder/datatypes/__init__.py b/oarepo_model_builder/datatypes/__init__.py index 3261e661..d60010cc 100644 --- a/oarepo_model_builder/datatypes/__init__.py +++ b/oarepo_model_builder/datatypes/__init__.py @@ -20,7 +20,6 @@ object represented as flatten type in elasticsearch """ - from .containers import ( # noqa ArrayDataType, FlatObjectDataType, diff --git a/oarepo_model_builder/datatypes/components/model/resource.py b/oarepo_model_builder/datatypes/components/model/resource.py index 609ce4b7..5e170fa2 100644 --- a/oarepo_model_builder/datatypes/components/model/resource.py +++ b/oarepo_model_builder/datatypes/components/model/resource.py @@ -41,6 +41,14 @@ class Meta: imports = ma.fields.List( ma.fields.Nested(ImportSchema), metadata={"doc": "List of python imports"} ) + additional_args = ma.fields.List( + ma.fields.String(), + attribute="additional-args", + data_key="additional-args", + metadata={ + "doc": "List of additional arguments that will be passed to the resource constructor" + }, + ) skip = ma.fields.Boolean() @@ -88,6 +96,14 @@ class Meta: imports = ma.fields.List( ma.fields.Nested(ImportSchema), metadata={"doc": "List of python imports"} ) + additional_args = ma.fields.List( + ma.fields.String(), + attribute="additional-args", + data_key="additional-args", + metadata={ + "doc": "List of additional arguments that will be passed to the resource config constructor" + }, + ) skip = ma.fields.Boolean() @@ -137,6 +153,7 @@ def before_model_prepare(self, datatype, *, context, **kwargs): "imports", [], ) + resource.setdefault("additional-args", []) convert_config_to_qualified_name(resource) config = set_default(datatype, "resource-config", {}) @@ -161,4 +178,5 @@ def before_model_prepare(self, datatype, *, context, **kwargs): "imports", [], ) + config.setdefault("additional-args", []) convert_config_to_qualified_name(config) diff --git a/oarepo_model_builder/datatypes/components/model/service.py b/oarepo_model_builder/datatypes/components/model/service.py index f7cac47e..497c2dac 100644 --- a/oarepo_model_builder/datatypes/components/model/service.py +++ b/oarepo_model_builder/datatypes/components/model/service.py @@ -40,6 +40,14 @@ class Meta: imports = ma.fields.List( ma.fields.Nested(ImportSchema), metadata={"doc": "List of python imports"} ) + additional_args = ma.fields.List( + ma.fields.String(), + attribute="additional-args", + data_key="additional-args", + metadata={ + "doc": "List of additional arguments that will be passed to the service constructor" + }, + ) skip = ma.fields.Boolean() @@ -81,6 +89,14 @@ class Meta: imports = ma.fields.List( ma.fields.Nested(ImportSchema), metadata={"doc": "List of python imports"} ) + additional_args = ma.fields.List( + ma.fields.String(), + attribute="additional-args", + data_key="additional-args", + metadata={ + "doc": "List of additional arguments that will be passed to the service config constructor" + }, + ) skip = ma.fields.Boolean() @@ -132,6 +148,7 @@ def before_model_prepare(self, datatype, *, context, **kwargs): ], ) config.setdefault("components", []) + config.setdefault("additional-args", []) convert_config_to_qualified_name(config) service = set_default(datatype, "service", {}) @@ -153,4 +170,5 @@ def before_model_prepare(self, datatype, *, context, **kwargs): "imports", [], ) + service.setdefault("additional-args", []) convert_config_to_qualified_name(service) diff --git a/oarepo_model_builder/invenio/templates/ext_resource.py.jinja2 b/oarepo_model_builder/invenio/templates/ext_resource.py.jinja2 index efeb30a9..acff03b8 100644 --- a/oarepo_model_builder/invenio/templates/ext_resource.py.jinja2 +++ b/oarepo_model_builder/invenio/templates/ext_resource.py.jinja2 @@ -6,7 +6,10 @@ class {{ vars.ext|class_header }}: @cached_property def {{ ext.ext_service_name }}(self): return config.{{ vars.service.config_key }}( - config=config.{{ vars.service_config.config_key }}(), + config=config.{{ vars.service_config.config_key }}( + {% if vars.service_config.additional_args %} + {{ vars.service_config.additional_args|generate_list }} + {% endif %}), {% if vars.service.additional_args %} {{ vars.service.additional_args|generate_list }} {% endif %} @@ -18,6 +21,12 @@ class {{ vars.ext|class_header }}: def {{ ext.ext_resource_name }}(self): return config.{{ vars.resource.config_key }}( service=self.{{ ext.ext_service_name }}, - config=config.{{ vars.resource_config.config_key }}(), + config=config.{{ vars.resource_config.config_key }}( + {% if vars.resource_config.additional_args %} + {{ vars.resource_config.additional_args|generate_list }} + {% endif %}), + {% if vars.resource.additional_args %} + {{ vars.resource.additional_args|generate_list }} + {% endif %} ) {% endif %} \ No newline at end of file diff --git a/oarepo_model_builder/merger.py b/oarepo_model_builder/merger.py index 395b8e15..dd1de628 100644 --- a/oarepo_model_builder/merger.py +++ b/oarepo_model_builder/merger.py @@ -52,9 +52,11 @@ def merger(source, destination, result, destination_first, overwrite): merge_file( fn, destination.joinpath(relative_fn), - result.joinpath(relative_fn) - if result - else destination.joinpath(relative_fn), + ( + result.joinpath(relative_fn) + if result + else destination.joinpath(relative_fn) + ), destination_first, overwrite, ) diff --git a/setup.cfg b/setup.cfg index 009273ba..3fa59f3d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = oarepo-model-builder -version = 4.0.72 +version = 4.0.73 description = A utility library that generates OARepo required data model files from a JSON specification file authors = Miroslav Bauer , Miroslav Simek readme = README.md @@ -147,23 +147,13 @@ oarepo_model_builder.builders.base = 0060-setup-py = oarepo_model_builder.builders.setup_py:SetupPyBuilder 0070-pyproject-toml = oarepo_model_builder.builders.pyproject_toml:PyprojectTOMLBuilder 0100-python_structure = oarepo_model_builder.builders.python_structure:PythonStructureBuilder - 0110-invenio_record = oarepo_model_builder.invenio.invenio_record:InvenioRecordBuilder 0120-invenio_record_metadata = oarepo_model_builder.invenio.invenio_record_metadata:InvenioRecordMetadataBuilder 0130-invenio_record_marshmallow = oarepo_model_builder.invenio.invenio_record_marshmallow:InvenioRecordMarshmallowBuilder 0140-invenio_record_ui_marshmallow = oarepo_model_builder.invenio.invenio_record_ui_marshmallow:InvenioRecordUIMarshmallowBuilder - - - #should stay here? 0310-invenio_record_service_config = oarepo_model_builder.invenio.invenio_record_service_config:InvenioRecordServiceConfigBuilder - - 0320-invenio_record_service = oarepo_model_builder.invenio.invenio_record_service:InvenioRecordServiceBuilder - - #prob move to record 0400-invenio_record_resource_config = oarepo_model_builder.invenio.invenio_record_resource_config:InvenioRecordResourceConfigBuilder - - 0410-invenio_record_resource = oarepo_model_builder.invenio.invenio_record_resource:InvenioRecordResourceBuilder 0420-invenio_api_views = oarepo_model_builder.invenio.invenio_api_views:InvenioAPIViewsBuilder 0421-invenio_app_views = oarepo_model_builder.invenio.invenio_app_views:InvenioAPPViewsBuilder @@ -173,14 +163,8 @@ oarepo_model_builder.builders.base = 0605-invenio_ext_resource = oarepo_model_builder.invenio.invenio_ext_resource:InvenioExtResourceBuilder 0610-invenio_ext_setup_cfg = oarepo_model_builder.invenio.invenio_ext_setup_cfg:InvenioExtSetupCfgBuilder 0700-invenio_proxies = oarepo_model_builder.invenio.invenio_proxies:InvenioProxiesBuilder - 0920-invenio_record_metadata_models_setup_cfg = oarepo_model_builder.invenio.invenio_record_metadata_models_setup_cfg:InvenioRecordMetadataModelsSetupCfgBuilder 0930-invenio_resource_setup_cfg = oarepo_model_builder.invenio.invenio_record_resource_setup_cfg:InvenioRecordResourceSetupCfgBuilder - - - - - #### #### Extended schema profile ####