-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #194 from oarepo/ext-service-hardcode
ext refactor
- Loading branch information
Showing
23 changed files
with
205 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
oarepo_model_builder/datatypes/components/model/ext_resource.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import marshmallow as ma | ||
|
||
from oarepo_model_builder.datatypes import DataTypeComponent, ModelDataType | ||
from oarepo_model_builder.datatypes.components.model.utils import set_default | ||
|
||
|
||
class ExtResourceSchema(ma.Schema): | ||
generate = ma.fields.Bool() | ||
skip = ma.fields.Bool() | ||
|
||
class Meta: | ||
unknown = ma.RAISE | ||
|
||
|
||
class ExtResourceModelComponent(DataTypeComponent): | ||
eligible_datatypes = [ModelDataType] | ||
|
||
class ModelSchema(ma.Schema): | ||
ext_resource = ma.fields.Nested( | ||
ExtResourceSchema, | ||
attribute="ext-resource", | ||
data_key="ext-resource", | ||
) | ||
|
||
def process_ext_resource(self, datatype, section, **kwargs): | ||
if self.is_record_profile: | ||
cfg = section.config | ||
cfg["ext-service-name"] = "service_records" | ||
cfg["ext-resource-name"] = "resource_records" | ||
|
||
def before_model_prepare(self, datatype, *, context, **kwargs): | ||
self.is_record_profile = context["profile"] == "record" | ||
if not self.is_record_profile: | ||
return | ||
ext = set_default(datatype, "ext-resource", {}) | ||
|
||
ext.setdefault("generate", True) | ||
ext.setdefault("skip", False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from .invenio_base import InvenioBaseClassPythonBuilder | ||
|
||
|
||
class InvenioExtResourceBuilder(InvenioBaseClassPythonBuilder): | ||
TYPE = "invenio_ext_resource" | ||
section = "ext" | ||
template = "ext-resource" | ||
|
||
def finish(self, **extra_kwargs): | ||
ext = self.current_model.section_ext_resource.config | ||
super().finish(ext=ext, **extra_kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
oarepo_model_builder/invenio/templates/ext_resource.py.jinja2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from functools import cached_property | ||
{{ vars.config.module|generate_import(alias='config') }} | ||
|
||
class {{ vars.ext|class_header }}: | ||
{% if not vars.service.skip %} | ||
@cached_property | ||
def {{ ext.ext_service_name }}(self): | ||
return config.{{ vars.service.config_key }}( | ||
config=config.{{ vars.service_config.config_key }}(), | ||
{% if vars.service.additional_args %} | ||
{{ vars.service.additional_args|generate_list }} | ||
{% endif %} | ||
) | ||
{% endif %} | ||
|
||
{% if not vars.resource.skip %} | ||
@cached_property | ||
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 }}(), | ||
) | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[metadata] | ||
name = oarepo-model-builder | ||
version = 4.0.19 | ||
version = 4.0.20 | ||
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 | ||
|
@@ -148,6 +148,7 @@ oarepo_model_builder.builders.record = | |
0430-ui_serializer = oarepo_model_builder.invenio.invenio_record_ui_serializer:InvenioRecordUISerializerBuilder | ||
0500-invenio_config = oarepo_model_builder.invenio.invenio_config:InvenioConfigBuilder | ||
0600-invenio_ext = oarepo_model_builder.invenio.invenio_ext:InvenioExtBuilder | ||
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_ext = oarepo_model_builder.invenio.invenio_proxies:InvenioProxiesBuilder | ||
0910-invenio_record_metadata_alembic_setup_cfg = oarepo_model_builder.invenio.invenio_record_metadata_alembic_setup_cfg:InvenioRecordMetadataAlembicSetupCfgBuilder | ||
|
Oops, something went wrong.