Skip to content

Commit

Permalink
components property refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Alzbeta Pokorna committed Jan 15, 2025
1 parent a6f0679 commit 6d49e43
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 24 deletions.
15 changes: 4 additions & 11 deletions oarepo_model_builder/invenio/templates/service_config.py.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,18 @@ class {{ vars.service_config|class_header }}:
@property
def components(self):
components_list = []
target_classes = [
'invenio_rdm_records.services.config.RDMRecordServiceConfig',
'invenio_drafts_resources.services.records.config.RecordServiceConfig',
'invenio_records_resources.services.records.config.RecordServiceConfig'
]

for index, cls in enumerate(type(self).mro()):
if cls.__module__ + '.' + cls.__name__ in target_classes:
break
components_list.extend(process_service_configs(type(self).mro()[2:index+1]))
components_list.extend(process_service_configs(self))

additional_components = [{% for c in vars.service_config.components %}{{ c|extra_code }}{% if not loop.last %}, {% endif %}{% endfor %}]
components_list.extend(additional_components)
seen = set()
unique_components = []
for component in components_list:
if component not in seen:
identifier = (component.__module__, component.__name__)
if identifier not in seen:
unique_components.append(component)
seen.add(component)
seen.add(identifier)

return unique_components

Expand Down
2 changes: 1 addition & 1 deletion run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ cd "$(dirname "$0")"
export BUILDER_VENV=.venv
export TEST_VENV=.venv-tests
export SERVER_VENV=.venv-server
export PYTHON_VERSION=${PYTHON_VERSION:-python3.12}
export PYTHON_VERSION=${PYTHON_VERSION:-python3}

OAREPO_VERSION=${OAREPO_VERSION:-12}

Expand Down
18 changes: 6 additions & 12 deletions tests/test_simple_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,24 +428,18 @@ class TestServiceConfig(PermissionsPresetsConfigMixin, InvenioRecordServiceConfi
@property
def components(self):
components_list = []
target_classes = [
'invenio_rdm_records.services.config.RDMRecordServiceConfig',
'invenio_drafts_resources.services.records.config.RecordServiceConfig',
'invenio_records_resources.services.records.config.RecordServiceConfig'
]
for index, cls in enumerate(type(self).mro()):
if cls.__module__ + '.' + cls.__name__ in target_classes:
break
components_list.extend(process_service_configs(type(self).mro()[2:index+1]))
components_list.extend(process_service_configs(self))
additional_components = []
components_list.extend(additional_components)
seen = set()
unique_components = []
for component in components_list:
if component not in seen:
identifier = (component.__module__, component.__name__)
if identifier not in seen:
unique_components.append(component)
seen.add(component)
seen.add(identifier)
return unique_components
Expand Down

0 comments on commit 6d49e43

Please sign in to comment.