Skip to content

Commit

Permalink
Merge branch 'release' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtmckee committed Feb 12, 2021
2 parents f8018c9 + c33ae8f commit 88618a9
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 36 deletions.
26 changes: 14 additions & 12 deletions CHANGES.rst
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
Expand All @@ -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.
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
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
Expand Down
2 changes: 1 addition & 1 deletion README.rst
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
Expand Down
6 changes: 2 additions & 4 deletions dodo.py
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
Expand All @@ -8,8 +8,6 @@
import random
import subprocess

import pelican_precompress

DOIT_CONFIG = {'default_tasks': ['build', 'test']}


Expand Down Expand Up @@ -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': [
Expand Down
6 changes: 3 additions & 3 deletions pelican_precompress.py
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
Expand All @@ -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__)

Expand Down Expand Up @@ -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()

Expand Down
5 changes: 5 additions & 0 deletions requirements-dev.txt
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
Expand All @@ -9,3 +13,4 @@ docutils
doit
tox
twine
wheel
3 changes: 2 additions & 1 deletion setup.py
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
Expand Down Expand Up @@ -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',
Expand Down
51 changes: 39 additions & 12 deletions test_pelican_precompress.py
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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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."""
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
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

Expand Down

0 comments on commit 88618a9

Please sign in to comment.