From bab54d1286c096308d7abb8ab6173e90d78b9303 Mon Sep 17 00:00:00 2001 From: Simon Conseil Date: Tue, 6 Jul 2021 22:44:19 +0200 Subject: [PATCH] Add pre-commit config --- .pre-commit-config.yaml | 19 ++++++++ docs/changelog.py | 1 - docs/faq.rst | 2 +- docs/plugins.rst | 1 - setup.cfg | 4 +- setup.py | 1 + sigal/image.py | 3 +- sigal/plugins/adjust.py | 1 + sigal/plugins/encrypt/static/decrypt.js | 48 +++++++++---------- sigal/plugins/nonmedia_files.py | 4 +- sigal/themes/default/templates/piwik.html | 2 +- .../flickr_jerquiaga_2394751088_cc-by-nc.md | 1 - .../dir1/test2/CMB_Timeline300_no_WMAP.md | 1 - .../sample/pictures/nomedia/created/.nomedia | 2 +- tests/test_image.py | 2 +- tests/test_video.py | 2 +- 16 files changed, 54 insertions(+), 40 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..459a30b --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,19 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: + - id: check-yaml + - id: check-added-large-files + - id: trailing-whitespace + exclude: ".*(galleria|photoswipe|jquery).*$" + - id: end-of-file-fixer + exclude: ".*(galleria|photoswipe|jquery).*$" +- repo: https://gitlab.com/pycqa/flake8 + rev: 3.9.2 + hooks: + - id: flake8 + types: [file, python] +- repo: https://github.com/timothycrosley/isort + rev: 5.8.0 + hooks: + - id: isort diff --git a/docs/changelog.py b/docs/changelog.py index 9a5ff74..dc95ea8 100644 --- a/docs/changelog.py +++ b/docs/changelog.py @@ -37,7 +37,6 @@ import os import re from git import Repo - from github import Github this_repo = Repo(os.path.join(os.path.dirname(__file__), "..")) diff --git a/docs/faq.rst b/docs/faq.rst index 3bf379b..6e3ed7f 100644 --- a/docs/faq.rst +++ b/docs/faq.rst @@ -119,7 +119,7 @@ end of the file, like so:: #!/bin/sh # automatically configured by git-annex git annex post-receive - + /home/foo/src/git-hooks/sigal-git-hook This assumes, of course, that you are running your own Git server; diff --git a/docs/plugins.rst b/docs/plugins.rst index c2d8a28..7637342 100644 --- a/docs/plugins.rst +++ b/docs/plugins.rst @@ -145,4 +145,3 @@ ZIP Gallery plugin ================== .. automodule:: sigal.plugins.zip_gallery - diff --git a/setup.cfg b/setup.cfg index e2d28ce..fba82bb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -56,7 +56,7 @@ ignore = readthedocs.yml [flake8] -ignore = E731, W504 +ignore = E731,W504,E501 [isort] -known_third_party=blinker,click,jinja2,markdown,natsort,PIL,Pillow +known_third_party=blinker,click,jinja2,markdown,natsort,PIL,Pillow,pilkit diff --git a/setup.py b/setup.py index 8bf1ba9..6068493 100644 --- a/setup.py +++ b/setup.py @@ -1,2 +1,3 @@ from setuptools import setup + setup() diff --git a/sigal/image.py b/sigal/image.py index 55af92a..7a068f8 100644 --- a/sigal/image.py +++ b/sigal/image.py @@ -37,11 +37,10 @@ import warnings from copy import deepcopy from datetime import datetime +import pilkit.processors from PIL import Image as PILImage from PIL import ImageFile, ImageOps, IptcImagePlugin from PIL.ExifTags import GPSTAGS, TAGS - -import pilkit.processors from pilkit.processors import Transpose from pilkit.utils import save_image diff --git a/sigal/plugins/adjust.py b/sigal/plugins/adjust.py index 82a3779..6e517e0 100644 --- a/sigal/plugins/adjust.py +++ b/sigal/plugins/adjust.py @@ -18,6 +18,7 @@ Settings:: import logging from pilkit.processors import Adjust + from sigal import signals logger = logging.getLogger(__name__) diff --git a/sigal/plugins/encrypt/static/decrypt.js b/sigal/plugins/encrypt/static/decrypt.js index e640c44..079ba41 100644 --- a/sigal/plugins/encrypt/static/decrypt.js +++ b/sigal/plugins/encrypt/static/decrypt.js @@ -7,10 +7,10 @@ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or * sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -82,7 +82,7 @@ class Decryptor { const aes_key = await Decryptor._initAesKey(crypto, salt, iters, shared_key); if (await this._swCheckAesKey(aes_key, gcm_tag)) { this.workerReady = true; - this._decrypt = (encrypted_blob_arraybuffer) => + this._decrypt = (encrypted_blob_arraybuffer) => Decryptor.decrypt(crypto, encrypted_blob_arraybuffer, aes_key, gcm_tag); this._swNotifyWorkerReady(); } else { @@ -167,7 +167,7 @@ class Decryptor { _mGetLocalConfig() { try { const local_config = JSON.parse(localStorage.getItem(this._config.galleryId)); - if (local_config + if (local_config && local_config.galleryId && local_config.sw_script && local_config.password @@ -178,7 +178,7 @@ class Decryptor { } } catch (e) { console.error("Error retrieving config from local storage: " + e); - } + } return null; } @@ -196,7 +196,7 @@ class Decryptor { this.serviceWorker = registration.active; } - navigator.serviceWorker.onmessage = + navigator.serviceWorker.onmessage = (e) => Decryptor.onMessage(this.serviceWorker, e); this.serviceWorker = this._proxyWrap(this.serviceWorker); @@ -283,10 +283,10 @@ class Decryptor { static async _initAesKey(crypto, kdf_salt, kdf_iters, shared_key) { const pbkdf2key = await crypto.importKey( - "raw", - shared_key, - "PBKDF2", - false, + "raw", + shared_key, + "PBKDF2", + false, ["deriveKey"] ); const pbkdf2params = { @@ -296,10 +296,10 @@ class Decryptor { iterations: kdf_iters }; return await crypto.deriveKey( - pbkdf2params, - pbkdf2key, - { name: "AES-GCM", length: 128 }, - false, + pbkdf2params, + pbkdf2key, + { name: "AES-GCM", length: 128 }, + false, ["decrypt"] ); } @@ -315,8 +315,8 @@ class Decryptor { static async checkMagicString(arraybuffer) { const sample = new DataView( - arraybuffer, - 0, + arraybuffer, + 0, Decryptor.MAGIC_STRING_ARRAYBUFFER.byteLength ); for (let i = 0; i < Decryptor.MAGIC_STRING_ARRAYBUFFER.byteLength; i++) { @@ -343,7 +343,7 @@ class Decryptor { // although 1 byte of data seems not acceptable for some browsers // in which case crypto.decrypt will throw an error // "The provided data is too small" - if (arraybuffer.byteLength < + if (arraybuffer.byteLength < Decryptor.MAGIC_STRING_ARRAYBUFFER.byteLength + Decryptor.IV_LENGTH + 1) { @@ -354,14 +354,14 @@ class Decryptor { // data is not encrypted return blob_or_arraybuffer; } - + const iv = new DataView( - arraybuffer, - Decryptor.MAGIC_STRING_ARRAYBUFFER.byteLength, + arraybuffer, + Decryptor.MAGIC_STRING_ARRAYBUFFER.byteLength, Decryptor.IV_LENGTH ); const ciphertext = new DataView( - arraybuffer, + arraybuffer, Decryptor.MAGIC_STRING_ARRAYBUFFER.byteLength + Decryptor.IV_LENGTH ); const decrypted = await crypto.decrypt( @@ -437,7 +437,7 @@ class Decryptor { if (!(method in instance && instance[method] instanceof Function)) { return Promise.reject(new Error(`no such method: ${method}`)) } - + try { let promise_or_value = instance[method].apply(instance, args); if (promise_or_value instanceof Promise) { @@ -462,7 +462,7 @@ class Decryptor { Decryptor._asyncReturn(instance, method, args) .then( - (result) => { return {type: "reply", success: true, result: result}; }, + (result) => { return {type: "reply", success: true, result: result}; }, (error) => { return {type: "reply", success: false, result: error.message}; } ) .then((reply) => { @@ -589,7 +589,7 @@ class Decryptor { } ); decrypted_response.headers.set("content-length", decrypted_blob.size); - + Decryptor._addToCache(request, decrypted_response.clone()); console.debug(`Responding with decrypted response ${request.url}`); diff --git a/sigal/plugins/nonmedia_files.py b/sigal/plugins/nonmedia_files.py index 7b962e0..66b385a 100644 --- a/sigal/plugins/nonmedia_files.py +++ b/sigal/plugins/nonmedia_files.py @@ -30,11 +30,9 @@ import os from PIL import Image as PILImage from PIL import ImageDraw, ImageFont - from pilkit.utils import save_image -from sigal import signals -from sigal import utils +from sigal import signals, utils from sigal.gallery import Media from sigal.settings import Status diff --git a/sigal/themes/default/templates/piwik.html b/sigal/themes/default/templates/piwik.html index 29c099a..1c50a88 100644 --- a/sigal/themes/default/templates/piwik.html +++ b/sigal/themes/default/templates/piwik.html @@ -14,4 +14,4 @@ -{% endif %} \ No newline at end of file +{% endif %} diff --git a/tests/sample/pictures/dir1/test1/flickr_jerquiaga_2394751088_cc-by-nc.md b/tests/sample/pictures/dir1/test1/flickr_jerquiaga_2394751088_cc-by-nc.md index d871335..e83f419 100644 --- a/tests/sample/pictures/dir1/test1/flickr_jerquiaga_2394751088_cc-by-nc.md +++ b/tests/sample/pictures/dir1/test1/flickr_jerquiaga_2394751088_cc-by-nc.md @@ -1,4 +1,3 @@ Title: WÎth spécial chÆracters This is a funny description of this image - diff --git a/tests/sample/pictures/dir1/test2/CMB_Timeline300_no_WMAP.md b/tests/sample/pictures/dir1/test2/CMB_Timeline300_no_WMAP.md index 88db3c4..027cbf9 100644 --- a/tests/sample/pictures/dir1/test2/CMB_Timeline300_no_WMAP.md +++ b/tests/sample/pictures/dir1/test2/CMB_Timeline300_no_WMAP.md @@ -1,2 +1 @@ Order: 03 - diff --git a/tests/sample/pictures/nomedia/created/.nomedia b/tests/sample/pictures/nomedia/created/.nomedia index d40f1d0..6ef7803 100644 --- a/tests/sample/pictures/nomedia/created/.nomedia +++ b/tests/sample/pictures/nomedia/created/.nomedia @@ -1,2 +1,2 @@ should_be_ignored3.jpg -ignored \ No newline at end of file +ignored diff --git a/tests/test_image.py b/tests/test_image.py index 2d20156..a22bdf9 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -5,9 +5,9 @@ import pytest from PIL import Image as PILImage from sigal import init_logging +from sigal.gallery import Image from sigal.image import (generate_image, generate_thumbnail, get_exif_data, get_exif_tags, get_iptc_data, get_size, process_image) -from sigal.gallery import Image from sigal.settings import Status, create_settings CURRENT_DIR = os.path.dirname(__file__) diff --git a/tests/test_video.py b/tests/test_video.py index e801682..a01f88a 100644 --- a/tests/test_video.py +++ b/tests/test_video.py @@ -1,4 +1,5 @@ import os +from unittest.mock import patch import pytest @@ -6,7 +7,6 @@ from sigal.gallery import Video from sigal.settings import Status, create_settings from sigal.video import (generate_thumbnail, generate_video, process_video, video_size) -from unittest.mock import patch CURRENT_DIR = os.path.dirname(__file__) SRCDIR = os.path.join(CURRENT_DIR, 'sample', 'pictures')