Skip to content

Commit

Permalink
setup: migrate to ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
utnapischtim committed May 25, 2023
1 parent 00313c9 commit 68f273c
Show file tree
Hide file tree
Showing 17 changed files with 116 additions and 91 deletions.
4 changes: 4 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
select = ["ALL"]
ignore = ["ANN101", "ANN102", "D203", "D211", "D212", "D213", "UP009", "S101", "S314", "INP001", "FLY002", "TD002", "TD003"]

exclude = ["docs"]
11 changes: 2 additions & 9 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2021 Graz University of Technology.
# Copyright (C) 2021-2023 Graz University of Technology.
#
# invenio-campusonline is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
# details.

# TODO: Generate this manifest file by running the following commands:
# (please sort the lines in this file after running below commands)
#
# git init
# git add -A
# pip install -e .[all]
# check-manifest -u

include .dockerignore
include .editorconfig
include .tx/config
Expand All @@ -26,6 +18,7 @@ include *.md
include *.rst
include *.sh
include *.txt
include *.toml
include babel.ini
include pytest.ini
recursive-include docs *.bat
Expand Down
4 changes: 4 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
"sphinx.ext.viewcode",
]

nitpick_ignore = [
("py:class", "flask.app.Flask"),
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

Expand Down
4 changes: 2 additions & 2 deletions invenio_campusonline/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2021-2022 Graz University of Technology.
# Copyright (C) 2021-2023 Graz University of Technology.
#
# invenio-campusonline is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
# details.

"""This module is used to import/export from/to the CampusOnline System."""
"""The module is used to import/export from/to the CampusOnline System."""

from .api import fetch_all_ids, import_from_campusonline
from .ext import InvenioCampusonline
Expand Down
15 changes: 10 additions & 5 deletions invenio_campusonline/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
# file for more details.

"""API functions of the campusonline connector."""
from typing import Callable
from collections.abc import Callable
from xml.etree.ElementTree import fromstring

from invenio_records_resources.services.records.results import RecordItem
from requests import post

from .types import (
Expand All @@ -29,22 +30,26 @@


def import_from_campusonline(
import_func: Callable, cms_id: CampusOnlineID, configs: CampusOnlineConfigs
):
import_func: Callable,
cms_id: CampusOnlineID,
configs: CampusOnlineConfigs,
) -> RecordItem:
"""Import record from campusonline."""
return import_func(cms_id, configs, get_metadata, download_file)


def fetch_all_ids(
endpoint: URL, token: CampusOnlineToken, theses_filters: ThesesFilter = None
endpoint: URL,
token: CampusOnlineToken,
theses_filters: ThesesFilter = None,
) -> list[tuple[CampusOnlineID, ThesesState]]:
"""Fetch to import ids."""
ids = []
for theses_filter, state in theses_filters:
body = create_request_body_ids(token, theses_filter)

headers = create_request_header("getAllThesesMetadataRequest")
response = post(endpoint, data=body, headers=headers)
response = post(endpoint, data=body, headers=headers, timeout=10)

root = fromstring(response.text)
xpath = "{http://www.campusonline.at/thesisservice/basetypes}ID"
Expand Down
25 changes: 20 additions & 5 deletions invenio_campusonline/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


@group()
def campusonline():
def campusonline() -> None:
"""Campusonline CLI."""


Expand All @@ -28,16 +28,27 @@ def campusonline():
@option("--campusonline-id", type=STRING)
@option("--token", type=STRING)
@option("--user-email", type=STRING, default="[email protected]")
@option("--no-color", is_flag=True)
def import_thesis(endpoint, campusonline_id, token, user_email, no_color=False):
@option("--no-color", is_flag=True, default=False)
def import_thesis(
endpoint: str,
campusonline_id: str,
token: str,
user_email: str,
no_color: bool, # noqa: FBT001
) -> None:
"""Import metadata and file (aka one thesis) from campusonline."""
import_func = current_app.config["CAMPUSONLINE_IMPORT_FUNC"]
theses_filters = current_app.config["CAMPUSONLINE_THESES_FILTERS"]
recipients = current_app.config["CAMPUSONLINE_ERROR_MAIL_RECIPIENTS"]
sender = current_app.config["CAMPUSONLINE_ERROR_MAIL_SENDER"]

configs = CampusOnlineConfigs(
endpoint, token, user_email, theses_filters, recipients, sender
endpoint,
token,
user_email,
theses_filters,
recipients,
sender,
)
record = import_from_campusonline(import_func, campusonline_id, configs)

Expand All @@ -50,7 +61,11 @@ def import_thesis(endpoint, campusonline_id, token, user_email, no_color=False):
@option("--endpoint", type=URL)
@option("--token", type=STRING)
@option("--no-color", is_flag=True)
def fetch_ids(endpoint, token, no_color):
def fetch_ids(
endpoint: str,
token: str,
no_color: bool, # noqa: FBT001
) -> None:
"""Fetch all to import ids."""
theses_filters = current_app.config["CAMPUSONLINE_THESES_FILTERS"]
ids = fetch_all_ids(endpoint, token, theses_filters)
Expand Down
4 changes: 2 additions & 2 deletions invenio_campusonline/config.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2021-2022 Graz University of Technology.
# Copyright (C) 2021-2023 Graz University of Technology.
#
# invenio-campusonline is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
# details.

"""This is the configuration file."""
"""The configuration file."""

CAMPUSONLINE_ENDPOINT = ""
"""This is the endpoint to fetch the records."""
Expand Down
10 changes: 6 additions & 4 deletions invenio_campusonline/ext.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2021-2022 Graz University of Technology.
# Copyright (C) 2021-2023 Graz University of Technology.
#
# invenio-campusonline is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
# details.

"""This module is used to import/export from/to the CampusOnline System."""
"""The module is used to import/export from/to the CampusOnline System."""

from flask import Flask


class InvenioCampusonline:
"""invenio-campusonline extension."""

def __init__(self, app=None):
def __init__(self, app: Flask = None) -> None:
"""Extension initialization."""
if app:
self.init_app(app)

def init_app(self, app):
def init_app(self, app: Flask) -> None:
"""Flask application initialization."""
app.extensions["invenio-campusonline"] = self
15 changes: 10 additions & 5 deletions invenio_campusonline/tasks.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2022 Graz University of Technology.
# Copyright (C) 2022-2023 Graz University of Technology.
#
# invenio-campusonline is free software; you can redistribute it
# and/or modify it under the terms of the MIT License; see LICENSE
# file for more details.


"""Celery tasks for `invenio-campusonline`."""
from typing import Callable
from collections.abc import Callable

from celery import shared_task
from flask import current_app
Expand All @@ -19,7 +19,7 @@


def config_variables() -> tuple[Callable, CampusOnlineConfigs]:
"""Configuration variables."""
"""Configure variables."""
import_func = current_app.config["CAMPUSONLINE_IMPORT_FUNC"]
endpoint = current_app.config["CAMPUSONLINE_ENDPOINT"]
token = current_app.config["CAMPUSONLINE_TOKEN"]
Expand All @@ -29,7 +29,12 @@ def config_variables() -> tuple[Callable, CampusOnlineConfigs]:
sender = current_app.config["CAMPUSONLINE_ERROR_MAIL_SENDER"]

return import_func, CampusOnlineConfigs(
endpoint, token, user_email, theses_filters, recipients, sender
endpoint,
token,
user_email,
theses_filters,
recipients,
sender,
)


Expand All @@ -39,7 +44,7 @@ def import_theses_from_campusonline() -> None:
import_func, configs = config_variables()
ids = fetch_all_ids(configs.endpoint, configs.token, configs.theses_filters)

for cms_id, state in ids:
for cms_id, _ in ids:
try:
import_from_campusonline(import_func, cms_id, configs)
except RuntimeError:
Expand Down
10 changes: 5 additions & 5 deletions invenio_campusonline/types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2022 Graz University of Technology.
# Copyright (C) 2022-2023 Graz University of Technology.
#
# invenio-campusonline is free software; you can redistribute it
# and/or modify it under the terms of the MIT License; see LICENSE
Expand Down Expand Up @@ -40,14 +40,14 @@

@dataclass(frozen=True)
class Color:
"""This class is for the output color management."""
"""The class is for the output color management."""

neutral = "black"
error = "red"
warning = "yellow"
abort = "magenta"
success = "green"
alternate = ["blue", "cyan"]
alternate = ("blue", "cyan")


class ThesesState(Enum):
Expand All @@ -64,8 +64,8 @@ class ThesesFilter:
filter_: list[Element]
state: ThesesState

def __iter__(self):
"""This method makes the properties iterable."""
def __iter__(self): # noqa: ANN204
"""Make the class iteratable."""
return iter(astuple(self))


Expand Down
Loading

0 comments on commit 68f273c

Please sign in to comment.