diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 23eea98..8b88622 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/pyproject.toml b/pyproject.toml index badb390..19ee7a5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 diff --git a/sigal/gallery.py b/sigal/gallery.py index 926c4a0..d78f3fa 100644 --- a/sigal/gallery.py +++ b/sigal/gallery.py @@ -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, diff --git a/sigal/plugins/titleregexp.py b/sigal/plugins/titleregexp.py index 5f50377..9814ad6 100644 --- a/sigal/plugins/titleregexp.py +++ b/sigal/plugins/titleregexp.py @@ -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) diff --git a/sigal/plugins/upload_s3.py b/sigal/plugins/upload_s3.py index 5cab211..6752449 100644 --- a/sigal/plugins/upload_s3.py +++ b/sigal/plugins/upload_s3.py @@ -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) diff --git a/sigal/plugins/zip_gallery.py b/sigal/plugins/zip_gallery.py index 28bcbcb..5901d50 100644 --- a/sigal/plugins/zip_gallery.py +++ b/sigal/plugins/zip_gallery.py @@ -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 diff --git a/tests/sample/sigal.conf.py b/tests/sample/sigal.conf.py index de18d13..d11348e 100644 --- a/tests/sample/sigal.conf.py +++ b/tests/sample/sigal.conf.py @@ -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, + } ] } diff --git a/tests/test_cli.py b/tests/test_cli.py index e0de643..7191572 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -105,7 +105,6 @@ def test_serve(tmpdir): def test_set_meta(tmpdir): - testdir = tmpdir.mkdir("test") testfile = tmpdir.join("test.jpg") diff --git a/tests/test_gallery.py b/tests/test_gallery.py index 49f0bce..6159e58 100644 --- a/tests/test_gallery.py +++ b/tests/test_gallery.py @@ -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' diff --git a/tests/test_plugins.py b/tests/test_plugins.py index 6d0a08f..ce5f837 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -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"]