Skip to content

Commit 0dda934

Browse files
authored
Merge pull request #73 from pycompression/igzip_lib2
Add an igzip_lib module.
2 parents 7e0577f + 2029f2c commit 0dda934

19 files changed

+836
-408
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ jobs:
197197
CIBW_TEST_REQUIRES: "pytest"
198198
# Simple test that requires the project to be build correctly
199199
CIBW_TEST_COMMAND: >-
200-
pytest {project}/tests/test_igzip.py {project}/tests/test_isal.py
200+
pytest {project}/tests/test_igzip.py
201+
{project}/tests/test_compat.py
202+
{project}/tests/test_igzip_lib.py
201203
- name: Build sdist
202204
if: "runner.os == 'Linux'"
203205
run: python setup.py sdist

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ Changelog
99
1010
version 0.10.0-dev
1111
------------------
12+
+ Added an ``igzip_lib`` module which allows more direct access to ISA-L's
13+
igzip_lib API. This allows features such as headerless compression and
14+
decompression, as well as setting the memory levels manually.
1215
+ Added more extensive documentation.
1316

1417
version 0.9.0

README.rst

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,34 @@ Acceleration Library (ISA-L) implements several key algorithms in `assembly
4545
language <https://en.wikipedia.org/wiki/Assembly_language>`_. This includes
4646
a variety of functions to provide zlib/gzip-compatible compression.
4747

48-
``python-isal`` provides the bindings by offering an ``isal_zlib`` and
49-
``igzip`` module which are usable as drop-in replacements for the ``zlib``
50-
and ``gzip`` modules from the stdlib (with some minor exceptions, see below).
48+
``python-isal`` provides the bindings by offering three modules:
49+
50+
+ ``isal_zlib``: A drop-in replacement for the zlib module that uses ISA-L to
51+
accelerate its performance.
52+
+ ``igzip``: A drop-in replacement for the gzip module that uses ``isal_zlib``
53+
instead of ``zlib`` to perform its compression and checksum tasks, which
54+
improves performance.
55+
+ ``igzip_lib``: Provides compression functions which have full access to the
56+
API of ISA-L's compression functions.
57+
58+
``isal_zlib`` and ``igzip`` are almost fully compatible with ``zlib`` and
59+
``gzip`` from the Python standard library. There are some minor differences
60+
see: differences-with-zlib-and-gzip-modules_.
5161

5262
.. introduction end
5363
5464
Quickstart
5565
----------
5666

57-
.. usage start
67+
.. quickstart start
5868
59-
Python-isal has faster versions of the stdlib's ``zlib`` and ``gzip`` module
60-
these are called ``isal_zlib`` and ``igzip`` respectively.
61-
62-
They can be imported as follows
69+
The python-isal modules can be imported as follows
6370

6471
.. code-block:: python
6572
6673
from isal import isal_zlib
6774
from isal import igzip
75+
from isal import igzip_lib
6876
6977
``isal_zlib`` and ``igzip`` are meant to be used as drop in replacements so
7078
their api and functions are the same as the stdlib's modules. Except where
@@ -78,7 +86,7 @@ application (just like ``python -m gzip``). Full usage documentation can be
7886
found on `our readthedocs page <https://python-isal.readthedocs.io>`_.
7987

8088

81-
.. usage end
89+
.. quickstart end
8290
8391
Installation
8492
------------
@@ -89,6 +97,8 @@ Installation is supported on Linux, Windows and MacOS. For more advanced
8997
installation options check the `documentation
9098
<https://python-isal.readthedocs.io/en/stable/index.html#installation>`_.
9199

100+
.. _differences-with-zlib-and-gzip-modules:
101+
92102
Differences with zlib and gzip modules
93103
--------------------------------------
94104

@@ -144,8 +154,8 @@ This project builds upon the software and experience of many. Many thanks to:
144154
to create an extension and helping a novice get start with pointer addresses.
145155
+ The `CPython contributors
146156
<https://github.com/python/cpython/graphs/contributors>`_.
147-
Python-isal mimicks ``zlibmodule.c`` and ``igzip.py`` to make it easier for
148-
python users to adopt it.
157+
Python-isal mimicks ``zlibmodule.c`` and ``gzip.py`` from the standard
158+
library to make it easier for python users to adopt it.
149159
+ `@marcelm <https://github.com/marcelm>`_ for taking a chance on this project
150160
and make it a dependency for his `xopen
151161
<https://github.com/pycompression/xopen>`_ and by extension `cutadapt

docs/includes/Installation.rst

Lines changed: 0 additions & 54 deletions
This file was deleted.

docs/includes/igzip.rst

Lines changed: 0 additions & 10 deletions
This file was deleted.

docs/includes/isal.igzip_usage.rst

Lines changed: 0 additions & 8 deletions
This file was deleted.

docs/includes/isal_zlib.rst

Lines changed: 0 additions & 6 deletions
This file was deleted.

docs/index.rst

Lines changed: 84 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,66 @@ Introduction
2323
Quickstart
2424
==========
2525

26-
Python-isal has faster versions of the stdlib's ``zlib`` and ``gzip`` module
27-
these are called ``isal_zlib`` and ``igzip`` respectively.
26+
.. include:: includes/README.rst
27+
:start-after: .. quickstart start
28+
:end-before: .. quickstart end
29+
30+
============
31+
Installation
32+
============
33+
Installation with pip
34+
---------------------
35+
36+
::
37+
38+
pip install isal
39+
40+
Installation is supported on Linux, MacOS and Windows. On most platforms
41+
wheels are provided.
42+
The installation will include a staticallly linked version of ISA-L.
43+
If a wheel is not provided for your system the
44+
installation will build ISA-L first in a temporary directory. Please check the
45+
`ISA-L homepage <https://github.com/intel/isa-l>`_ for the build requirements.
46+
47+
The latest development version of python-isal can be installed with::
48+
49+
pip install git+https://github.com/rhpvorderman/python-isal.git
2850

29-
They can be imported as follows
51+
This requires having the build requirements installed.
52+
If you wish to link
53+
dynamically against a version of libisal installed on your system use::
3054

31-
.. code-block:: python
55+
PYTHON_ISAL_LINK_DYNAMIC=true pip install isal --no-binary isal
3256

33-
from isal import isal_zlib
34-
from isal import igzip
57+
ISA-L is available in numerous Linux distro's as well as on conda via the
58+
conda-forge channel. Checkout the `ports documentation
59+
<https://github.com/intel/isa-l/wiki/Ports--Repos>`_ on the ISA-L project wiki
60+
to find out how to install it. It is important that the development headers
61+
are also installed.
3562

36-
``isal_zlib`` and ``igzip`` are meant to be used as drop in replacements so
37-
their api and functions are the same as the stdlib's modules. Except where
38-
ISA-L does not support the same calls as zlib (See differences below).
63+
On Debian and Ubuntu the ISA-L libraries (including the development headers)
64+
can be installed with::
3965

40-
A full API documentation can be found below.
66+
sudo apt install libisal-dev
4167

42-
``python -m isal.igzip`` implements a simple gzip-like command line
43-
application (just like ``python -m gzip``). Full usage documentation can be
44-
found below.
68+
Installation via conda
69+
----------------------
70+
Python-isal can be installed via conda, for example using
71+
the `miniconda <https://docs.conda.io/en/latest/miniconda.html>`_ installer
72+
with a properly setup `conda-forge
73+
<https://conda-forge.org/docs/user/introduction.html#how-can-i-install-packages-from-conda-forge>`_
74+
channel. When used with bioinformatics tools setting up `bioconda
75+
<http://bioconda.github.io/user/install.html#install-conda>`_
76+
provides a clear set of installation instructions for conda.
4577

78+
python-isal is available on conda-forge and can be installed with::
4679

47-
.. include:: includes/Installation.rst
80+
conda install python-isal
81+
82+
This will automatically install the ISA-L library dependency as well, since
83+
it is available on conda-forge.
84+
85+
.. _differences-with-zlib-and-gzip-modules:
4886

4987
======================================
5088
Differences with zlib and gzip modules
@@ -54,11 +92,40 @@ Differences with zlib and gzip modules
5492
:start-after: .. differences start
5593
:end-before: .. differences end
5694

57-
.. include:: includes/isal_zlib.rst
95+
============================
96+
API Documentation: isal_zlib
97+
============================
98+
99+
.. automodule:: isal.isal_zlib
100+
:members:
101+
102+
========================
103+
API-documentation: igzip
104+
========================
105+
106+
.. automodule:: isal.igzip
107+
:members: compress, decompress, open
108+
109+
.. autoclass:: IGzipFile
110+
:members:
111+
:special-members: __init__
112+
113+
============================
114+
API Documentation: igzip_lib
115+
============================
116+
117+
.. automodule:: isal.igzip_lib
118+
:members:
119+
120+
==========================
121+
python -m isal.igzip usage
122+
==========================
58123

59-
.. include:: includes/igzip.rst
124+
.. argparse::
125+
:module: isal.igzip
126+
:func: _argument_parser
127+
:prog: python -m isal.igzip
60128

61-
.. include:: includes/isal.igzip_usage.rst
62129

63130
============
64131
Contributing

setup.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ class IsalExtension(Extension):
4141
pass
4242

4343

44-
MODULES = [IsalExtension("isal.isal_zlib", ["src/isal/isal_zlib.pyx"])]
44+
MODULES = [IsalExtension("isal.isal_zlib", ["src/isal/isal_zlib.pyx"]),
45+
IsalExtension("isal.igzip_lib", ["src/isal/igzip_lib.pyx"])]
4546
if SYSTEM_IS_UNIX:
4647
MODULES.append(IsalExtension("isal._isal", ["src/isal/_isal.pyx"]))
4748

@@ -80,7 +81,8 @@ def build_extension(self, ext):
8081
else:
8182
if self.compiler.compiler_type == "msvc":
8283
compiler = copy.deepcopy(self.compiler)
83-
compiler.initialize()
84+
if not compiler.initialized:
85+
compiler.initialize()
8486
compiler_command = f'"{compiler.cc}"'
8587
compiler_args = compiler.compile_options
8688
elif self.compiler.compiler_type == "unix":

src/isal/igzip.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from typing import List, Optional, SupportsInt
3232
import _compression # noqa: I201 # Not third-party
3333

34-
from . import isal_zlib
34+
from . import igzip_lib, isal_zlib
3535

3636
__all__ = ["IGzipFile", "open", "compress", "decompress", "BadGzipFile"]
3737

@@ -270,12 +270,11 @@ def compress(data, compresslevel=_COMPRESS_LEVEL_BEST, *, mtime=None):
270270
Optional argument is the compression level, in range of 0-3.
271271
"""
272272
header = _create_simple_gzip_header(compresslevel, mtime)
273-
# Compress the data without header or trailer in a raw deflate block.
274-
compressed = isal_zlib.compress(data, compresslevel, wbits=-15)
275-
length = len(data) & 0xFFFFFFFF
276-
crc = isal_zlib.crc32(data)
277-
trailer = struct.pack("<LL", crc, length)
278-
return header + compressed + trailer
273+
# use igzip_lib to compress the data without a gzip header but with a
274+
# gzip trailer.
275+
compressed = igzip_lib.compress(data, compresslevel,
276+
flag=igzip_lib.COMP_GZIP_NO_HDR)
277+
return header + compressed
279278

280279

281280
def _gzip_header_end(data: bytes) -> int:

0 commit comments

Comments
 (0)