From a95e8acaa269f0aba2109806802f831e3b4d69dc Mon Sep 17 00:00:00 2001 From: Kurt McKee Date: Thu, 11 Feb 2021 18:41:42 -0600 Subject: [PATCH 1/7] Update the copyright to 2021 and parametrize the header testing --- CHANGES.rst | 2 +- LICENSE.txt | 2 +- README.rst | 2 +- dodo.py | 2 +- pelican_precompress.py | 2 +- requirements-dev.txt | 4 ++++ setup.py | 2 +- test_pelican_precompress.py | 26 ++++++++++++++------------ tox.ini | 2 +- 9 files changed, 25 insertions(+), 19 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 4b8b5ea..4692e41 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,5 +1,5 @@ .. This file is part of the pelican_precompress plugin. -.. Copyright 2019-2020 Kurt McKee +.. Copyright 2019-2021 Kurt McKee .. Released under the MIT license. Changelog diff --git a/LICENSE.txt b/LICENSE.txt index 6e7cf00..a5ba4ed 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019-2020 Kurt McKee +Copyright (c) 2019-2021 Kurt McKee Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.rst b/README.rst index b2c05c2..389d65d 100644 --- a/README.rst +++ b/README.rst @@ -1,5 +1,5 @@ .. This file is part of the pelican_precompress plugin. -.. Copyright 2019-2020 Kurt McKee +.. Copyright 2019-2021 Kurt McKee .. Released under the MIT license. pelican_precompress diff --git a/dodo.py b/dodo.py index fa663e8..0d05951 100644 --- a/dodo.py +++ b/dodo.py @@ -1,5 +1,5 @@ # This file is part of the pelican-precompress plugin. -# Copyright 2019-2020 Kurt McKee +# Copyright 2019-2021 Kurt McKee # Released under the MIT license. # The tasks defined in this file automates the entire diff --git a/pelican_precompress.py b/pelican_precompress.py index ea633d5..79fc7e8 100644 --- a/pelican_precompress.py +++ b/pelican_precompress.py @@ -1,5 +1,5 @@ # This file is part of the pelican-precompress plugin. -# Copyright 2019-2020 Kurt McKee +# Copyright 2019-2021 Kurt McKee # Released under the MIT license. import functools diff --git a/requirements-dev.txt b/requirements-dev.txt index 9ff3be5..8f49d73 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,3 +1,7 @@ +# This file is part of the pelican-precompress plugin. +# Copyright 2019-2021 Kurt McKee +# Released under the MIT license. +# # Setup instructions: # # $ python -m venv venv diff --git a/setup.py b/setup.py index 3b61a86..48ef347 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,5 @@ # This file is part of the pelican-precompress plugin. -# Copyright 2019-2020 Kurt McKee +# Copyright 2019-2021 Kurt McKee # Released under the MIT license. import os diff --git a/test_pelican_precompress.py b/test_pelican_precompress.py index 65b6b31..ad91866 100644 --- a/test_pelican_precompress.py +++ b/test_pelican_precompress.py @@ -1,5 +1,5 @@ # This file is part of the pelican-precompress plugin. -# Copyright 2019-2020 Kurt McKee +# Copyright 2019-2021 Kurt McKee # Released under the MIT license. import gzip @@ -7,11 +7,6 @@ import time from unittest.mock import patch, Mock -try: - import brotli -except ImportError: - pass - import pytest import pelican_precompress as pp @@ -145,11 +140,18 @@ def test_register(): pelican.signals.finalized.connect.assert_called_once_with(pp.compress_files) -def test_copyrights(): - for pattern in ('*.py', '*.rst', '*.ini'): - for path in pathlib.Path(__file__).parent.glob(pattern): - with path.open('r') as file: - assert f'2019-{time.gmtime().tm_year}' in file.read(100), f'{path.name} has an incorrect copyright date' +copyrighted_files = [ + *list(pathlib.Path(__file__).parent.glob('*.ini')), + *list(pathlib.Path(__file__).parent.glob('*.py')), + *list(pathlib.Path(__file__).parent.glob('*.rst')), + *list(pathlib.Path(__file__).parent.glob('*.txt')), +] + + +@pytest.mark.parametrize('path', copyrighted_files) +def test_copyrights(path): + with path.open('r') as file: + assert f'2019-{time.gmtime().tm_year}' in file.read(100), f'{path.name} has an incorrect copyright date' def apply_async_mock(fn, args, *extra_args, **kwargs): @@ -224,7 +226,7 @@ def test_compress_files_skip_existing_matching_files(fs): @patch('pelican_precompress.multiprocessing', multiprocessing_mock) def test_compress_files_overwrite_br(fs): - pytest.importorskip('brotli') + brotli = pytest.importorskip('brotli') with open('/test.txt', 'wb') as file: file.write(b'a' * 100) with open('/test.txt.br', 'wb') as file: diff --git a/tox.ini b/tox.ini index 95c0474..8fed9cc 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ # This file is part of the pelican-precompress plugin. -# Copyright 2019-2020 Kurt McKee +# Copyright 2019-2021 Kurt McKee # Released under the MIT license. From 8255f6619cc82721d3341641f7a33ea9ba7d3d56 Mon Sep 17 00:00:00 2001 From: Kurt McKee Date: Thu, 11 Feb 2021 18:53:54 -0600 Subject: [PATCH 2/7] Demonstrate that small files cause the compression loop to exit early --- test_pelican_precompress.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test_pelican_precompress.py b/test_pelican_precompress.py index ad91866..596ab85 100644 --- a/test_pelican_precompress.py +++ b/test_pelican_precompress.py @@ -285,6 +285,31 @@ def test_compress_files_file_size_increase(fs): assert not pathlib.Path('/test.txt.gz').exists() +@patch('pelican_precompress.multiprocessing', multiprocessing_mock) +def test_compress_files_continue_on_small_files(fs): + """Verify that small files do not cause an early exit. + + This was incorrect behavior was reported in issue #5. + """ + + with open('/000-too-small.txt', 'wb') as file: + file.write(b'a') + with open('/999-must-compress.txt', 'wb') as file: + file.write(b'a' * 100) + instance = Mock() + instance.settings = { + 'OUTPUT_PATH': '/', + 'PRECOMPRESS_BROTLI': False, + 'PRECOMPRESS_GZIP': True, + 'PRECOMPRESS_ZOPFLI': False, + 'PRECOMPRESS_MIN_SIZE': 100, + } + with patch('pelican_precompress.log', Mock()) as log: + pp.compress_files(instance) + log.info.assert_called_once() + assert pathlib.Path('/999-must-compress.txt.gz').exists() + + @patch('pelican_precompress.multiprocessing', multiprocessing_mock) def test_compress_files_overwrite_erase_existing_file(fs): """Ensure existing files are erased if the file size would increase.""" From 82d519f1261ada4971a72a8cde9d47009555da30 Mon Sep 17 00:00:00 2001 From: Kurt McKee Date: Thu, 11 Feb 2021 21:40:28 -0600 Subject: [PATCH 3/7] Prevent small files from terminating the file compression loop Fixes #5 --- CHANGES.rst | 2 ++ pelican_precompress.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 4692e41..9780900 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -8,6 +8,8 @@ Changelog Unreleased changes ================== +* Prevent small files from terminating the file compression loop. (#5) + 1.1.1 diff --git a/pelican_precompress.py b/pelican_precompress.py index 79fc7e8..2fc09ea 100644 --- a/pelican_precompress.py +++ b/pelican_precompress.py @@ -148,7 +148,7 @@ def compress_files(instance): # Ignore files smaller than the minimum size. if minimum_size and path.stat().st_size < minimum_size: log.info(f'{path} is less than {minimum_size} bytes. Skipping.') - return + continue data = path.read_bytes() From b894609ccc0abd2c7fc62f7d3dbd143078bebcfc Mon Sep 17 00:00:00 2001 From: Kurt McKee Date: Thu, 11 Feb 2021 21:53:12 -0600 Subject: [PATCH 4/7] Bump the version; use the Keep a Changelog format --- CHANGES.rst | 23 +++++++++++------------ pelican_precompress.py | 2 +- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 9780900..c1a9668 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -8,23 +8,24 @@ Changelog Unreleased changes ================== -* Prevent small files from terminating the file compression loop. (#5) +1.1.2 - 2021-02-11 +================== -1.1.1 -===== +* Prevent small files from terminating the file compression loop. (#5) -*Released 13 July 2020* -* Fix a bytes/str oversight in the release process. +1.1.1 - 2020-07-13 +================== + +* Fix a bytes/str oversight in the release process. -1.1.0 -===== -*Released 13 July 2020* +1.1.0 - 2020-07-13 +================== * Compress files in parallel on multi-core CPU's. * Add a ``PRECOMPRESS_MIN_SIZE`` option to skip files that are too small. @@ -37,10 +38,8 @@ Unreleased changes -1.0.0 -===== - -*Released 5 February 2020* +1.0.0 - 2020-02-05 +================== * Initial release * Support brotli, zopfli, and gzip static compression. diff --git a/pelican_precompress.py b/pelican_precompress.py index 2fc09ea..19b88c9 100644 --- a/pelican_precompress.py +++ b/pelican_precompress.py @@ -10,7 +10,7 @@ from typing import Dict, Iterable, Optional, Set, Union import zlib -__version__ = '1.1.1' +__version__ = '1.1.2' log = logging.getLogger(__name__) From 498df4b75c90b46937532803189135894de47aab Mon Sep 17 00:00:00 2001 From: Kurt McKee Date: Thu, 11 Feb 2021 22:04:32 -0600 Subject: [PATCH 5/7] Clean up some minor issues in dodo.py --- dodo.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/dodo.py b/dodo.py index 0d05951..e6f119f 100644 --- a/dodo.py +++ b/dodo.py @@ -8,8 +8,6 @@ import random import subprocess -import pelican_precompress - DOIT_CONFIG = {'default_tasks': ['build', 'test']} @@ -50,7 +48,7 @@ def task_test_release(): """Upload to test.pypi.org.""" name_suffix = ''.join(chr(i) for i in random.sample(range(0x61, 0x61+26), 10)) - version_suffix = str(random.choice(range(1,1000))) + version_suffix = str(random.choice(range(1, 1000))) return { 'actions': [ From a43799949dab1dcb538c3cf89f580f5ab4e3043a Mon Sep 17 00:00:00 2001 From: Kurt McKee Date: Thu, 11 Feb 2021 22:10:19 -0600 Subject: [PATCH 6/7] Add wheel as a dev requirement --- requirements-dev.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements-dev.txt b/requirements-dev.txt index 8f49d73..5879a26 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -13,3 +13,4 @@ docutils doit tox twine +wheel From c33ae8f8270f4f34f8b632c25a82d161c59532c2 Mon Sep 17 00:00:00 2001 From: Kurt McKee Date: Thu, 11 Feb 2021 22:13:11 -0600 Subject: [PATCH 7/7] Support (and test) Python 3.9 --- CHANGES.rst | 1 + setup.py | 1 + tox.ini | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index c1a9668..acc27cd 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -14,6 +14,7 @@ Unreleased changes ================== * Prevent small files from terminating the file compression loop. (#5) +* Officially support Python 3.9. diff --git a/setup.py b/setup.py index 48ef347..8c81edd 100644 --- a/setup.py +++ b/setup.py @@ -37,6 +37,7 @@ 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', 'Topic :: Internet :: WWW/HTTP :: Site Management', ], python_requires='~=3.6', diff --git a/tox.ini b/tox.ini index 8fed9cc..a9c1417 100644 --- a/tox.ini +++ b/tox.ini @@ -4,7 +4,7 @@ [tox] -envlist = py{36, 37, 38}-{brotli, }-{zopfli, }, coverage +envlist = py{36, 37, 38, 39}-{brotli, }-{zopfli, }, coverage skip_missing_interpreters = True skipsdist = True