Skip to content

Commit bc592b8

Browse files
authored
Merge pull request #123 from pycompression/PYPY
Re-enable pypy support
2 parents 6841a7f + 0f8e499 commit bc592b8

File tree

7 files changed

+79
-29
lines changed

7 files changed

+79
-29
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ jobs:
6161
- "3.8"
6262
- "3.9"
6363
- "3.10"
64+
- "pypy-3.7"
65+
- "pypy-3.8"
66+
- "pypy-3.9"
6467
os: ["ubuntu-latest"]
6568
include:
6669
- os: "macos-latest"
@@ -130,6 +133,10 @@ jobs:
130133
strategy:
131134
matrix:
132135
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
136+
python_version: [ "python" ]
137+
include:
138+
- os: "ubuntu-latest"
139+
python_version: "pypy"
133140
steps:
134141
- uses: actions/[email protected]
135142
with:
@@ -139,7 +146,7 @@ jobs:
139146
with:
140147
channels: conda-forge,defaults
141148
- name: Install requirements (universal)
142-
run: conda install isa-l python tox
149+
run: conda install isa-l ${{ matrix.python_version}} tox
143150
- name: Set MSVC developer prompt
144151
uses: ilammy/[email protected]
145152
if: runner.os == 'Windows'
@@ -203,7 +210,7 @@ jobs:
203210
- name: Build wheels
204211
run: cibuildwheel --output-dir dist
205212
env:
206-
CIBW_SKIP: "*-win32 *-manylinux_i686 *pp3*" # Skip 32 bit and pypy
213+
CIBW_SKIP: "*-win32 *-manylinux_i686" # Skip 32 bit
207214
CIBW_ARCHS_LINUX: ${{ matrix.cibw_archs_linux }}
208215
CIBW_BEFORE_ALL_LINUX: ${{ matrix.cibw_before_all_linux }}
209216
# Fully test the build wheels again.

CHANGELOG.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,20 @@ Changelog
77
.. This document is user facing. Please word the changes in such a way
88
.. that users understand how the changes affect the new version.
99
10+
version 1.0.1
11+
------------------
12+
+ Fixed failing tests and wheel builds for PyPy.
13+
1014
version 1.0.0
1115
------------------
1216
Python-isal has been rewritten as a C-extension (first implementation was in
13-
Cython). This has made the library faster in many key areas. It does mean
14-
that PyPy is no longer supported.
17+
Cython). This has made the library faster in many key areas.
1518

1619
+ Since the module now mostly contains code copied from CPython and then
1720
modified to work with ISA-L the license has been changed to the
1821
Python Software Foundation License version 2.
1922
+ Python versions lower than 3.7 are no longer supported. Python 3.6 is out
2023
of support since December 2021.
21-
+ PyPy is no longer supported. PyPy+python-isal was slower than CPython + zlib
22-
for decompressing gzip files. PyPy should not be used for workloads that
23-
require heavy zlib-compatible compression/decompression. As such it was
24-
deemed unnecessary to continue supporting PyPy.
2524
+ Stub files with type information have now been updated to correctly display
2625
positional-only arguments.
2726
+ Expose ``READ`` and ``WRITE`` constants on the ``igzip`` module. These are

README.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,12 @@ your project please list a python-isal dependency as follows.
111111
``setup.cfg``::
112112

113113
install_requires =
114-
isal; platform.python_implementation == 'CPython' and (platform.machine == "x86_64" or platform.machine == "AMD64")
114+
isal; platform.machine == "x86_64" or platform.machine == "AMD64"
115115

116116
``setup.py``::
117117

118118
extras_require={
119-
":platform.python_implementation == 'CPython' and "
120-
"(platform.machine == 'x86_64' or platform.machine == 'AMD64')": ['isal']
119+
":platform.machine == 'x86_64' or platform.machine == 'AMD64'": ['isal']
121120
},
122121

123122
.. dependency end

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ def build_isa_l(compiler_command: str, compiler_options: str):
188188
"Programming Language :: Python :: 3.8",
189189
"Programming Language :: Python :: 3.9",
190190
"Programming Language :: Python :: 3.10",
191+
"Programming Language :: Python :: Implementation :: CPython",
192+
"Programming Language :: Python :: Implementation :: PyPy",
191193
"Programming Language :: C",
192194
"Development Status :: 5 - Production/Stable",
193195
"Topic :: System :: Archiving :: Compression",

tests/test_igzip.py

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import re
1616
import shutil
1717
import struct
18+
import subprocess
1819
import sys
1920
import tempfile
2021
import zlib
@@ -28,6 +29,21 @@
2829
DATA = b'This is a simple test with igzip'
2930
COMPRESSED_DATA = gzip.compress(DATA)
3031
TEST_FILE = str((Path(__file__).parent / "data" / "test.fastq.gz"))
32+
PYPY = sys.implementation.name == "pypy"
33+
34+
35+
def run_isal_igzip(*args, stdin=None):
36+
"""Calling isal.igzip externally seems to solve some issues on PyPy where
37+
files would not be written properly when igzip.main() was called. This is
38+
probably due to some out of order execution that PyPy tries to pull.
39+
Running the process externally is detrimental to the coverage report,
40+
so this is only done for PyPy."""
41+
process = subprocess.Popen(["python", "-m", "isal.igzip", *args],
42+
stdout=subprocess.PIPE,
43+
stderr=subprocess.PIPE,
44+
stdin=subprocess.PIPE)
45+
46+
return process.communicate(stdin)
3147

3248

3349
def test_wrong_compresslevel_igzipfile():
@@ -112,10 +128,13 @@ def test_decompress_infile_outfile(tmp_path, capsysbinary):
112128
def test_compress_infile_outfile(tmp_path, capsysbinary):
113129
test_file = tmp_path / "test"
114130
test_file.write_bytes(DATA)
115-
sys.argv = ['', str(test_file)]
116-
igzip.main()
131+
if PYPY:
132+
out, err = run_isal_igzip(str(test_file))
133+
else:
134+
sys.argv = ['', str(test_file)]
135+
igzip.main()
136+
out, err = capsysbinary.readouterr()
117137
out_file = test_file.with_suffix(".gz")
118-
out, err = capsysbinary.readouterr()
119138
assert err == b''
120139
assert out == b''
121140
assert out_file.exists()
@@ -176,9 +195,13 @@ def test_compress_infile_out_file(tmp_path, capsysbinary):
176195
test = tmp_path / "test"
177196
test.write_bytes(DATA)
178197
out_file = tmp_path / "compressed.gz"
179-
sys.argv = ['', '-o', str(out_file), str(test)]
180-
igzip.main()
181-
out, err = capsysbinary.readouterr()
198+
args = ['-o', str(out_file), str(test)]
199+
if PYPY:
200+
out, err = run_isal_igzip(*args)
201+
else:
202+
sys.argv = ['', *args]
203+
igzip.main()
204+
out, err = capsysbinary.readouterr()
182205
assert gzip.decompress(out_file.read_bytes()) == DATA
183206
assert err == b''
184207
assert out == b''
@@ -189,9 +212,13 @@ def test_compress_infile_out_file_force(tmp_path, capsysbinary):
189212
test.write_bytes(DATA)
190213
out_file = tmp_path / "compressed.gz"
191214
out_file.touch()
192-
sys.argv = ['', '-f', '-o', str(out_file), str(test)]
193-
igzip.main()
194-
out, err = capsysbinary.readouterr()
215+
args = ['-f', '-o', str(out_file), str(test)]
216+
if PYPY:
217+
out, err = run_isal_igzip(*args)
218+
else:
219+
sys.argv = ['', *args]
220+
igzip.main()
221+
out, err = capsysbinary.readouterr()
195222
assert gzip.decompress(out_file.read_bytes()) == DATA
196223
assert err == b''
197224
assert out == b''
@@ -234,23 +261,30 @@ def test_compress_infile_out_file_inmplicit_name_prompt_accept(
234261
test.write_bytes(DATA)
235262
out_file = tmp_path / "test.gz"
236263
out_file.touch()
237-
sys.argv = ['', str(test)]
238-
mock_stdin = io.BytesIO(b"y")
239-
sys.stdin = io.TextIOWrapper(mock_stdin)
240-
igzip.main()
241-
out, err = capsysbinary.readouterr()
242-
assert gzip.decompress(out_file.read_bytes()) == DATA
264+
if PYPY:
265+
out, err = run_isal_igzip(str(test), stdin=b"y\n")
266+
else:
267+
sys.argv = ['', str(test)]
268+
mock_stdin = io.BytesIO(b"y")
269+
sys.stdin = io.TextIOWrapper(mock_stdin)
270+
igzip.main()
271+
out, err = capsysbinary.readouterr()
243272
assert b"already exists; do you wish to overwrite" in out
244273
assert err == b""
274+
assert gzip.decompress(out_file.read_bytes()) == DATA
245275

246276

247277
def test_compress_infile_out_file_no_name(tmp_path, capsysbinary):
248278
test = tmp_path / "test"
249279
test.write_bytes(DATA)
250280
out_file = tmp_path / "compressed.gz"
251-
sys.argv = ['', '-n', '-o', str(out_file), str(test)]
252-
igzip.main()
253-
out, err = capsysbinary.readouterr()
281+
args = ['-n', '-o', str(out_file), str(test)]
282+
if PYPY:
283+
out, err = run_isal_igzip(*args)
284+
else:
285+
sys.argv = ['', '-n', '-o', str(out_file), str(test)]
286+
igzip.main()
287+
out, err = capsysbinary.readouterr()
254288
output = out_file.read_bytes()
255289
assert gzip.decompress(output) == DATA
256290
assert err == b''

tests/test_igzip_lib.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import itertools
1313
import os
1414
import pickle
15+
import sys
1516
import zlib
1617
from typing import NamedTuple
1718

@@ -119,6 +120,9 @@ def testDecompress4G(self):
119120
compressed = None
120121
decompressed = None
121122

123+
@pytest.mark.skipif(sys.implementation.name == "pypy",
124+
reason="Pickling is not a requirement, and certainly "
125+
"not a blocker for PyPy.")
122126
def testPickle(self):
123127
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
124128
with pytest.raises(TypeError):

tests/test_zlib_compliance.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,11 @@ def test_flush_large_length(self, size):
662662
dco.decompress(data, 1)
663663
self.assertEqual(dco.flush(size), input[1:])
664664

665+
# Skip this test for pypy. This is an extreme fringe use case. There are
666+
# constants provided for the mode parameter, so it seems very unlikely
667+
# custom ints will be used.
668+
@unittest.skipIf(sys.implementation.name == "pypy",
669+
"PyPy does not handle __index__ properly")
665670
def test_flush_custom_length(self):
666671
input = HAMLET_SCENE * 10
667672
data = isal_zlib.compress(input, 1)

0 commit comments

Comments
 (0)