Skip to content

Commit f9255f2

Browse files
authored
Update libbrotli to 1.0.9
1 parent 9876131 commit f9255f2

File tree

9 files changed

+90
-93
lines changed

9 files changed

+90
-93
lines changed

.github/workflows/ci.yml

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
with:
3333
submodules: recursive
3434
- uses: actions/setup-python@v1
35+
if: runner.os != 'Windows' # see issue #174
3536
with:
3637
python-version: 2.7
3738
- uses: actions/setup-python@v1
@@ -40,10 +41,16 @@ jobs:
4041
- uses: actions/setup-python@v1
4142
with:
4243
python-version: 3.9
43-
- name: Install Visual C++ for Python 2.7
44+
# - name: Install Visual C++ for Python 2.7
45+
# if: runner.os == 'Windows'
46+
# run: choco install vcpython27 -f -y
47+
- name: Run tests on Windows # see issue #174
4448
if: runner.os == 'Windows'
45-
run: choco install vcpython27 -f -y
46-
- name: Run tests
49+
run: |
50+
python -m pip install tox
51+
tox -e py35,py39
52+
- name: Run tests on Linux and macOS
53+
if: runner.os != 'Windows'
4754
run: |
4855
python -m pip install tox
4956
tox --skip-missing-interpreters
@@ -85,10 +92,16 @@ jobs:
8592

8693
- name: Install cibuildwheel
8794
run: python -m pip install cibuildwheel
88-
- name: Install Visual C++ for Python 2.7
95+
# - name: Install Visual C++ for Python 2.7
96+
# if: runner.os == 'Windows'
97+
# run: choco install vcpython27 -f -y
98+
- name: Build wheels for Windows # see issue #174
8999
if: runner.os == 'Windows'
90-
run: choco install vcpython27 -f -y
91-
- name: Build wheels
100+
run: python -m cibuildwheel --output-dir wheelhouse
101+
env:
102+
CIBW_BUILD: cp35-${{ matrix.name }}* pp*-${{ matrix.name }}*
103+
- name: Build wheels for Linux and macOS
104+
if: runner.os != 'Windows'
92105
run: python -m cibuildwheel --output-dir wheelhouse
93106
env:
94107
CIBW_BUILD: cp27-${{ matrix.name }}* cp35-${{ matrix.name }}* pp*-${{ matrix.name }}*
@@ -105,19 +118,19 @@ jobs:
105118
- uses: actions/download-artifact@v1
106119
with:
107120
name: sdist
108-
path: dists/
121+
path: dist/
109122
- uses: actions/download-artifact@v1
110123
with:
111124
name: wheels-win
112-
path: dists/
125+
path: dist/
113126
- uses: actions/download-artifact@v1
114127
with:
115128
name: wheels-macos
116-
path: dists/
129+
path: dist/
117130
- uses: actions/download-artifact@v1
118131
with:
119132
name: wheels-manylinux
120-
path: dists/
133+
path: dist/
121134
- name: Publish to PyPI
122135
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/')
123136
uses: pypa/gh-action-pypi-publish@master

MANIFEST.in

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ include LICENSE README.rst HISTORY.rst
55
include libbrotli/LICENSE
66

77
# Include the needed .c and .h files
8-
recursive-include libbrotli/enc *.c *.h *.cc
9-
recursive-include libbrotli/dec *.c *.h *.cc
10-
recursive-include libbrotli/common *.c *.h *.cc
11-
recursive-include libbrotli/include *.c *.h *.cc
8+
recursive-include libbrotli/c/enc *.c *.h *.cc
9+
recursive-include libbrotli/c/dec *.c *.h *.cc
10+
recursive-include libbrotli/c/common *.c *.h *.cc
11+
recursive-include libbrotli/c/include *.c *.h *.cc
1212

1313
# Include test files
1414
recursive-include test/ *.py

libbrotli

Submodule libbrotli updated 294 files

setup.py

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
#!/usr/bin/env python
22
import os
3+
import re
34
import platform
45
import sys
56
from setuptools import find_packages, setup
67
from setuptools.command.build_ext import build_ext
78

9+
base_dir = os.path.dirname(os.path.abspath(__file__))
810
long_description = (
911
open("README.rst").read() + '\n\n' + open("HISTORY.rst").read()
1012
)
1113

14+
with open(os.path.join(base_dir, "src", "brotlicffi", "__init__.py")) as f:
15+
__version__ = re.search(r"__version__ = \"([^\"]+)\"", f.read()).group(1)
16+
17+
1218
class BuildClibBeforeExt(build_ext):
1319
""" Setuptools `develop` command (used by `pip install -e .`) only calls
1420
`build_ext`, unlike `install` which calls `build` and all its related
@@ -21,44 +27,43 @@ class BuildClibBeforeExt(build_ext):
2127
https://github.com/pypa/pip/issues/4523
2228
"""
2329

30+
def get_source_files(self):
31+
filenames = build_ext.get_source_files(self)
32+
filenames.extend(depends)
33+
return filenames
34+
2435
def run(self):
2536
self.run_command("build_clib")
2637
build_ext.run(self)
2738

39+
40+
depends = []
2841
libraries = []
2942
USE_SHARED_BROTLI = os.environ.get("USE_SHARED_BROTLI")
3043
if USE_SHARED_BROTLI != "1":
44+
sources = []
45+
46+
for root, _, filenames in os.walk("libbrotli/c"):
47+
root_parts = os.path.split(root)
48+
if "fuzz" in root_parts or "tools" in root_parts:
49+
continue
50+
for filename in filenames:
51+
relpath = os.path.relpath(os.path.join(root, filename), base_dir)
52+
if filename.endswith(".h"):
53+
depends.append(relpath)
54+
elif filename.endswith(".c"):
55+
sources.append(relpath)
56+
3157
libraries = [
3258
("libbrotli", {
3359
"include_dirs": [
34-
"libbrotli/include",
35-
"libbrotli/",
60+
"libbrotli/c/include",
61+
"libbrotli/c/common",
62+
"libbrotli/c",
3663
"src/brotlicffi"
3764
],
38-
"sources": [
39-
'libbrotli/common/dictionary.c',
40-
'libbrotli/dec/huffman.c',
41-
'libbrotli/dec/bit_reader.c',
42-
'libbrotli/dec/decode.c',
43-
'libbrotli/dec/state.c',
44-
'libbrotli/enc/backward_references.c',
45-
'libbrotli/enc/backward_references_hq.c',
46-
'libbrotli/enc/bit_cost.c',
47-
'libbrotli/enc/block_splitter.c',
48-
'libbrotli/enc/histogram.c',
49-
'libbrotli/enc/memory.c',
50-
'libbrotli/enc/literal_cost.c',
51-
'libbrotli/enc/brotli_bit_stream.c',
52-
'libbrotli/enc/compress_fragment_two_pass.c',
53-
'libbrotli/enc/compress_fragment.c',
54-
'libbrotli/enc/cluster.c',
55-
'libbrotli/enc/utf8_util.c',
56-
'libbrotli/enc/encode.c',
57-
'libbrotli/enc/metablock.c',
58-
'libbrotli/enc/static_dict.c',
59-
'libbrotli/enc/dictionary_hash.c',
60-
'libbrotli/enc/entropy_encode.c'
61-
]
65+
"depends": depends,
66+
"sources": sources,
6267
}),
6368
]
6469

@@ -77,7 +82,7 @@ def finalize_options(self):
7782

7883
setup(
7984
name="brotlicffi",
80-
version="0.8.0",
85+
version=__version__,
8186

8287
description="Python CFFI bindings to the Brotli library",
8388
long_description=long_description,

src/brotlicffi/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
Compressor, MODE_GENERIC, MODE_TEXT, MODE_FONT, error, Error
66
)
77

8-
__version__ = "0.8.0"
8+
__version__ = "1.0.9.0"

src/brotlicffi/_api.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ def compress(data,
9595
mode=DEFAULT_MODE,
9696
quality=lib.BROTLI_DEFAULT_QUALITY,
9797
lgwin=lib.BROTLI_DEFAULT_WINDOW,
98-
lgblock=0,
99-
dictionary=b''):
98+
lgblock=0):
10099
"""
101100
Compress a string using Brotli.
102101
@@ -124,11 +123,6 @@ def compress(data,
124123
based on ``quality``.
125124
:type lgblock: ``int``
126125
127-
:param dictionary: A pre-set dictionary for LZ77. Please use this with
128-
caution: if a dictionary is used for compression, the same dictionary
129-
**must** be used for decompression!
130-
:type dictionary: ``bytes``
131-
132126
:returns: The compressed bytestring.
133127
:rtype: ``bytes``
134128
"""
@@ -141,8 +135,7 @@ def compress(data,
141135
mode=mode,
142136
quality=quality,
143137
lgwin=lgwin,
144-
lgblock=lgblock,
145-
dictionary=dictionary
138+
lgblock=lgblock
146139
)
147140
compressed_data = compressor._compress(data, lib.BROTLI_OPERATION_FINISH)
148141
assert lib.BrotliEncoderIsFinished(compressor._encoder) == lib.BROTLI_TRUE
@@ -255,8 +248,7 @@ def __init__(self,
255248
mode=DEFAULT_MODE,
256249
quality=lib.BROTLI_DEFAULT_QUALITY,
257250
lgwin=lib.BROTLI_DEFAULT_WINDOW,
258-
lgblock=0,
259-
dictionary=b''):
251+
lgblock=0):
260252
enc = lib.BrotliEncoderCreateInstance(
261253
ffi.NULL, ffi.NULL, ffi.NULL
262254
)
@@ -271,13 +263,6 @@ def __init__(self,
271263
_set_parameter(enc, lib.BROTLI_PARAM_LGWIN, "lgwin", lgwin)
272264
_set_parameter(enc, lib.BROTLI_PARAM_LGBLOCK, "lgblock", lgblock)
273265

274-
if dictionary:
275-
self._dictionary = ffi.new("uint8_t []", dictionary)
276-
self._dictionary_size = len(dictionary)
277-
lib.BrotliEncoderSetCustomDictionary(
278-
enc, self._dictionary_size, self._dictionary
279-
)
280-
281266
self._encoder = enc
282267

283268
def _compress(self, data, operation):

src/brotlicffi/_build.py

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <brotli/encode.h>
2222
""",
2323
libraries=libraries,
24-
include_dirs=["libbrotli", "libbrotli/include"]
24+
include_dirs=["libbrotli/c", "libbrotli/c/include", "libbrotli/c/common"]
2525
)
2626

2727
ffi.cdef("""
@@ -93,20 +93,6 @@
9393
uint8_t** next_out,
9494
size_t* total_out);
9595
96-
/* Fills the new state with a dictionary for LZ77, warming up the
97-
ringbuffer, e.g. for custom static dictionaries for data formats.
98-
Not to be confused with the built-in transformable dictionary of Brotli.
99-
|size| should be less or equal to 2^24 (16MiB), otherwise the dictionary
100-
will be ignored. The dictionary must exist in memory until decoding is
101-
done and is owned by the caller. To use:
102-
1) Allocate and initialize state with BrotliCreateInstance
103-
2) Use BrotliSetCustomDictionary
104-
3) Use BrotliDecompressStream
105-
4) Clean up and free state with BrotliDestroyState
106-
*/
107-
void BrotliDecoderSetCustomDictionary(
108-
BrotliDecoderState* s, size_t size, const uint8_t* dict);
109-
11096
/* Returns true, if decoder has some unconsumed output.
11197
Otherwise returns false. */
11298
BROTLI_BOOL BrotliDecoderHasMoreOutput(const BrotliDecoderState* s);
@@ -205,15 +191,6 @@
205191
BrotliEncoderParameter p,
206192
uint32_t value);
207193
208-
/* Fills the new state with a dictionary for LZ77, warming up the
209-
ringbuffer, e.g. for custom static dictionaries for data formats.
210-
Not to be confused with the built-in transformable dictionary of Brotli.
211-
To decode, use BrotliSetCustomDictionary() of the decoder with the same
212-
dictionary. */
213-
void BrotliEncoderSetCustomDictionary(BrotliEncoderState* state,
214-
size_t size,
215-
const uint8_t* dict);
216-
217194
/* Check if encoder is in "finished" state, i.e. no more input is
218195
acceptable and no more output will be produced.
219196
Works only with BrotliEncoderCompressStream workflow.

test/test_compatibility.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
66
Tests for names that exist purely for compatibility purposes.
77
"""
8+
import re
9+
from os.path import abspath, join, dirname
810
import brotlicffi
911

1012

@@ -16,3 +18,26 @@ def test_compatible_names():
1618
assert brotlicffi.MODE_GENERIC is brotlicffi.BrotliEncoderMode.GENERIC
1719
assert brotlicffi.MODE_TEXT is brotlicffi.BrotliEncoderMode.TEXT
1820
assert brotlicffi.MODE_FONT is brotlicffi.BrotliEncoderMode.FONT
21+
22+
23+
def test_brotli_version():
24+
"""
25+
Test that the __version__ starts with the
26+
Brotli version that's compiled with.
27+
"""
28+
version_h = join(
29+
dirname(dirname(abspath(__file__))), "libbrotli/c/common/version.h"
30+
)
31+
with open(version_h) as f:
32+
brotli_version = int(
33+
re.search(
34+
r"#define BROTLI_VERSION 0x([A-Fa-f0-9]+)", f.read()
35+
).group(1),
36+
16,
37+
)
38+
major = brotli_version >> 24
39+
minor = (brotli_version >> 12) & 0xFFF
40+
patch = brotli_version & 0xFFF
41+
assert brotlicffi.__version__.startswith(
42+
"%d.%d.%d." % (major, minor, patch)
43+
)

test/test_simple_compression.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,6 @@ def test_compressed_data_roundtrips(s):
110110
assert brotlicffi.decompress(brotlicffi.compress(s)) == s
111111

112112

113-
@given(binary(), binary())
114-
def test_compressed_data_with_dictionaries(s, dictionary):
115-
d = brotlicffi.Decompressor(dictionary)
116-
compressed = brotlicffi.compress(s, dictionary=dictionary)
117-
uncompressed = d.decompress(compressed)
118-
assert uncompressed == s
119-
120-
121113
@given(binary())
122114
def test_process_alias(s):
123115
c1 = brotlicffi.Compressor()

0 commit comments

Comments
 (0)