diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6a49744b1b6784bedff604305af921846438cc63..02ef6f42646f9cc19331908ea8f707c2fe9ca0e7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,21 +1,17 @@ repos: - - repo: https://github.com/asottile/seed-isort-config - rev: v2.2.0 - hooks: - - id: seed-isort-config - repo: https://github.com/pre-commit/mirrors-isort - rev: v4.3.21 + rev: v5.10.1 hooks: - id: isort - repo: https://gitlab.com/pycqa/flake8 - rev: 3.8.3 + rev: 3.9.2 hooks: - id: flake8 additional_dependencies: - 'flake8-copyright==0.2.2' - 'flake8-debugger==3.1.0' - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.1.0 + rev: v4.1.0 hooks: - id: check-ast - id: check-docstring-first @@ -31,6 +27,8 @@ repos: args: ['--django'] - id: check-json - id: requirements-txt-fixer + - id: end-of-file-fixer + - id: mixed-line-ending - repo: meta hooks: - id: check-useless-excludes diff --git a/arkindex/dataimport/managers.py b/arkindex/dataimport/managers.py index 268f5e4b8e472702ad459b75d75759b5a45302b1..00209913ddeee0eb7718704b7ae8ca803817cbf6 100644 --- a/arkindex/dataimport/managers.py +++ b/arkindex/dataimport/managers.py @@ -43,7 +43,14 @@ class CorpusWorkerVersionManager(models.Manager): """ Rebuild the corpus worker versions cache from all ML results. """ - from arkindex.documents.models import Element, Transcription, Entity, TranscriptionEntity, Classification, MetaData + from arkindex.documents.models import ( + Classification, + Element, + Entity, + MetaData, + Transcription, + TranscriptionEntity, + ) querysets = [ Element.objects.exclude(worker_version_id=None).values_list('corpus_id', 'worker_version_id'), diff --git a/arkindex/dataimport/providers.py b/arkindex/dataimport/providers.py index 370527a19d4ab9ff44bfeefdee51eb34993f5e9b..718899a39b4dc86379607670a839951ad5a59f1d 100644 --- a/arkindex/dataimport/providers.py +++ b/arkindex/dataimport/providers.py @@ -106,7 +106,7 @@ class GitProvider(ABC): For a worker repository, start a single process to build the new workers For other repositories, start a process for each corpus depending on the repository """ - from arkindex.dataimport.models import DataImport, RepositoryType, DataImportMode + from arkindex.dataimport.models import DataImport, DataImportMode, RepositoryType mode = DataImportMode.Repository user = rev.repo.credentials.user refs = ", ".join(rev.refs.values_list('name', flat=True)) @@ -279,7 +279,7 @@ class GitLabProvider(GitProvider): raise APIException("Error while creating GitLab hook: {}".format(str(e))) def create_revision(self, repo, sha, save=True): - from arkindex.dataimport.models import Revision, GitRefType + from arkindex.dataimport.models import GitRefType, Revision project = self._get_project_from_repo(repo) commit = project.commits.get(sha) diff --git a/arkindex/dataimport/tests/test_providers.py b/arkindex/dataimport/tests/test_providers.py index 012477801e468d040a581ec9a53a8429b7076963..f3d6318e2461efcfb276505824bc814f2fc7ee12 100644 --- a/arkindex/dataimport/tests/test_providers.py +++ b/arkindex/dataimport/tests/test_providers.py @@ -20,6 +20,7 @@ Please, try again with another push or contact your system administrator. -- Arkindex + """ diff --git a/arkindex/documents/export/entity.sql b/arkindex/documents/export/entity.sql index 73d549953fc3bc6598c7c950437a6538abe99162..cf244c881d5b5bd40b26560a7f752647abb99526 100644 --- a/arkindex/documents/export/entity.sql +++ b/arkindex/documents/export/entity.sql @@ -8,4 +8,4 @@ SELECT entity.worker_version_id FROM documents_entity entity LEFT JOIN users_user moderator ON (moderator.id = entity.moderator_id) -WHERE entity.corpus_id = '{corpus_id}'::uuid \ No newline at end of file +WHERE entity.corpus_id = '{corpus_id}'::uuid diff --git a/arkindex/documents/export/entity_link.sql b/arkindex/documents/export/entity_link.sql index 58b113c51b913ea6de908442e67d9367ac6336f0..443f12374d48c43a0ff29ac9982e2dc315549988 100644 --- a/arkindex/documents/export/entity_link.sql +++ b/arkindex/documents/export/entity_link.sql @@ -1,4 +1,4 @@ SELECT link.id, link.parent_id, link.child_id, link.role_id FROM documents_entitylink link INNER JOIN documents_entityrole role ON (link.role_id = role.id) -WHERE role.corpus_id = '{corpus_id}'::uuid \ No newline at end of file +WHERE role.corpus_id = '{corpus_id}'::uuid diff --git a/arkindex/documents/export/entity_role.sql b/arkindex/documents/export/entity_role.sql index 00c5128ed10e0df64f69a4ee640912960208e39d..ffe7db4067f46370a9d39c2e13109ac6e42999f8 100644 --- a/arkindex/documents/export/entity_role.sql +++ b/arkindex/documents/export/entity_role.sql @@ -1,3 +1,3 @@ SELECT id, parent_name, child_name, parent_type, child_type FROM documents_entityrole -WHERE corpus_id = '{corpus_id}'::uuid \ No newline at end of file +WHERE corpus_id = '{corpus_id}'::uuid diff --git a/arkindex/documents/export/metadata.sql b/arkindex/documents/export/metadata.sql index 606ca2d995c23611f64caaf03c163b8031f724cd..c4a9fa7021f8d538895a27b7541635dae26a54b1 100644 --- a/arkindex/documents/export/metadata.sql +++ b/arkindex/documents/export/metadata.sql @@ -8,4 +8,4 @@ SELECT metadata.worker_version_id FROM documents_metadata metadata INNER JOIN documents_element element ON (element.id = metadata.element_id) -WHERE element.corpus_id = '{corpus_id}'::uuid \ No newline at end of file +WHERE element.corpus_id = '{corpus_id}'::uuid diff --git a/arkindex/documents/export/transcription.sql b/arkindex/documents/export/transcription.sql index c1bb2c76b4a88e86215a0a2550656f3817cfc5fb..1dc0f0402ae717e5f4959f11b2b1566cda851b62 100644 --- a/arkindex/documents/export/transcription.sql +++ b/arkindex/documents/export/transcription.sql @@ -6,4 +6,4 @@ SELECT transcription.worker_version_id FROM documents_transcription transcription INNER JOIN documents_element element ON (element.id = transcription.element_id) -WHERE element.corpus_id = '{corpus_id}'::uuid \ No newline at end of file +WHERE element.corpus_id = '{corpus_id}'::uuid diff --git a/arkindex/documents/managers.py b/arkindex/documents/managers.py index 5bb515bc8259e7e0c6f86e9d63ab1d1d698ec8b4..4ec05f7fa8ded0ee4b3b334823fe300e171e45bf 100644 --- a/arkindex/documents/managers.py +++ b/arkindex/documents/managers.py @@ -21,8 +21,15 @@ class ElementQuerySet(models.QuerySet): def trash(self, delete_children=True): """Performant deletion of any element queryset""" - from arkindex.documents.models import Element, MetaData, Transcription, TranscriptionEntity, Classification, Selection from arkindex.dataimport.models import DataImport, DataImportElement, WorkerActivity + from arkindex.documents.models import ( + Classification, + Element, + MetaData, + Selection, + Transcription, + TranscriptionEntity, + ) # We only need the Element IDs to join on other models # Disable all ordering as it will not be required for deletions diff --git a/arkindex/manage.py b/arkindex/manage.py index 2278abfce086c968f1bd551a0640d10b7a8a8769..5343a931579e20fc97b8eec1f533b615a24b9176 100755 --- a/arkindex/manage.py +++ b/arkindex/manage.py @@ -11,7 +11,7 @@ if __name__ == "__main__": # issue is really that Django is missing to avoid masking other # exceptions on Python 2. try: - import django # noqa + import django # noqa except ImportError: raise ImportError( "Couldn't import Django. Are you sure it's installed and " diff --git a/arkindex/project/checks.py b/arkindex/project/checks.py index 8cb441b7d5323c1bdac21fc2c55cb4cb2422e4ed..bb6633b1d70b6b92041b242d7a7ed5ed5f6ee8d4 100644 --- a/arkindex/project/checks.py +++ b/arkindex/project/checks.py @@ -43,6 +43,7 @@ def local_imageserver_check(*args, **kwargs): Check that the configured local ImageServer exists """ from django.conf import settings + from arkindex.images.models import ImageServer local_id = settings.LOCAL_IMAGESERVER_ID diff --git a/arkindex/project/runtests.py b/arkindex/project/runtests.py index 11d5f697d192ed31f2c269c7dd371ed89226d308..b4c759741c6eb6179e276b1733270c34766aefb4 100644 --- a/arkindex/project/runtests.py +++ b/arkindex/project/runtests.py @@ -9,9 +9,9 @@ sys.path.insert(0, test_dir) def run(): # Setup django - from django.test.utils import get_runner - from django.conf import settings import django + from django.conf import settings + from django.test.utils import get_runner django.setup() # Run tests on arkindex apps diff --git a/arkindex/project/settings.py b/arkindex/project/settings.py index 7b528470c41696dcf270be74b5083c66fdb5e202..6fa4d7b6e9bea7b8686bfc1a1633dc8a801a6ab4 100644 --- a/arkindex/project/settings.py +++ b/arkindex/project/settings.py @@ -570,7 +570,7 @@ if TEST_ENV: # Optional unit tests runner with code coverage try: - import django_nose # noqa + import django_nose # noqa INSTALLED_APPS.append('django_nose') TEST_RUNNER = 'django_nose.NoseTestSuiteRunner' NOSE_ARGS = [ @@ -584,7 +584,7 @@ except ImportError: # Local settings if DEBUG and not TEST_ENV: try: - from .local_settings import * # noqa + from .local_settings import * # noqa except ImportError: pass @@ -602,7 +602,7 @@ except ImportError: pass try: - import debug_toolbar.settings # noqa + import debug_toolbar.settings # noqa MIDDLEWARE.insert(0, 'debug_toolbar.middleware.DebugToolbarMiddleware') INSTALLED_APPS.append('debug_toolbar') except ImportError: @@ -611,9 +611,9 @@ except ImportError: if SENTRY_DSN and not DJANGO_SHELL: import sentry_sdk from sentry_sdk.integrations.django import DjangoIntegration + from sentry_sdk.integrations.logging import ignore_logger from sentry_sdk.integrations.redis import RedisIntegration from sentry_sdk.integrations.rq import RqIntegration - from sentry_sdk.integrations.logging import ignore_logger ignore_logger('django.security.DisallowedHost') sentry_sdk.init( diff --git a/arkindex/project/tests/config_samples/expected_errors.yaml b/arkindex/project/tests/config_samples/expected_errors.yaml index daecdd0337c11660d18096e68dbb3e7eb886e492..9f79f1d94921567dd537c6e3527a5f5dd0458826 100644 --- a/arkindex/project/tests/config_samples/expected_errors.yaml +++ b/arkindex/project/tests/config_samples/expected_errors.yaml @@ -29,4 +29,3 @@ session: cookie_samesite: "'foo' is not a valid CookieSameSiteOption" static: root_path: /aaaaa does not exist - diff --git a/arkindex/project/tests/test_checks.py b/arkindex/project/tests/test_checks.py index a28e8e3730b13c4135fcf1400debd74c4ecbb397..489e1b49d51b357661b9242f500ad939394d69d4 100644 --- a/arkindex/project/tests/test_checks.py +++ b/arkindex/project/tests/test_checks.py @@ -14,8 +14,8 @@ class ChecksTestCase(TestCase): ''' Check should always be OK ''' - from arkindex.project.checks import api_urls_check from arkindex.project.api_v1 import api + from arkindex.project.checks import api_urls_check self.assertListEqual(api_urls_check(), []) @@ -39,8 +39,8 @@ class ChecksTestCase(TestCase): """ Test the local imageserver existence check """ - from arkindex.project.checks import local_imageserver_check from arkindex.images.models import ImageServer + from arkindex.project.checks import local_imageserver_check self.assertEqual(ImageServer.objects.count(), 0) with self.settings(LOCAL_IMAGESERVER_ID=42): diff --git a/arkindex/templates/webhook_error.html b/arkindex/templates/webhook_error.html index 8a05086255aa2b3383b18be72cd48f6523af5bf2..d4f4ea1285f3bed0296c7aba56ad5efc4b1fcc85 100644 --- a/arkindex/templates/webhook_error.html +++ b/arkindex/templates/webhook_error.html @@ -10,4 +10,4 @@ Please, try again with another push or contact your system administrator. -- Arkindex -{% endautoescape %} \ No newline at end of file +{% endautoescape %}