-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
69 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
.. This file is part of the pelican_precompress plugin. | ||
.. Copyright 2019-2020 Kurt McKee <[email protected]> | ||
.. Copyright 2019-2021 Kurt McKee <[email protected]> | ||
.. Released under the MIT license. | ||
Changelog | ||
|
@@ -10,19 +10,23 @@ Unreleased changes | |
|
||
|
||
|
||
1.1.1 | ||
===== | ||
1.1.2 - 2021-02-11 | ||
================== | ||
|
||
*Released 13 July 2020* | ||
* Prevent small files from terminating the file compression loop. (#5) | ||
* Officially support Python 3.9. | ||
|
||
* 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. | ||
|
@@ -35,10 +39,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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019-2020 Kurt McKee <[email protected]> | ||
Copyright (c) 2019-2021 Kurt McKee <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
.. This file is part of the pelican_precompress plugin. | ||
.. Copyright 2019-2020 Kurt McKee <[email protected]> | ||
.. Copyright 2019-2021 Kurt McKee <[email protected]> | ||
.. Released under the MIT license. | ||
pelican_precompress | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# This file is part of the pelican-precompress plugin. | ||
# Copyright 2019-2020 Kurt McKee <[email protected]> | ||
# Copyright 2019-2021 Kurt McKee <[email protected]> | ||
# Released under the MIT license. | ||
|
||
# The tasks defined in this file automates the entire | ||
|
@@ -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': [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# This file is part of the pelican-precompress plugin. | ||
# Copyright 2019-2020 Kurt McKee <[email protected]> | ||
# Copyright 2019-2021 Kurt McKee <[email protected]> | ||
# Released under the MIT license. | ||
|
||
import functools | ||
|
@@ -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__) | ||
|
||
|
@@ -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() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# This file is part of the pelican-precompress plugin. | ||
# Copyright 2019-2021 Kurt McKee <[email protected]> | ||
# Released under the MIT license. | ||
# | ||
# Setup instructions: | ||
# | ||
# $ python -m venv venv | ||
|
@@ -9,3 +13,4 @@ docutils | |
doit | ||
tox | ||
twine | ||
wheel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# This file is part of the pelican-precompress plugin. | ||
# Copyright 2019-2020 Kurt McKee <[email protected]> | ||
# Copyright 2019-2021 Kurt McKee <[email protected]> | ||
# Released under the MIT license. | ||
|
||
import os | ||
|
@@ -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', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,12 @@ | ||
# This file is part of the pelican-precompress plugin. | ||
# Copyright 2019-2020 Kurt McKee <[email protected]> | ||
# Copyright 2019-2021 Kurt McKee <[email protected]> | ||
# Released under the MIT license. | ||
|
||
import gzip | ||
import pathlib | ||
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: | ||
|
@@ -283,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.""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
# This file is part of the pelican-precompress plugin. | ||
# Copyright 2019-2020 Kurt McKee <[email protected]> | ||
# Copyright 2019-2021 Kurt McKee <[email protected]> | ||
# Released under the MIT license. | ||
|
||
|
||
[tox] | ||
envlist = py{36, 37, 38}-{brotli, }-{zopfli, }, coverage | ||
envlist = py{36, 37, 38, 39}-{brotli, }-{zopfli, }, coverage | ||
skip_missing_interpreters = True | ||
skipsdist = True | ||
|
||
|