Skip to content

Commit a489b3b

Browse files
authored
Merge pull request #74 from pycompression/profile
Refactor setup.py so compiler directives can be set globally.
2 parents 0dda934 + 76ad49d commit a489b3b

File tree

9 files changed

+39
-34
lines changed

9 files changed

+39
-34
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ jobs:
3030
matrix:
3131
tox_env:
3232
- docs
33-
- mypy
3433
- twine_check
3534
needs: lint
3635
runs-on: ubuntu-20.04

profile_igzipreader.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import cProfile
2+
import sys
3+
4+
from isal import igzip
5+
6+
7+
def main():
8+
with igzip.open(sys.argv[1], mode="rb") as gzip_h:
9+
while True:
10+
block = gzip_h.read(32*1024)
11+
if block == b"":
12+
return
13+
14+
15+
if __name__ == "__main__":
16+
cProfile.run("main()")

setup.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
SYSTEM_IS_WINDOWS = sys.platform.startswith("win")
3737

3838

39+
def default_compiler_directives():
40+
return dict(language_level="3",
41+
binding=True)
42+
43+
3944
class IsalExtension(Extension):
4045
"""Custom extension to allow for targeted modification."""
4146
pass
@@ -106,21 +111,22 @@ def build_extension(self, ext):
106111
# -fPIC needed for proper static linking
107112
ext.extra_compile_args = ["-fPIC"]
108113

109-
if os.getenv("CYTHON_COVERAGE") is not None:
110-
# Import cython here so python setup.py can be used without
111-
# installing cython.
112-
from Cython.Build import cythonize
113-
# Add cython directives and macros for coverage support.
114-
cythonized_exts = cythonize(ext, compiler_directives=dict(
115-
linetrace=True
116-
))
117-
for cython_ext in cythonized_exts:
114+
# Import cython here so python setup.py can be used without
115+
# installing cython.
116+
from Cython.Build import cythonize
117+
compiler_directives = default_compiler_directives()
118+
line_tracing_enabled = os.getenv("CYTHON_COVERAGE") is not None
119+
if line_tracing_enabled:
120+
# Add cython directives for coverage support.
121+
compiler_directives.update(linetrace=True)
122+
cythonized_exts = cythonize(
123+
ext, compiler_directives=compiler_directives)
124+
125+
for cython_ext in cythonized_exts:
126+
if line_tracing_enabled:
118127
cython_ext.define_macros = [("CYTHON_TRACE_NOGIL", "1")]
119-
cython_ext._needs_stub = False
120-
super().build_extension(cython_ext)
121-
return
122-
123-
super().build_extension(ext)
128+
cython_ext._needs_stub = False
129+
super().build_extension(cython_ext)
124130

125131

126132
# Use a cache to prevent isa-l from being build twice. According to the

src/isal/_isal.pyx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
# SOFTWARE.
2020

21-
# cython: language_level=3
22-
2321
from .version cimport ISAL_MAJOR_VERSION as C_ISAL_MAJOR_VERSION
2422
from .version cimport ISAL_MINOR_VERSION as C_ISAL_MINOR_VERSION
2523
from .version cimport ISAL_PATCH_VERSION as C_ISAL_PATCH_VERSION

src/isal/crc.pxd

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
# SOFTWARE.
2020

21-
# cython: language_level=3
22-
2321
cdef extern from "<isa-l/crc.h>":
2422
cdef unsigned int crc32_gzip_refl(
2523
unsigned int init_crc, #!< initial CRC value, 32 bits

src/isal/igzip_lib.pxd

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
# SOFTWARE.
2020

21-
# cython: language_level=3
22-
2321
cdef extern from "<isa-l/igzip_lib.h>":
2422
# Deflate compression standard defines
2523
int ISAL_DEF_MAX_HDR_SIZE

src/isal/igzip_lib.pyx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
# SOFTWARE.
2020

21-
# cython: language_level=3
22-
# cython: binding=True
23-
2421
"""
2522
Pythonic interface to ISA-L's igzip_lib.
2623

src/isal/isal_zlib.pyx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
# SOFTWARE.
2020

21-
# cython: language_level=3
22-
# cython: binding=True
23-
2421
"""
2522
Implementation of the zlib module using the ISA-L libraries.
2623
"""

tox.ini

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,12 @@ commands=
4242
[testenv:lint]
4343
deps=flake8
4444
flake8-import-order
45+
mypy
46+
pytest
4547
skip_install=True
4648
commands =
4749
flake8 src tests setup.py benchmark.py
48-
49-
[testenv:mypy]
50-
# pytest dep needed for mypy check
51-
deps=mypy
52-
pytest
53-
commands =
54-
mypy src/ tests/
50+
mypy src/ tests
5551

5652
[testenv:twine_check]
5753
deps=wheel

0 commit comments

Comments
 (0)