From 769cbb75cf5a9c15a2b7f41b6a9c7202b9b1c9a6 Mon Sep 17 00:00:00 2001 From: Simon Conseil Date: Sun, 14 Jul 2024 20:07:59 +0200 Subject: [PATCH] pre-commit --- .pre-commit-config.yaml | 10 +++------- pyproject.toml | 9 ++------- src/sigal/gallery.py | 8 +++++--- src/sigal/plugins/compress_assets.py | 7 ++++--- src/sigal/plugins/extended_caching.py | 2 +- src/sigal/plugins/nomedia.py | 2 +- src/sigal/plugins/titleregexp.py | 2 +- src/sigal/plugins/upload_s3.py | 4 ++-- src/sigal/plugins/zip_gallery.py | 2 +- src/sigal/writer.py | 2 +- tests/test_compress_assets_plugin.py | 4 +++- 11 files changed, 24 insertions(+), 28 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f751d68..3c4ad1d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v4.6.0 hooks: - id: check-added-large-files - id: check-merge-conflict @@ -11,13 +11,9 @@ repos: - id: trailing-whitespace exclude: ".*(galleria|photoswipe|jquery|leaflet).*$" -- repo: https://github.com/psf/black - rev: 23.11.0 - hooks: - - id: black - - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.1.4 + rev: v0.5.2 hooks: - id: ruff args: [ --fix, --show-fixes, --exit-non-zero-on-fix ] + - id: ruff-format diff --git a/pyproject.toml b/pyproject.toml index 4ffb392..7f9f7be 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -60,12 +60,7 @@ sigal = [ [tool.setuptools_scm] write_to = "src/sigal/version.py" -[tool.black] -line-length = 88 -target-version = ['py39'] - -[tool.ruff] -target-version = "py39" +[tool.ruff.lint] select = [ "E", "F", "W", # flake8 "I", # isort @@ -76,7 +71,7 @@ unfixable = [ "F841", # Removes unused variables ] -[tool.ruff.isort] +[tool.ruff.lint.isort] known-first-party = ["sigal"] [tool.coverage.run] diff --git a/src/sigal/gallery.py b/src/sigal/gallery.py index 8adfabb..51cb5d7 100644 --- a/src/sigal/gallery.py +++ b/src/sigal/gallery.py @@ -516,7 +516,7 @@ class Album: continue return "" - key = natsort_keygen(key=sort_key, alg=ns.SIGNED|ns.LOCALE) + key = natsort_keygen(key=sort_key, alg=ns.SIGNED | ns.LOCALE) self.subdirs.sort(key=key, reverse=reverse) signals.albums_sorted.send(self) @@ -531,11 +531,13 @@ class Album: elif medias_sort_attr.startswith("meta."): meta_key = medias_sort_attr.split(".", 1)[1] key = natsort_keygen( - key=lambda s: s.meta.get(meta_key, [""])[0], alg=ns.SIGNED|ns.LOCALE + key=lambda s: s.meta.get(meta_key, [""])[0], + alg=ns.SIGNED | ns.LOCALE, ) else: key = natsort_keygen( - key=lambda s: getattr(s, medias_sort_attr), alg=ns.SIGNED|ns.LOCALE + key=lambda s: getattr(s, medias_sort_attr), + alg=ns.SIGNED | ns.LOCALE, ) self.medias.sort(key=key, reverse=self.settings["medias_sort_reverse"]) diff --git a/src/sigal/plugins/compress_assets.py b/src/sigal/plugins/compress_assets.py index 6c2b365..c16482e 100644 --- a/src/sigal/plugins/compress_assets.py +++ b/src/sigal/plugins/compress_assets.py @@ -106,9 +106,10 @@ class GZipCompressor(BaseCompressor): suffix = "gz" def do_compress(self, filename, compressed_filename): - with open(filename, "rb") as f_in, gzip.open( - compressed_filename, "wb" - ) as f_out: + with ( + open(filename, "rb") as f_in, + gzip.open(compressed_filename, "wb") as f_out, + ): shutil.copyfileobj(f_in, f_out) diff --git a/src/sigal/plugins/extended_caching.py b/src/sigal/plugins/extended_caching.py index 4e0d8ac..fce32bb 100644 --- a/src/sigal/plugins/extended_caching.py +++ b/src/sigal/plugins/extended_caching.py @@ -18,7 +18,7 @@ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. -""" Decreases the time needed to build large galleries (e.g.: 25k images in +"""Decreases the time needed to build large galleries (e.g.: 25k images in 2.5s instead of 30s) This plugin allows extended caching, which is useful for large galleries. Once diff --git a/src/sigal/plugins/nomedia.py b/src/sigal/plugins/nomedia.py index 93fb403..0719ed8 100644 --- a/src/sigal/plugins/nomedia.py +++ b/src/sigal/plugins/nomedia.py @@ -18,7 +18,7 @@ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. -""" This plugin offers more fine-grained control over exluded images and +"""This plugin offers more fine-grained control over exluded images and folders, similarly to how it's handled on Android. To ignore a folder or image put a ``.nomedia`` file next to it in its parent diff --git a/src/sigal/plugins/titleregexp.py b/src/sigal/plugins/titleregexp.py index 057725c..d46e776 100644 --- a/src/sigal/plugins/titleregexp.py +++ b/src/sigal/plugins/titleregexp.py @@ -18,7 +18,7 @@ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. -""" This plugin modifies titles of galleries by using regular-expressions and +"""This plugin modifies titles of galleries by using regular-expressions and simple string or character replacements. It is acting in two phases: First, all regular-expression-based modifications are carried out, second, string/character replacements are done. diff --git a/src/sigal/plugins/upload_s3.py b/src/sigal/plugins/upload_s3.py index 6752449..363f6af 100644 --- a/src/sigal/plugins/upload_s3.py +++ b/src/sigal/plugins/upload_s3.py @@ -75,9 +75,9 @@ def generate_cache_metadata(gallery, f): proposed_cache_control = None if "media_max_age" in options and ext in [".jpg", ".png", ".webm", ".mp4"]: - proposed_cache_control = "max-age=%s" % options["media_max_age"] + proposed_cache_control = f"max-age={options['media_max_age']}" elif "max_age" in options: - proposed_cache_control = "max-age=%s" % options["max_age"] + proposed_cache_control = f"max-age={options['max_age']}" return proposed_cache_control diff --git a/src/sigal/plugins/zip_gallery.py b/src/sigal/plugins/zip_gallery.py index 4996f26..9ea58fa 100644 --- a/src/sigal/plugins/zip_gallery.py +++ b/src/sigal/plugins/zip_gallery.py @@ -18,7 +18,7 @@ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. -""" This plugin controls the generation of a ZIP archive for a gallery +"""This plugin controls the generation of a ZIP archive for a gallery If the ``zip_gallery`` setting is set, it contains the location of a zip archive with all original images of the corresponding directory. diff --git a/src/sigal/writer.py b/src/sigal/writer.py index 6831d58..60d3b03 100644 --- a/src/sigal/writer.py +++ b/src/sigal/writer.py @@ -55,7 +55,7 @@ class AbstractWriter: ): self.theme = os.path.join(THEMES_PATH, self.theme) if not os.path.exists(self.theme): - raise Exception("Impossible to find the theme %s" % self.theme) + raise Exception(f"Impossible to find the theme {self.theme}") self.logger.info("Theme : %s", self.theme) theme_relpath = os.path.join(self.theme, "templates") diff --git a/tests/test_compress_assets_plugin.py b/tests/test_compress_assets_plugin.py index 653b98e..2b24ccb 100644 --- a/tests/test_compress_assets_plugin.py +++ b/tests/test_compress_assets_plugin.py @@ -82,5 +82,7 @@ def test_failed_compress( with mock.patch.dict(sys.modules, {mask: None}): make_gallery(settings, tmpdir, method) walk_destination( - settings["destination"], [], compress_suffix # No file should be compressed + settings["destination"], + [], + compress_suffix, # No file should be compressed )