diff --git a/ckanext/iiif/builders/abc.py b/ckanext/iiif/builders/abc.py index 44fc58e..1cf2e2d 100644 --- a/ckanext/iiif/builders/abc.py +++ b/ckanext/iiif/builders/abc.py @@ -1,6 +1,5 @@ -from typing import Optional - import abc +from typing import Optional class IIIFResourceBuilder(abc.ABC): @@ -12,8 +11,7 @@ class IIIFResourceBuilder(abc.ABC): """ @abc.abstractmethod - def match_and_build(self, identifier: str) -> Optional[dict]: - ... + def match_and_build(self, identifier: str) -> Optional[dict]: ... @abc.abstractmethod def build_identifier(self, **kwargs) -> str: diff --git a/ckanext/iiif/builders/manifest.py b/ckanext/iiif/builders/manifest.py index 76391c0..ea890d1 100644 --- a/ckanext/iiif/builders/manifest.py +++ b/ckanext/iiif/builders/manifest.py @@ -1,13 +1,14 @@ import re +from typing import Dict, List, Optional, Union + from ckan import model from ckan.common import config from ckan.lib.helpers import url_for_static_or_external from ckan.logic import NotFound from ckan.plugins import toolkit -from typing import List, Dict, Optional, Union from .abc import IIIFResourceBuilder -from .utils import create_id_url, wrap_language, IIIFBuildError +from .utils import IIIFBuildError, create_id_url, wrap_language class RecordManifestBuilder(IIIFResourceBuilder): @@ -35,8 +36,8 @@ def match_and_build(self, identifier: str) -> Optional[dict]: :param identifier: the manifest ID :return: the manifest as a dict or None if the identifier wasn't a match to the - required format - :raise: IIIFBuildError if anything goes wrong after the identifier is matched + required format + :raises IIIFBuildError: if anything goes wrong after the identifier is matched """ regex = re.compile( 'resource/(?P.+?)/record/(?P[^/]+).*$' @@ -71,7 +72,7 @@ def build_record_manifest(resource: dict, record: dict) -> Optional[dict]: :param resource: the resource dict :param record: the record data :return: the IIIF manifest for the record and its images - :raise: IIIFBuildError if no images are present on the record + :raises IIIFBuildError: if no images are present on the record """ manifest_id = RecordManifestBuilder._build_record_manifest_id(resource, record) diff --git a/ckanext/iiif/builders/utils.py b/ckanext/iiif/builders/utils.py index caf34ea..0762b7d 100644 --- a/ckanext/iiif/builders/utils.py +++ b/ckanext/iiif/builders/utils.py @@ -1,6 +1,7 @@ -from ckan.plugins import toolkit from typing import Dict, List, Union +from ckan.plugins import toolkit + def create_id_url(identifier: str) -> str: """ diff --git a/ckanext/iiif/interfaces.py b/ckanext/iiif/interfaces.py index 93779ac..54041fe 100644 --- a/ckanext/iiif/interfaces.py +++ b/ckanext/iiif/interfaces.py @@ -1,5 +1,6 @@ +from typing import Callable, Optional, OrderedDict + from ckan.plugins import interfaces -from typing import Optional, Callable, OrderedDict class IIIIF(interfaces.Interface): diff --git a/ckanext/iiif/logic/actions.py b/ckanext/iiif/logic/actions.py index 9bb76d5..db7a7a9 100644 --- a/ckanext/iiif/logic/actions.py +++ b/ckanext/iiif/logic/actions.py @@ -1,9 +1,10 @@ +import logging from collections import OrderedDict +from typing import Optional +from typing import OrderedDict as OrderedDictType -import logging from ckan.plugins import toolkit from ckantools.decorators import action -from typing import Optional, OrderedDict as OrderedDictType from ..builders.abc import IIIFResourceBuilder from ..builders.manifest import RecordManifestBuilder diff --git a/ckanext/iiif/plugin.py b/ckanext/iiif/plugin.py index 28d250d..fa92832 100644 --- a/ckanext/iiif/plugin.py +++ b/ckanext/iiif/plugin.py @@ -1,11 +1,11 @@ -import ckan.plugins as plugins import logging +from contextlib import suppress + +import ckan.plugins as plugins from ckan.plugins import toolkit from ckantools.loaders import create_actions, create_auth -from contextlib import suppress -from . import interfaces -from . import routes +from . import interfaces, routes from .builders.manifest import RecordManifestBuilder from .logic import actions, auth diff --git a/docs/_scripts/gen_api_pages.py b/docs/_scripts/gen_api_pages.py index 950143f..0b53f15 100644 --- a/docs/_scripts/gen_api_pages.py +++ b/docs/_scripts/gen_api_pages.py @@ -1,6 +1,5 @@ # !/usr/bin/env python # encoding: utf-8 - """ Generate the code reference pages and navigation. diff --git a/tests/integration/test_actions.py b/tests/integration/test_actions.py index 0b474cb..5a4c963 100644 --- a/tests/integration/test_actions.py +++ b/tests/integration/test_actions.py @@ -1,7 +1,7 @@ +from unittest.mock import MagicMock, patch + import pytest from ckan.plugins import toolkit -from ckan.tests import factories -from unittest.mock import MagicMock, patch from ckanext.iiif.builders.manifest import RecordManifestBuilder diff --git a/tests/integration/test_iiif_route.py b/tests/integration/test_iiif_route.py index 1c7f938..64994d6 100644 --- a/tests/integration/test_iiif_route.py +++ b/tests/integration/test_iiif_route.py @@ -1,7 +1,7 @@ import json +from unittest.mock import MagicMock, call, patch import pytest -from unittest.mock import patch, MagicMock, call @pytest.mark.ckan_config('ckan.plugins', 'iiif') diff --git a/tests/unit/builders/test_manifest.py b/tests/unit/builders/test_manifest.py index 318454a..b367bb1 100644 --- a/tests/unit/builders/test_manifest.py +++ b/tests/unit/builders/test_manifest.py @@ -1,11 +1,12 @@ +from unittest.mock import MagicMock, patch + import pytest from ckan.logic import NotFound from ckan.plugins import toolkit from ckan.tests import factories -from unittest.mock import patch, MagicMock from ckanext.iiif.builders.manifest import RecordManifestBuilder -from ckanext.iiif.builders.utils import wrap_language, IIIFBuildError +from ckanext.iiif.builders.utils import IIIFBuildError, wrap_language class TestBuildManifestID: diff --git a/tests/unit/builders/test_utils.py b/tests/unit/builders/test_utils.py index de28a4f..5d29dbd 100644 --- a/tests/unit/builders/test_utils.py +++ b/tests/unit/builders/test_utils.py @@ -1,6 +1,7 @@ -from ckanext.iiif.builders.utils import wrap_language from mock import MagicMock +from ckanext.iiif.builders.utils import wrap_language + def test_wrap_language(): # use a mock to test that nothing gets changed (i.e. the function doesn't try to diff --git a/tests/unit/logic/test_actions.py b/tests/unit/logic/test_actions.py index 05c7f9d..8fe2aa1 100644 --- a/tests/unit/logic/test_actions.py +++ b/tests/unit/logic/test_actions.py @@ -1,9 +1,10 @@ +from unittest.mock import MagicMock, patch + import pytest -from unittest.mock import patch, MagicMock from ckanext.iiif.builders.manifest import RecordManifestBuilder from ckanext.iiif.builders.utils import IIIFBuildError -from ckanext.iiif.logic.actions import build_iiif_resource, build_iiif_identifier +from ckanext.iiif.logic.actions import build_iiif_identifier, build_iiif_resource class TestBuildIIIFResource: diff --git a/tests/unit/logic/test_auth.py b/tests/unit/logic/test_auth.py index 8ef0539..3c419cc 100644 --- a/tests/unit/logic/test_auth.py +++ b/tests/unit/logic/test_auth.py @@ -1,6 +1,6 @@ from unittest.mock import MagicMock -from ckanext.iiif.logic.auth import build_iiif_resource, build_iiif_identifier +from ckanext.iiif.logic.auth import build_iiif_identifier, build_iiif_resource class TestBuildIIIFResource: diff --git a/tests/unit/routes/test_iiif.py b/tests/unit/routes/test_iiif.py index cccd10f..e93ec8d 100644 --- a/tests/unit/routes/test_iiif.py +++ b/tests/unit/routes/test_iiif.py @@ -1,6 +1,7 @@ +from unittest.mock import MagicMock, patch + import pytest from flask import Response -from unittest.mock import patch, MagicMock from ckanext.iiif.routes.iiif import blueprint, resource diff --git a/tests/unit/test_plugin.py b/tests/unit/test_plugin.py index 81250b0..26600db 100644 --- a/tests/unit/test_plugin.py +++ b/tests/unit/test_plugin.py @@ -1,6 +1,7 @@ +from unittest.mock import MagicMock, call, patch + import pytest from ckan.tests import factories -from unittest.mock import patch, MagicMock, call from ckanext.iiif.builders.manifest import RecordManifestBuilder from ckanext.iiif.logic import actions