From 31160448df742f1f37a99a8bf1d0910b4107fd8d Mon Sep 17 00:00:00 2001 From: Bastien Abadie <bastien@nextcairn.com> Date: Tue, 23 Jun 2020 14:50:00 +0000 Subject: [PATCH] Add pre-commit basic checks --- .pre-commit-config.yaml | 18 +++++++++++ README.md | 4 +-- arkindex/dataimport/models.py | 8 ++--- .../documents/fixtures/roles_transkribus.yml | 30 +++++++++---------- .../tests/config_samples/expected_errors.yaml | 6 ++-- ci/static-deploy.sh | 1 + requirements.txt | 10 +++---- tests-requirements.txt | 6 ++-- 8 files changed, 50 insertions(+), 33 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 91d535dffa..16f3ccafcd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,6 +6,24 @@ repos: 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 + hooks: + - id: check-ast + - id: check-docstring-first + - id: check-executables-have-shebangs + - id: check-merge-conflict + - id: check-symlinks + - id: debug-statements + - id: trailing-whitespace + exclude: '^arkindex/documents/tests/pagexml_samples/(.*).xml$' + - id: check-yaml + args: [--allow-multiple-documents] + - id: mixed-line-ending + - id: name-tests-test + args: ['--django'] + - id: check-json + - id: requirements-txt-fixer - repo: meta hooks: - id: check-useless-excludes diff --git a/README.md b/README.md index 7ee405e331..944683fd82 100644 --- a/README.md +++ b/README.md @@ -122,8 +122,8 @@ See `manage.py <command> --help` to view more details about a specific command. Once your code appears to be working on a local server, a few checks have to be performed: * **Migrations:** Ensure that all migrations have been created by typing `./manage.py makemigrations`. -* **Unit tests:** Run `./manage.py test` to perform unit tests. - Use `./manage.py test module_name` to perform tests on a single module, if you wish to spend less time waiting for all tests to complete. +* **Unit tests:** Run `./manage.py test` to perform unit tests. + - Use `./manage.py test module_name` to perform tests on a single module, if you wish to spend less time waiting for all tests to complete. ### Linting diff --git a/arkindex/dataimport/models.py b/arkindex/dataimport/models.py index d27463507d..bec3eb7d65 100644 --- a/arkindex/dataimport/models.py +++ b/arkindex/dataimport/models.py @@ -196,12 +196,10 @@ class DataImport(IndexableModel): return serializer.validated_data +# The maximum length for DataFile filenames. +# Used in the file upload API because accessing the max_length attribute on a field +# inside a Django model is unnecessarily complex. MAX_FILENAME_LENGTH = 255 -""" -The maximum length for DataFile filenames. -Used in the file upload API because accessing the max_length attribute on a field -inside a Django model is unnecessarily complex. -""" class DataFile(S3FileMixin, models.Model): diff --git a/arkindex/documents/fixtures/roles_transkribus.yml b/arkindex/documents/fixtures/roles_transkribus.yml index ebcc15aac8..fd3bcdd050 100644 --- a/arkindex/documents/fixtures/roles_transkribus.yml +++ b/arkindex/documents/fixtures/roles_transkribus.yml @@ -1,88 +1,88 @@ -père de l'époux: +père de l'époux: parent_name: père child_name: enfant parent_type: person child_type: person link_with: époux -mère de l'époux: +mère de l'époux: parent_name: mère child_name: enfant parent_type: person child_type: person link_with: époux -père de l'épouse: +père de l'épouse: parent_name: père child_name: enfant parent_type: person child_type: person link_with: épouse -mère de l'épouse: +mère de l'épouse: parent_name: mère child_name: enfant parent_type: person child_type: person link_with: épouse -marraine: +marraine: parent_name: marraine child_name: filleul parent_type: person child_type: person link_with: sujet -parrain: +parrain: parent_name: parrain child_name: filleul parent_type: person child_type: person link_with: sujet -conjoint: +conjoint: parent_name: conjoint child_name: conjointe parent_type: person child_type: person link_with: conjointe -conjointe: +conjointe: parent_name: conjointe child_name: conjoint parent_type: person child_type: person link_with: conjoint -ex-conjointe: +ex-conjointe: parent_name: ex-conjointe child_name: ex-conjoint parent_type: person child_type: person link_with: conjoint -ex-conjoint: +ex-conjoint: parent_name: ex-conjoint child_name: ex-conjointe parent_type: person child_type: person link_with: conjointe -témoin: +témoin: parent_name: témoin child_name: sujet parent_type: person child_type: person link_with: sujet -époux: +époux: parent_name: époux child_name: épouse parent_type: person child_type: person link_with: épouse -épouse: +épouse: parent_name: épouse child_name: époux parent_type: person child_type: person link_with: époux -père: +père: parent_name: père child_name: enfant parent_type: person child_type: person link_with: sujet -mère: +mère: parent_name: mère child_name: enfant parent_type: person diff --git a/arkindex/project/tests/config_samples/expected_errors.yaml b/arkindex/project/tests/config_samples/expected_errors.yaml index fcafdb5694..e7314adf6a 100644 --- a/arkindex/project/tests/config_samples/expected_errors.yaml +++ b/arkindex/project/tests/config_samples/expected_errors.yaml @@ -1,20 +1,20 @@ cache: url: cache.url is required for a Redis cache -cors: +cors: suffixes: "'int' object is not iterable" csrf: cookie_samesite: "'relax' is not a valid CookieSameSiteOption" trusted_origins: "'float' object is not iterable" database: port: "invalid literal for int() with base 10: 'rotterdam'" -email: +email: password: This option is required port: This option is required user: This option is required features: sv_cheats: This option does not exist ml_classifiers_dir: /aaaaa does not exist -redis: +redis: capacity: "invalid literal for int() with base 10: 'over nine thousand'" session: cookie_samesite: "'foo' is not a valid CookieSameSiteOption" diff --git a/ci/static-deploy.sh b/ci/static-deploy.sh index da4e19b0ab..15e7b3e247 100755 --- a/ci/static-deploy.sh +++ b/ci/static-deploy.sh @@ -1,3 +1,4 @@ +#!/bin/sh VERSION=${VERSION:-${CI_COMMIT_TAG}} [ -z "$VERSION" ] && echo "No version specified" && exit 1 diff --git a/requirements.txt b/requirements.txt index cae5ec043d..cd6b564a11 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,9 @@ # -r ./base/requirements.txt -arkindex-common==0.2.0 apistar==0.7.2 +git+https://gitlab.com/teklia/apistar.git#egg=apistar +arkindex-common==0.2.0 +git+https://gitlab.com/arkindex/common.git#egg=arkindex-common certifi==2017.7.27.1 channels==2.3.1 channels-redis==2.4.1 @@ -22,11 +24,9 @@ python-magic==0.4.15 python-memcached==1.59 pytz>=2018.7 PyYAML==5.1 -responses==0.10.7 requests==2.22 +responses==0.10.7 sentry-sdk==0.14.3 tenacity==6.2 -urllib3==1.22 uritemplate==3 -git+https://gitlab.com/arkindex/common.git#egg=arkindex-common -git+https://gitlab.com/teklia/apistar.git#egg=apistar +urllib3==1.22 diff --git a/tests-requirements.txt b/tests-requirements.txt index 1fafac3a67..96a6787c4c 100644 --- a/tests-requirements.txt +++ b/tests-requirements.txt @@ -1,5 +1,5 @@ -tripoli -django-nose coverage -responses +django-nose mock~=4.0.0 +responses +tripoli -- GitLab