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

Rdm #275

Closed
wants to merge 7 commits into from
Closed

Rdm #275

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
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def before_model_prepare(self, datatype, *, context, **kwargs):
marshmallow.setdefault("class", f"{module}.{prefix}Schema")
marshmallow.setdefault("extra-code", "")
marshmallow.setdefault("base-classes", ["marshmallow.Schema"])
marshmallow["base-classes"].append("oarepo_runtime.services.schema.rdm.RDMRecordMixin")
convert_config_to_qualified_name(marshmallow)

if "properties" in datatype.definition and "metadata" in (
Expand Down
3 changes: 2 additions & 1 deletion oarepo_model_builder/datatypes/components/model/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@ def before_model_prepare(self, datatype, *, context, **kwargs):
record.setdefault("class", f"{records_module}.{record_prefix}Record")
record.setdefault(
"base-classes",
["invenio_records_resources.records.api.Record{InvenioRecord}"],
["invenio_rdm_records.records.api.RDMRecord"],
)
record.setdefault(
"imports",
[],

)
record.setdefault("extra-code", "")
record.setdefault("fields", {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ def before_model_prepare(self, datatype, context, **kwargs):
metadata.setdefault("extra-code", "")
metadata.setdefault(
"imports",
[],
[{"import": "invenio_rdm_records.records.systemfields.deletion_status.RecordDeletionStatusEnum"},
{"import": "sqlalchemy_utils.types.ChoiceType"}],
)
metadata.setdefault(
"table", f"{datatype.definition['module']['prefix-snake']}_metadata"
Expand Down
2 changes: 1 addition & 1 deletion oarepo_model_builder/datatypes/components/model/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def before_model_prepare(self, datatype, *, context, **kwargs):
service.setdefault("extra-code", "")
service.setdefault(
"base-classes",
["invenio_records_resources.services.RecordService{InvenioRecordService}"],
["invenio_rdm_records.services.services.RDMRecordService"],
)
service.setdefault(
"imports",
Expand Down
19 changes: 19 additions & 0 deletions oarepo_model_builder/invenio/templates/ext.py.jinja2
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import re

from invenio_rdm_records.services.pids import PIDsService, PIDManager
{{ vars.config.module|generate_import(alias='config') }}
{{ vars.ext|imports }}

Expand All @@ -13,6 +15,7 @@ class {{ vars.ext|class_header }}:

def init_app(self, app):
"""Flask application initialization."""
self.app = app
{% if vars.ext.base_classes %}
super().init_app(app=app)
{% endif %}
Expand All @@ -28,6 +31,8 @@ class {{ vars.ext|class_header }}:

def init_config(self, app):
"""Initialize configuration."""
{{ vars.service }}
{{ vars.ext }}
for identifier in dir(config):
if re.match('^[A-Z_0-9]*$', identifier) and not identifier.startswith('_'):
if isinstance(app.config.get(identifier), list):
Expand All @@ -54,4 +59,18 @@ class {{ vars.ext|class_header }}:
return True
return False

@cached_property
def service_records(self):
{{ vars.service_config.class|generate_import }}
{{ vars.service.class|generate_import }}
config_class = {{ vars.service_config.class|base_name }}.build(self.app)
return {{ vars.service.class|base_name }}(
config=config_class,
pids_service=PIDsService(config_class, PIDManager),
{% if vars.service.additional_args %}
{{ vars.service.additional_args|generate_list }}
{% endif %}
)


{{ vars.ext|extra_code }}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@ class {{ vars.record_metadata|class_header }}:
__versioned__ = {}
{% endif %}

deletion_status = db.Column(
ChoiceType(RecordDeletionStatusEnum, impl=db.String(1)),
nullable=False,
default=RecordDeletionStatusEnum.PUBLISHED.value,
)
{{ vars.record_metadata|extra_code }}
21 changes: 15 additions & 6 deletions run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ initialize_server_venv() {
rm -rf $SERVER_VENV
fi

python3 -m venv $SERVER_VENV
python3.12 -m venv $SERVER_VENV
source $SERVER_VENV/bin/activate

$SERVER_VENV/bin/pip install -U setuptools pip wheel
$SERVER_VENV/bin/pip install "oarepo[tests]==${OAREPO_VERSION}.*"
$SERVER_VENV/bin/pip install -e complex-model



.venv-server/bin/pip install -U setuptools pip wheel nrp-devtools ~/cesnet/nr/temp/oarepo-runtime/
.venv-server/bin/nrp-devtools proxy 120 &
.venv-server/bin/pip install "oarepo[tests,rdm]==12.*" --index-url "http://127.0.0.1:4549/simple" --extra-index-url https://pypi.org/simple


.venv-server/bin/pip install -e complex-model --index-url "http://127.0.0.1:4549/simple" --extra-index-url https://pypi.org/simple
}

initialize_builder_venv() {
Expand All @@ -33,7 +39,7 @@ initialize_builder_venv() {
rm -rf $BUILDER_VENV
fi

python3 -m venv $BUILDER_VENV
python3.12 -m venv $BUILDER_VENV
. $BUILDER_VENV/bin/activate
$BUILDER_VENV/bin/pip install -U setuptools pip wheel
$BUILDER_VENV/bin/pip install -e '.[tests]'
Expand All @@ -45,10 +51,11 @@ initialize_client_test_venv() {
rm -rf $TEST_VENV
fi

python3 -m venv $TEST_VENV
python3.12 -m venv $TEST_VENV

$TEST_VENV/bin/pip install -U setuptools pip wheel
$TEST_VENV/bin/pip install requests PyYAML pytest

}

run_builder_tests() {
Expand Down Expand Up @@ -156,6 +163,8 @@ if [ "$1" == "--server" ] ; then
fi

cat complex-model/data/sample_data.yaml


$TEST_VENV/bin/pytest tests-model


Expand Down
Loading
Loading