Skip to content

Commit 3a18724

Browse files
committed
Take into account possible missing header file on Windows
1 parent 5d97d42 commit 3a18724

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

setup.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@
3232
BUILD_CACHE_FILE = Path(os.environ.get("PYTHON_ISAL_BUILD_CACHE_FILE",
3333
DEFAULT_CACHE_FILE))
3434

35+
EXTENSIONS = [
36+
Extension("isal.isal_zlib", ["src/isal/isal_zlibmodule.c"]),
37+
Extension("isal.igzip_lib", ["src/isal/igzip_libmodule.c"]),
38+
]
39+
40+
# This does not add the extension on windows for dynamic linking. The required
41+
# header file might be missing.
42+
if not (SYSTEM_IS_WINDOWS and
43+
os.getenv("PYTHON_ISAL_LINK_DYNAMIC") is not None):
44+
EXTENSIONS.append(Extension("isal._isal", ["src/isal/_isalmodule.c"]))
45+
3546

3647
class BuildIsalExt(build_ext):
3748
def build_extension(self, ext):
@@ -186,9 +197,5 @@ def build_isa_l(compiler_command: str, compiler_options: str):
186197
"Operating System :: Microsoft :: Windows",
187198
],
188199
python_requires=">=3.7", # We use METH_FASTCALL
189-
ext_modules=[
190-
Extension("isal.isal_zlib", ["src/isal/isal_zlibmodule.c"]),
191-
Extension("isal.igzip_lib", ["src/isal/igzip_libmodule.c"]),
192-
Extension("isal._isal", ["src/isal/_isalmodule.c"])
193-
]
200+
ext_modules=EXTENSIONS
194201
)

src/isal/__init__.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@
55
# This file is part of python-isal which is distributed under the
66
# PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2.
77

8-
from . import _isal
9-
10-
ISAL_MAJOR_VERSION: int = _isal.ISAL_MAJOR_VERSION
11-
ISAL_MINOR_VERSION: int = _isal.ISAL_MINOR_VERSION
12-
ISAL_PATCH_VERSION: int = _isal.ISAL_PATCH_VERSION
13-
ISAL_VERSION: str = _isal.ISAL_VERSION
8+
from typing import Optional
149

10+
try:
11+
from . import _isal
12+
ISAL_MAJOR_VERSION: Optional[int] = _isal.ISAL_MAJOR_VERSION
13+
ISAL_MINOR_VERSION: Optional[int] = _isal.ISAL_MINOR_VERSION
14+
ISAL_PATCH_VERSION: Optional[int] = _isal.ISAL_PATCH_VERSION
15+
ISAL_VERSION: Optional[str] = _isal.ISAL_VERSION
16+
except ImportError:
17+
ISAL_MAJOR_VERSION = None
18+
ISAL_MINOR_VERSION = None
19+
ISAL_PATCH_VERSION = None
20+
ISAL_VERSION = None
1521

1622
__all__ = [
1723
"ISAL_MAJOR_VERSION",

tests/test_zlib_compliance.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141

4242
class VersionTestCase(unittest.TestCase):
4343

44+
@unittest.skipIf(os.getenv("PYTHON_ISAL_LINK_DYNAMIC") is not None and
45+
sys.platform.startswith("win"),
46+
"Header file missing on windows")
4447
def test_library_version(self):
4548
# Test that the major version of the actual library in use matches the
4649
# major version that we were compiled against. We can't guarantee that

0 commit comments

Comments
 (0)