Update and run pre-commit
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.1.0
|
||||
rev: v4.3.0
|
||||
hooks:
|
||||
- id: check-yaml
|
||||
- id: check-added-large-files
|
||||
@@ -18,6 +18,6 @@ repos:
|
||||
hooks:
|
||||
- id: isort
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 21.12b0
|
||||
rev: 22.6.0
|
||||
hooks:
|
||||
- id: black
|
||||
|
||||
@@ -8,5 +8,5 @@ write_to = "sigal/version.py"
|
||||
[tool.black]
|
||||
line-length = 88
|
||||
target-version = ['py38']
|
||||
experimental-string-processing = true
|
||||
preview = true
|
||||
skip-string-normalization = true
|
||||
|
||||
@@ -494,7 +494,7 @@ class Album:
|
||||
|
||||
def sort_key(s):
|
||||
sort_attr = albums_sort_attr
|
||||
if not isinstance(sort_attr,list):
|
||||
if not isinstance(sort_attr, list):
|
||||
sort_attr = [sort_attr]
|
||||
|
||||
album = self.gallery.albums[join(root_path, s)]
|
||||
@@ -803,7 +803,6 @@ class Gallery:
|
||||
|
||||
self.logger.info("Using %s cores", ncpu)
|
||||
if ncpu > 1:
|
||||
|
||||
self.pool = multiprocessing.Pool(
|
||||
processes=ncpu,
|
||||
initializer=pool_init,
|
||||
|
||||
@@ -57,36 +57,35 @@ Example::
|
||||
"""
|
||||
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
|
||||
from sigal import signals
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def titleregexp(album):
|
||||
"""Create a title by regexping name"""
|
||||
#logger.info("DEBUG: name=%s, path=%s, title=%s", album.name, album.path, album.title)
|
||||
#print(dir(album))
|
||||
|
||||
cfg = album.settings.get('titleregexp')
|
||||
|
||||
n = 0
|
||||
total = 0
|
||||
album_title_org = album.title
|
||||
|
||||
for r in cfg.get('regexp') :
|
||||
album.title, n = re.subn(r.get('search'), r.get('replace'), album.title, r.get('count', 0))
|
||||
for r in cfg.get('regexp'):
|
||||
album.title, n = re.subn(
|
||||
r.get('search'), r.get('replace'), album.title, r.get('count', 0)
|
||||
)
|
||||
total += n
|
||||
|
||||
if n>0 :
|
||||
for s in r.get('substitute', []) :
|
||||
album.title = album.title.replace(s[0],s[1])
|
||||
if r.get('break','') != '' :
|
||||
if n > 0:
|
||||
for s in r.get('substitute', []):
|
||||
album.title = album.title.replace(s[0], s[1])
|
||||
if r.get('break', '') != '':
|
||||
break
|
||||
|
||||
for r in cfg.get('substitute', []) :
|
||||
album.title = album.title.replace(r[0],r[1])
|
||||
for r in cfg.get('substitute', []):
|
||||
album.title = album.title.replace(r[0], r[1])
|
||||
|
||||
if total > 0:
|
||||
logger.info("Fixing title '%s' to '%s'", album_title_org, album.title)
|
||||
|
||||
@@ -50,7 +50,7 @@ def upload_s3(gallery, settings=None):
|
||||
|
||||
# Upload the files
|
||||
with progressbar(upload_files, label="Uploading files to S3") as bar:
|
||||
for (f, size) in bar:
|
||||
for f, size in bar:
|
||||
if gallery.settings["upload_s3_options"]["overwrite"] is False:
|
||||
# Check if file was uploaded before
|
||||
key = bucket.get_key(f)
|
||||
|
||||
@@ -112,7 +112,9 @@ def nozip_gallery_file(album, settings=None):
|
||||
|
||||
|
||||
def check_settings(gallery):
|
||||
if gallery.settings['zip_gallery'] and not isinstance(gallery.settings['zip_gallery'], str):
|
||||
if gallery.settings['zip_gallery'] and not isinstance(
|
||||
gallery.settings['zip_gallery'], str
|
||||
):
|
||||
logger.error("'zip_gallery' should be set to a filename")
|
||||
gallery.settings['zip_gallery'] = False
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ links = [
|
||||
("Another link", "http://example.org"),
|
||||
]
|
||||
|
||||
albums_sort_attr = [ "meta.nokey", "nosuchattribute", "name" ]
|
||||
albums_sort_attr = ["meta.nokey", "nosuchattribute", "name"]
|
||||
|
||||
files_to_copy = (("../watermark.png", "watermark.png"),)
|
||||
|
||||
@@ -44,7 +44,12 @@ atom_feed = {"feed_url": "http://127.0.0.1:8000/feed.atom", "nb_items": 10}
|
||||
|
||||
titleregexp = {
|
||||
"regexp": [
|
||||
{ "search": r"test ?(.*)", "replace": r"titleregexp \1", "substitute": [ [ "2", "02" ] ], "break": 1 }
|
||||
{
|
||||
"search": r"test ?(.*)",
|
||||
"replace": r"titleregexp \1",
|
||||
"substitute": [["2", "02"]],
|
||||
"break": 1,
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +105,6 @@ def test_serve(tmpdir):
|
||||
|
||||
|
||||
def test_set_meta(tmpdir):
|
||||
|
||||
testdir = tmpdir.mkdir("test")
|
||||
|
||||
testfile = tmpdir.join("test.jpg")
|
||||
|
||||
@@ -249,18 +249,18 @@ def test_albums_sort(settings):
|
||||
|
||||
settings['albums_sort_reverse'] = False
|
||||
a = Album('dir1', settings, album['subdirs'], album['medias'], gal)
|
||||
a.sort_subdirs(['meta.partialorder','meta.order'])
|
||||
assert [d.name for d in a.albums] == list(['test1','test2','test3'])
|
||||
a.sort_subdirs(['meta.partialorder', 'meta.order'])
|
||||
assert [d.name for d in a.albums] == list(['test1', 'test2', 'test3'])
|
||||
|
||||
settings['albums_sort_reverse'] = False
|
||||
a = Album('dir1', settings, album['subdirs'], album['medias'], gal)
|
||||
a.sort_subdirs(['meta.partialorderb','name'])
|
||||
assert [d.name for d in a.albums] == list(['test2','test3','test1'])
|
||||
a.sort_subdirs(['meta.partialorderb', 'name'])
|
||||
assert [d.name for d in a.albums] == list(['test2', 'test3', 'test1'])
|
||||
|
||||
settings['albums_sort_reverse'] = True
|
||||
a = Album('dir1', settings, album['subdirs'], album['medias'], gal)
|
||||
a.sort_subdirs(['meta.partialorderb','name'])
|
||||
assert [d.name for d in a.albums] == list(['test1','test3','test2'])
|
||||
a.sort_subdirs(['meta.partialorderb', 'name'])
|
||||
assert [d.name for d in a.albums] == list(['test1', 'test3', 'test2'])
|
||||
|
||||
|
||||
def test_medias_sort(settings):
|
||||
@@ -329,7 +329,6 @@ def test_gallery(settings, tmp_path, caplog):
|
||||
|
||||
|
||||
def test_custom_theme(settings, tmp_path, caplog):
|
||||
|
||||
theme_path = tmp_path / 'mytheme'
|
||||
tpl_path = theme_path / 'templates'
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ CURRENT_DIR = os.path.dirname(__file__)
|
||||
|
||||
|
||||
def test_plugins(settings, tmpdir, disconnect_signals):
|
||||
|
||||
settings['destination'] = str(tmpdir)
|
||||
if "sigal.plugins.nomedia" not in settings["plugins"]:
|
||||
settings['plugins'] += ["sigal.plugins.nomedia"]
|
||||
@@ -31,7 +30,6 @@ def test_plugins(settings, tmpdir, disconnect_signals):
|
||||
|
||||
|
||||
def test_nonmedia_files(settings, tmpdir, disconnect_signals):
|
||||
|
||||
settings['destination'] = str(tmpdir)
|
||||
settings['plugins'] += ['sigal.plugins.nonmedia_files']
|
||||
|
||||
@@ -48,8 +46,8 @@ def test_nonmedia_files(settings, tmpdir, disconnect_signals):
|
||||
)
|
||||
assert os.path.isfile(outthumb)
|
||||
|
||||
def test_titleregexp(settings, tmpdir, disconnect_signals):
|
||||
|
||||
def test_titleregexp(settings, tmpdir, disconnect_signals):
|
||||
if "sigal.plugins.titleregexp" not in settings["plugins"]:
|
||||
settings['plugins'] += ["sigal.plugins.titleregexp"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user