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

global: update ruff #17

Merged
merged 2 commits into from
Jun 13, 2024
Merged
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
4 changes: 0 additions & 4 deletions .ruff.toml

This file was deleted.

38 changes: 19 additions & 19 deletions invenio_global_search/components.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
# -*- 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.

"""Components to Hook into other data models."""

from __future__ import annotations

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 +72,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 +87,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 +106,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 +127,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 +148,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,
)
17 changes: 16 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
# -*- 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",
"FA102",
"PLR0913",
"TCH001", "TCH002", "TCH003",
"TID252",
"UP009",
]
5 changes: 2 additions & 3 deletions setup.cfg
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 @@ -17,8 +17,7 @@ author_email =
platforms = any
url = https://github.com/tu-graz-library/invenio-global-search
classifiers =
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.12
Development Status :: 5 - Production/Stable
License :: OSI Approved :: MIT License
Operating System :: OS Independent
Expand Down