Skip to content

Commit

Permalink
additonal service args
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald Krist committed Feb 20, 2024
1 parent 042d4e2 commit ea99872
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 23 deletions.
1 change: 0 additions & 1 deletion oarepo_model_builder/datatypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
object represented as flatten type in elasticsearch
"""


from .containers import ( # noqa
ArrayDataType,
FlatObjectDataType,
Expand Down
18 changes: 18 additions & 0 deletions oarepo_model_builder/datatypes/components/model/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down Expand Up @@ -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()


Expand Down Expand Up @@ -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", {})
Expand All @@ -161,4 +178,5 @@ def before_model_prepare(self, datatype, *, context, **kwargs):
"imports",
[],
)
config.setdefault("additional-args", [])
convert_config_to_qualified_name(config)
18 changes: 18 additions & 0 deletions oarepo_model_builder/datatypes/components/model/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down Expand Up @@ -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()


Expand Down Expand Up @@ -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", {})
Expand All @@ -153,4 +170,5 @@ def before_model_prepare(self, datatype, *, context, **kwargs):
"imports",
[],
)
service.setdefault("additional-args", [])
convert_config_to_qualified_name(service)
13 changes: 11 additions & 2 deletions oarepo_model_builder/invenio/templates/ext_resource.py.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand All @@ -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 %}
8 changes: 5 additions & 3 deletions oarepo_model_builder/merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
18 changes: 1 addition & 17 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>, Miroslav Simek <[email protected]>
readme = README.md
Expand Down Expand Up @@ -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
Expand All @@ -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
####
Expand Down

0 comments on commit ea99872

Please sign in to comment.