diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8ef8bfd..a3f80b8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -3,6 +3,7 @@ # This file is part of Invenio. # Copyright (C) 2020 CERN. # Copyright (C) 2022 Graz University of Technology. +# Copyright (C) 2024 KTH Royal Institute of Technology. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. @@ -11,9 +12,11 @@ name: CI on: push: - branches: master + branches: + - master pull_request: - branches: master + branches: + - master schedule: # * is a special character in YAML so you have to quote this string - cron: '0 3 * * 6' @@ -25,58 +28,7 @@ on: default: 'Manual trigger' jobs: - Tests: - runs-on: ubuntu-20.04 - timeout-minutes: 20 - strategy: - matrix: - python-version: [3.8, 3.9] - requirements-level: [pypi] - db-service: [postgresql14,postgresql13,mysql8] - mq-service: [rabbitmq] - search-service: [opensearch2,elasticsearch7] - include: - - db-service: postgresql14 - DB_EXTRAS: "postgresql" - - - db-service: postgresql13 - DB_EXTRAS: "postgresql" - - - db-service: mysql8 - DB_EXTRAS: "mysql" - env: - DB: ${{ matrix.db-service }} - MQ: ${{ matrix.mq-service }} - SEARCH: ${{ matrix.search-service }} - EXTRAS: tests,${{ matrix.search-service }} - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - - name: Generate dependencies - run: | - pip install wheel requirements-builder - requirements-builder -e "$EXTRAS" --level=${{ matrix.requirements-level }} setup.py > .${{ matrix.requirements-level }}-${{ matrix.python-version }}-requirements.txt - - - name: Cache pip - uses: actions/cache@v2 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('.${{ matrix.requirements-level }}-${{ matrix.python-version }}-requirements.txt') }} - - - name: Install dependencies - run: | - pip install -r .${{ matrix.requirements-level }}-${{ matrix.python-version }}-requirements.txt - pip install ".[$EXTRAS]" - pip freeze - docker --version - docker compose --version - - - name: Run tests - run: | - ./run-tests.sh + Python: + uses: inveniosoftware/workflows/.github/workflows/tests-python.yml@master + with: + extras: "tests" diff --git a/invenio_oaiserver/admin.py b/invenio_oaiserver/admin.py index 25b7378..a34cc1d 100644 --- a/invenio_oaiserver/admin.py +++ b/invenio_oaiserver/admin.py @@ -2,6 +2,7 @@ # # This file is part of Invenio. # Copyright (C) 2015-2018 CERN. +# Copyright (C) 2024 KTH Royal Institute of Technology. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. @@ -9,15 +10,11 @@ """Admin model views for OAI sets.""" from flask_admin.contrib.sqla import ModelView +from invenio_i18n import gettext as _ from .models import OAISet -def _(x): - """Identity.""" - return x - - class OAISetModelView(ModelView): """OAISets model view.""" diff --git a/invenio_oaiserver/models.py b/invenio_oaiserver/models.py index c370cc7..1b5dba9 100644 --- a/invenio_oaiserver/models.py +++ b/invenio_oaiserver/models.py @@ -3,6 +3,7 @@ # This file is part of Invenio. # Copyright (C) 2015-2022 CERN. # Copyright (C) 2022 Graz University of Technology. +# Copyright (C) 2024 KTH Royal Institute of Technology. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. @@ -79,7 +80,7 @@ class OAISet(db.Model, Timestamp): def validate_spec(self, key, value): """Forbit updates of set identifier.""" if self.spec and self.spec != value: - raise OAISetSpecUpdateError("Updating spec is not allowed.") + raise OAISetSpecUpdateError(_("Updating spec is not allowed.")) return value diff --git a/invenio_oaiserver/percolator.py b/invenio_oaiserver/percolator.py index 86631c8..fa334b8 100644 --- a/invenio_oaiserver/percolator.py +++ b/invenio_oaiserver/percolator.py @@ -3,6 +3,7 @@ # This file is part of Invenio. # Copyright (C) 2017-2024 CERN. # Copyright (C) 2022 Graz University of Technology. +# Copyright (C) 2024 KTH Royal Institute of Technology. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. @@ -12,6 +13,7 @@ import json from flask import current_app +from invenio_i18n import lazy_gettext as _ from invenio_indexer.api import RecordIndexer from invenio_search import current_search, current_search_client from invenio_search.engine import search @@ -128,7 +130,9 @@ def create_percolate_query( ) else: raise Exception( - "Either documents or (document_search_ids and document_search_indices) must be specified." + _( + "Either documents or (document_search_ids and document_search_indices) must be specified." + ) ) if percolator_ids: diff --git a/invenio_oaiserver/verbs.py b/invenio_oaiserver/verbs.py index ebb3994..9119c3f 100644 --- a/invenio_oaiserver/verbs.py +++ b/invenio_oaiserver/verbs.py @@ -4,6 +4,7 @@ # Copyright (C) 2015-2018 CERN. # Copyright (C) 2021-2022 Graz University of Technology. # Copyright (C) 2022 RERO. +# Copyright (C) 2024 KTH Royal Institute of Technology. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. @@ -11,6 +12,7 @@ """OAI-PMH verbs.""" from flask import current_app, request +from invenio_i18n import gettext as _ from invenio_rest.serializer import BaseSchema from marshmallow import ValidationError, fields, validates_schema from marshmallow.fields import DateTime as _DateTime @@ -28,7 +30,7 @@ def validate_metadata_prefix(value, **kwargs): metadataFormats = current_app.config["OAISERVER_METADATA_FORMATS"] if value not in metadataFormats: raise ValidationError( - "metadataPrefix does not exist", field_names=["metadataPrefix"] + _("metadataPrefix does not exist"), field_names=["metadataPrefix"] ) @@ -88,12 +90,13 @@ def validate(self, data, **kwargs): if "verb" in data and data["verb"] != self.__class__.__name__: raise ValidationError( # FIXME encode data - "This is not a valid OAI-PMH verb:{0}".format(data["verb"]), + _("This is not a valid OAI-PMH verb:{0}").format(data["verb"]), field_names=["verb"], ) if "from_" in data and "until" in data and data["from_"] > data["until"]: - raise ValidationError('Date "from" must be before "until".') + + raise ValidationError(_('Date "from" must be before "until".')) class Verbs(object): @@ -162,7 +165,7 @@ def check_extra_params_in_request(verb): ] ) if extra: - raise ValidationError({"_schema": ["You have passed too many arguments."]}) + raise ValidationError({"_schema": [_("You have passed too many arguments.")]}) def make_request_validator(request): diff --git a/setup.cfg b/setup.cfg index 534bdc6..06c5f8b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,6 +3,7 @@ # This file is part of Invenio. # Copyright (C) 2015-2018 CERN. # Copyright (C) 2022 Graz University of Technology. +# Copyright (C) 2024 KTH Royal Institute of Technology. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. @@ -73,6 +74,8 @@ invenio_pidstore.minters = oaiid = invenio_oaiserver.minters:oaiid_minter invenio_pidstore.fetchers = oaiid = invenio_oaiserver.fetchers:oaiid_fetcher +invenio_i18n.translations = + invenio_oaiserver = invenio_oaiserver [build_sphinx] source-dir = docs/