Skip to content

Commit d159e2c

Browse files
committed
Merge remote-tracking branch 'origin/develop' into fixints
2 parents 7db9508 + 73f73a2 commit d159e2c

File tree

10 files changed

+157
-10
lines changed

10 files changed

+157
-10
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,25 @@ jobs:
4444
run: tox -e docs
4545
env:
4646
PYTHON_ISAL_LINK_DYNAMIC: True
47+
mypy:
48+
needs: lint
49+
runs-on: ubuntu-20.04
50+
steps:
51+
- uses: actions/[email protected]
52+
with:
53+
submodules: recursive
54+
- name: Set up Python 3.6
55+
uses: actions/[email protected]
56+
with:
57+
python-version: 3.6
58+
- name: Install isal
59+
run: sudo apt-get install libisal-dev
60+
- name: Install tox and upgrade setuptools and pip
61+
run: pip install --upgrade tox setuptools pip
62+
- name: Mypy checks
63+
run: tox -e mypy
64+
env:
65+
PYTHON_ISAL_LINK_DYNAMIC: True
4766
twine_check:
4867
needs: lint
4968
runs-on: ${{ matrix.os }}

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Changelog
99
1010
version 0.5.0-dev
1111
-----------------
12+
+ Provided stubs (type-hint files) for ``isal_zlib`` and ``_isal`` modules.
13+
Package is now tested with mypy to ensure correct type information.
1214
+ The command-line interface now reads in blocks of 32K instead of 8K. This
1315
improves performance by about 6% when compressing and 11% when decompressing.
1416
A hidden ``-b`` flag was added to adjust the buffer size for benchmarks.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def build_isa_l():
128128
zip_safe=False,
129129
packages=find_packages('src'),
130130
package_dir={'': 'src'},
131-
package_data={'isal': ['*.pxd', '*.pyx',
131+
package_data={'isal': ['*.pxd', '*.pyx', '*.pyi', 'py.typed',
132132
# Include isa-l LICENSE and other relevant files
133133
# with the binary distribution.
134134
'isa-l/LICENSE', 'isa-l/README.md',

src/isal/_isal.pyi

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright (c) 2020 Leiden University Medical Center
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy
4+
# of this software and associated documentation files (the "Software"), to deal
5+
# in the Software without restriction, including without limitation the rights
6+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
# copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
#
10+
# The above copyright notice and this permission notice shall be included in
11+
# all copies or substantial portions of the Software.
12+
#
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
# SOFTWARE.
20+
21+
ISAL_MAJOR_VERSION: int
22+
ISAL_MINOR_VERSION: int
23+
ISAL_PATCH_VERSION: int
24+
ISAL_VERSION: str

src/isal/igzip.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
_COMPRESS_LEVEL_BEST = isal_zlib.ISAL_BEST_COMPRESSION
3737

3838
try:
39-
BadGzipFile = gzip.BadGzipFile
39+
BadGzipFile = gzip.BadGzipFile # type: ignore
4040
except AttributeError: # Versions lower than 3.8 do not have BadGzipFile
4141
BadGzipFile = OSError
4242

@@ -76,7 +76,8 @@ def open(filename, mode="rb", compresslevel=_COMPRESS_LEVEL_TRADEOFF,
7676
raise ValueError("Argument 'newline' not supported in binary mode")
7777

7878
gz_mode = mode.replace("t", "")
79-
if isinstance(filename, (str, bytes, os.PathLike)):
79+
# __fspath__ method is os.PathLike
80+
if isinstance(filename, (str, bytes)) or hasattr(filename, "__fspath__"):
8081
binary_file = IGzipFile(filename, gz_mode, compresslevel)
8182
elif hasattr(filename, "read") or hasattr(filename, "write"):
8283
binary_file = IGzipFile(None, gz_mode, compresslevel, filename)

src/isal/isal_zlib.pyi

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Copyright (c) 2020 Leiden University Medical Center
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy
4+
# of this software and associated documentation files (the "Software"), to deal
5+
# in the Software without restriction, including without limitation the rights
6+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
# copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
#
10+
# The above copyright notice and this permission notice shall be included in
11+
# all copies or substantial portions of the Software.
12+
#
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
# SOFTWARE.
20+
21+
ISAL_BEST_SPEED: int
22+
ISAL_BEST_COMPRESSION: int
23+
ISAL_DEFAULT_COMPRESSION: int
24+
Z_BEST_SPEED: int
25+
Z_BEST_COMPRESSION: int
26+
Z_DEFAULT_COMPRESSION: int
27+
28+
DEF_BUF_SIZE: int
29+
DEF_MEM_LEVEL: int
30+
MAX_WBITS: int
31+
ISAL_DEFAULT_HIST_BITS: int
32+
33+
DEFLATED: int
34+
35+
Z_DEFAULT_STRATEGY: int
36+
Z_RLE: int
37+
Z_HUFFMAN_ONLY: int
38+
Z_FILTERED: int
39+
Z_FIXED: int
40+
41+
ISAL_NO_FLUSH: int
42+
ISAL_SYNC_FLUSH: int
43+
ISAL_FULL_FLUSH: int
44+
45+
Z_NO_FLUSH: int
46+
Z_SYNC_FLUSH: int
47+
Z_FINISH: int
48+
49+
class IsalError(OSError): ...
50+
51+
error: IsalError
52+
53+
def adler32(data, value: int = ...) -> int: ...
54+
def crc32(data, value: int = ...) -> int: ...
55+
56+
def compress(data, level: int = ..., wbits: int = ...) -> bytes: ...
57+
def decompress(data, wbits: int = ..., bufsize: int = ...) -> bytes: ...
58+
59+
class Compress:
60+
def compress(self, data) -> bytes: ...
61+
def flush(self, mode: int = ...) -> bytes: ...
62+
63+
class Decompress:
64+
unused_data: bytes
65+
unconsumed_tail: bytes
66+
eof: bool
67+
crc: int
68+
69+
def decompress(self, data, max_length: int = ...) -> bytes: ...
70+
def flush(self, length: int = ...) -> bytes: ...
71+
72+
def compressobj(level: int = ..., method: int = ..., wbits: int = ...,
73+
memLevel: int = ..., strategy: int = ..., zdict = ...
74+
) -> Compress: ...
75+
def decompressobj(wbits: int = ..., zdict = ...) -> Decompress: ...

src/isal/py.typed

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright (c) 2020 Leiden University Medical Center
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy
4+
# of this software and associated documentation files (the "Software"), to deal
5+
# in the Software without restriction, including without limitation the rights
6+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
# copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
#
10+
# The above copyright notice and this permission notice shall be included in
11+
# all copies or substantial portions of the Software.
12+
#
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
# SOFTWARE.
20+
#
21+
# Marker file for PEP 561.

tests/test_gzip_compliance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
import tempfile
2727
import unittest
2828
from subprocess import PIPE, Popen
29-
from test.support import _4G, bigmemtest
30-
from test.support.script_helper import assert_python_failure, assert_python_ok
29+
from test.support import _4G, bigmemtest # type: ignore
30+
from test.support.script_helper import assert_python_failure, assert_python_ok # type: ignore # noqa: E501
3131

3232
from isal import igzip
3333

tests/test_zlib_compliance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import random
2020
import sys
2121
import unittest
22-
from test import support
23-
from test.support import _1G, _4G, bigmemtest
22+
from test import support # type: ignore
23+
from test.support import _1G, _4G, bigmemtest # type: ignore
2424

2525
import isal
2626
from isal import isal_zlib

tox.ini

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,17 @@ commands=
4141
[testenv:lint]
4242
deps=flake8
4343
flake8-import-order
44-
mypy
45-
# Linting does not need the installed package.
46-
skip_install=true
44+
skip_install=True
4745
commands =
4846
flake8 src tests setup.py benchmark.py
4947

48+
[testenv:mypy]
49+
# pytest dep needed for mypy check
50+
deps=mypy
51+
pytest
52+
commands =
53+
mypy src/ tests/
54+
5055
# Documentation should build on python version 3
5156
[testenv:docs]
5257
deps=-r requirements-docs.txt

0 commit comments

Comments
 (0)