From b6336b0183b2e5c95c8e65501278ccc69a5d78e2 Mon Sep 17 00:00:00 2001 From: Bastien Abadie <abadie@teklia.com> Date: Fri, 4 Feb 2022 08:41:08 +0000 Subject: [PATCH] Update pre-commit hooks --- .pre-commit-config.yaml | 12 +++++------- arkindex/dataimport/managers.py | 9 ++++++++- arkindex/dataimport/providers.py | 4 ++-- arkindex/dataimport/tests/test_providers.py | 1 + arkindex/documents/export/entity.sql | 2 +- arkindex/documents/export/entity_link.sql | 2 +- arkindex/documents/export/entity_role.sql | 2 +- arkindex/documents/export/metadata.sql | 2 +- arkindex/documents/export/transcription.sql | 2 +- arkindex/documents/managers.py | 9 ++++++++- arkindex/manage.py | 2 +- arkindex/project/checks.py | 1 + arkindex/project/runtests.py | 4 ++-- arkindex/project/settings.py | 8 ++++---- .../tests/config_samples/expected_errors.yaml | 1 - arkindex/project/tests/test_checks.py | 4 ++-- arkindex/templates/webhook_error.html | 2 +- 17 files changed, 40 insertions(+), 27 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6a49744b1b..02ef6f4264 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 268f5e4b8e..00209913dd 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 370527a19d..718899a39b 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 012477801e..f3d6318e24 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 73d549953f..cf244c881d 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 58b113c51b..443f12374d 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 00c5128ed1..ffe7db4067 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 606ca2d995..c4a9fa7021 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 c1bb2c76b4..1dc0f0402a 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 5bb515bc82..4ec05f7fa8 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 2278abfce0..5343a93157 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 8cb441b7d5..bb6633b1d7 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 11d5f697d1..b4c759741c 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 7b528470c4..6fa4d7b6e9 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 daecdd0337..9f79f1d949 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 a28e8e3730..489e1b49d5 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 8a05086255..d4f4ea1285 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 %} -- GitLab