Skip to content

Commit

Permalink
global: update ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
utnapischtim committed May 28, 2024
1 parent ca5a3f1 commit 75aef20
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 44 deletions.
4 changes: 0 additions & 4 deletions .ruff.toml

This file was deleted.

36 changes: 19 additions & 17 deletions invenio_global_search/components.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2023 Graz University of Technology.
# Copyright (C) 2023-2024 Graz University of Technology.
#
# invenio-global-search is free software; you can redistribute it and/or modify
# it under the terms of the MIT License; see LICENSE file for more details.
Expand All @@ -12,27 +12,29 @@
from collections.abc import Callable

from flask_principal import Identity
from flask_resources import MarshmallowSerializer
from invenio_rdm_records.records.api import RDMDraft, RDMRecord
from invenio_rdm_records.resources.serializers.dublincore import (
DublinCoreJSONSerializer,
)
from invenio_records.api import Record
from invenio_records_global_search import current_records_global_search
from invenio_records_lom.records import LOMRecord
from invenio_records_lom.utils import LOMMetadata
from invenio_records_marc21.records import Marc21Record
from invenio_records_marc21.services.record import Marc21Metadata
from invenio_records_resources.services.records.components import ServiceComponent
from invenio_records_resources.services.uow import Operation
from invenio_records_resources.services.uow import Operation, UnitOfWork

from .serializers import LOMRecordJSONSerializer, Marc21RecordJSONSerializer


def map_metadata_from_a_to_b(
record,
serializer_cls=None,
metadata_cls=None,
schema=None,
identity=None,
record: Record,
serializer_cls: MarshmallowSerializer = None,
metadata_cls: Marc21Metadata | LOMMetadata | None = None,
schema: str | None = None,
identity: Identity = None,
) -> None:
"""Func."""
schema_mapping = {
Expand Down Expand Up @@ -72,12 +74,12 @@ class ComponentOp(Operation):

def __init__(
self,
record: RDMRecord,
record: Record,
func: Callable = map_metadata_from_a_to_b,
serializer_cls=None,
metadata_cls=None,
schema=None,
identity=None,
serializer_cls: MarshmallowSerializer = None,
metadata_cls: Marc21Metadata | LOMMetadata | None = None,
schema: str | None = None,
identity: Identity = None,
) -> None:
"""Construct."""
self._record = record
Expand All @@ -87,7 +89,7 @@ def __init__(
self._schema = schema
self._identity = identity

def on_post_commit(self, uow) -> None: # noqa: ARG002
def on_post_commit(self, _: UnitOfWork) -> None:
"""Post commit."""
self._func(
self._record,
Expand All @@ -106,7 +108,7 @@ def publish(
identity: Identity,
data: dict | None = None, # noqa: ARG002
record: Marc21Record | None = None,
**_: dict,
**__: dict,
) -> None:
"""Create handler."""
cmp_op = ComponentOp(
Expand All @@ -127,7 +129,7 @@ def publish(
identity: Identity,
data: dict | None = None, # noqa: ARG002
record: LOMRecord | None = None,
**_: dict,
**__: dict,
) -> None:
"""Create handler."""
cmp_op = ComponentOp(
Expand All @@ -148,8 +150,8 @@ def publish(
identity: Identity,
data: dict | None = None, # noqa: ARG002
record: RDMRecord | None = None,
draft: RDMDraft | None = None,
**_: dict,
draft: RDMDraft | None = None, # noqa: ARG002
**__: dict,
) -> None:
"""Create handler."""
cmp_op = ComponentOp(
Expand Down
10 changes: 6 additions & 4 deletions invenio_global_search/ext.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2023 Graz University of Technology.
# Copyright (C) 2023-2024 Graz University of Technology.
#
# invenio-global-search is free software; you can redistribute it and/or modify
# it under the terms of the MIT License; see LICENSE file for more details.

"""Global Search for InvenioRDM."""


from flask import Flask

from . import config


class InvenioGlobalSearch:
"""InvenioGlobalSearch."""

def __init__(self, app):
def __init__(self, app: Flask) -> None:
"""Construct InvenioGlobalSearch."""
if app:
self.init_app(app)

def init_app(self, app):
def init_app(self, app: Flask) -> None:
"""Flask application initialization."""
self.init_config(app)
app.extensions["invenio-global-search"] = self

@staticmethod
def init_config(app):
def init_config(app: Flask) -> None:
"""Initialize configuration."""
for k in dir(config):
if k.startswith("GLOBAL_SEARCH_"):
Expand Down
8 changes: 4 additions & 4 deletions invenio_global_search/serializers/lom/serializer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2023 Graz University of Technology.
# Copyright (C) 2023-2024 Graz University of Technology.
#
# invenio-global-search is free software; you can redistribute it and/or modify
# it under the terms of the MIT License; see LICENSE file for more details.
Expand All @@ -16,11 +16,11 @@
class LOMRecordJSONSerializer(MarshmallowSerializer):
"""Marshmallow based DataCite serializer for records."""

def __init__(self, **options):
"""Constructor."""
def __init__(self, **kwargs: dict) -> None:
"""Construct."""
super().__init__(
format_serializer_cls=JSONSerializer,
object_schema_cls=LOMRecordSchema,
list_schema_cls=BaseListSchema,
**options
**kwargs,
)
8 changes: 4 additions & 4 deletions invenio_global_search/serializers/marc21/serializer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2023 Graz University of Technology.
# Copyright (C) 2023-2024 Graz University of Technology.
#
# invenio-global-search is free software; you can redistribute it and/or modify
# it under the terms of the MIT License; see LICENSE file for more details.
Expand All @@ -16,11 +16,11 @@
class Marc21RecordJSONSerializer(MarshmallowSerializer):
"""Marshmallow based DataCite serializer for records."""

def __init__(self, **options):
"""Constructor."""
def __init__(self, **kwargs: dict) -> None:
"""Construct."""
super().__init__(
format_serializer_cls=JSONSerializer,
object_schema_cls=Marc21RecordSchema,
list_schema_cls=BaseListSchema,
**options
**kwargs,
)
7 changes: 1 addition & 6 deletions invenio_global_search/serializers/rdm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2023 Graz University of Technology.
# Copyright (C) 2023-2024 Graz University of Technology.
#
# invenio-global-search is free software; you can redistribute it and/or modify
# it under the terms of the MIT License; see LICENSE file for more details.

"""Global Search rdm searializer."""

# the problem is the parent does not exists in this stage
# from invenio_rdm_records.resources.serializers.dublincore import (
# DublinCoreJSONSerializer as RDMRecordJSONSerializer,
# )

from .serializer import RDMRecordJSONSerializer

__all__ = ("RDMRecordJSONSerializer",)
8 changes: 4 additions & 4 deletions invenio_global_search/serializers/rdm/serializer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2023 Graz University of Technology.
# Copyright (C) 2023-2024 Graz University of Technology.
#
# invenio-global-search is free software; you can redistribute it and/or modify
# it under the terms of the MIT License; see LICENSE file for more details.
Expand All @@ -16,11 +16,11 @@
class RDMRecordJSONSerializer(MarshmallowSerializer):
"""Marshmallow based DataCite serializer for records."""

def __init__(self, **options):
"""Constructor."""
def __init__(self, **kwargs: dict) -> None:
"""Construct."""
super().__init__(
format_serializer_cls=JSONSerializer,
object_schema_cls=RDMRecordSchema,
list_schema_cls=BaseListSchema,
**options
**kwargs,
)
16 changes: 15 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2023 Graz University of Technology.
# Copyright (C) 2023-2024 Graz University of Technology.
#
# invenio-global-search is free software; you can redistribute it and/or modify
# it under the terms of the MIT License; see LICENSE file for more details.

[build-system]
requires = ["setuptools", "wheel", "babel>2.8"]
build-backend = "setuptools.build_meta"

[tool.ruff]
exclude = ["docs"]

[tool.ruff.lint]
select = ["ALL"]
ignore = [
"ANN101", "ANN102",
"D203", "D211", "D212", "D213",
"PLR0913",
"TCH001", "TCH002", "TCH003",
"TID252",
"UP009",
]

0 comments on commit 75aef20

Please sign in to comment.