Browse Source

pre-commit

pull/524/head
Simon Conseil 2 years ago
parent
commit
769cbb75cf
  1. 10
      .pre-commit-config.yaml
  2. 9
      pyproject.toml
  3. 8
      src/sigal/gallery.py
  4. 7
      src/sigal/plugins/compress_assets.py
  5. 2
      src/sigal/plugins/extended_caching.py
  6. 2
      src/sigal/plugins/nomedia.py
  7. 2
      src/sigal/plugins/titleregexp.py
  8. 4
      src/sigal/plugins/upload_s3.py
  9. 2
      src/sigal/plugins/zip_gallery.py
  10. 2
      src/sigal/writer.py
  11. 4
      tests/test_compress_assets_plugin.py

10
.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

9
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]

8
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"])

7
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)

2
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

2
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

2
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.

4
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

2
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.

2
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")

4
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
)

Loading…
Cancel
Save