Skip to content

Commit

Permalink
extend components (#273)
Browse files Browse the repository at this point in the history
* extend components

* prepend

* version
  • Loading branch information
Alzpeta authored Oct 14, 2024
1 parent 770338e commit 2f310f6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
5 changes: 3 additions & 2 deletions oarepo_model_builder/builtin_models/doi.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"service-config": {
"components": [
"extend:components": [
"{{oarepo_doi.services.components.DoiComponent}}"
]
}
}
}

26 changes: 23 additions & 3 deletions oarepo_model_builder/utils/deepmerge.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import copy
from typing import Union

def remove_colon_prefix(data):

if isinstance(data, dict):
new_data = {}
for k, v in data.items():
if ':' in k:
k = k.split(':', 1)[1]
new_data[k] = remove_colon_prefix(v)
return new_data
else:
return data

def deepmerge(
target,
Expand All @@ -23,13 +34,20 @@ def deepmerge(
else:
merged = None
if merged is None:
for k, v in source.items():
for k, v in list(source.items()):
_source = source
if ':' in k:
key = k
k = key.split(':')[1]
listmerge = key.split(':')[0]
_source[k] = _source.pop(key)

if k not in target:
target[k] = source[k]
target[k] = remove_colon_prefix(source[k])
else:
target[k] = deepmerge(
target[k],
source[k],
_source[k],
stack + [k],
listmerge=listmerge,
dictmerge=dictmerge,
Expand All @@ -53,6 +71,8 @@ def deepmerge(
target.append(source[idx])
elif listmerge == "extend":
target.extend(source)
elif listmerge == "prepend":
target = source + target
elif listmerge == "keep":
if len(source) > len(target):
target.extend(source[len(target) :])
Expand Down
3 changes: 1 addition & 2 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.91
version = 4.0.92
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 @@ -95,7 +95,6 @@ oarepo.models =
invenio = oarepo_model_builder.builtin_models:invenio.json
doi = oarepo_model_builder.builtin_models:doi.json


# outputs are generic, profile independent
oarepo_model_builder.outputs =
cfg = oarepo_model_builder.outputs.cfg:CFGOutput
Expand Down

0 comments on commit 2f310f6

Please sign in to comment.