Skip to content

Commit 16b6782

Browse files
committed
Use better qualified name for cpython extension module shared library
Shared library for a cpython extension module should be suffixed by the value of the EXT_SUFFIX configuration variable from the sysconfig module. Fixes #24.
1 parent 7326e78 commit 16b6782

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

hatch_cpp/tests/test_projects.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
from os import listdir
1+
import contextlib
2+
from os import listdir, remove
23
from pathlib import Path
3-
from shutil import rmtree
44
from subprocess import check_call
55
from sys import modules, path, platform
6+
from sysconfig import get_config_var
67

78
import pytest
89

@@ -24,9 +25,15 @@ class TestProject:
2425
],
2526
)
2627
def test_basic(self, project):
28+
29+
suffix_ext = get_config_var("EXT_SUFFIX")
30+
2731
# cleanup
28-
rmtree(f"hatch_cpp/tests/{project}/project/extension.so", ignore_errors=True)
29-
rmtree(f"hatch_cpp/tests/{project}/project/extension.pyd", ignore_errors=True)
32+
with contextlib.suppress(FileNotFoundError):
33+
remove(f"hatch_cpp/tests/{project}/project/extension.so")
34+
remove(f"hatch_cpp/tests/{project}/project/extension.pyd")
35+
remove(f"hatch_cpp/tests/{project}/project/extension{suffix_ext}")
36+
3037
modules.pop("project", None)
3138
modules.pop("project.extension", None)
3239

@@ -40,14 +47,14 @@ def test_basic(self, project):
4047
)
4148

4249
# assert built
43-
50+
project_dir_content = listdir(f"hatch_cpp/tests/{project}/project")
4451
if project == "test_project_limited_api" and platform != "win32":
45-
assert "extension.abi3.so" in listdir(f"hatch_cpp/tests/{project}/project")
52+
assert "extension.abi3.so" in project_dir_content
4653
else:
4754
if platform == "win32":
48-
assert "extension.pyd" in listdir(f"hatch_cpp/tests/{project}/project")
55+
assert "extension.pyd" in project_dir_content or f"extension{suffix_ext}" in project_dir_content
4956
else:
50-
assert "extension.so" in listdir(f"hatch_cpp/tests/{project}/project")
57+
assert "extension.so" in project_dir_content or f"extension{suffix_ext}" in project_dir_content
5158

5259
# import
5360
here = Path(__file__).parent / project

hatch_cpp/toolchains/common.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ def check_py_limited_api(cls, value: Any) -> Any:
101101
return value
102102

103103
def get_qualified_name(self, platform):
104+
if self.binding == "cpython" and not self.py_limited_api:
105+
suffix = get_config_var("EXT_SUFFIX")
106+
return f"{self.name}{suffix}"
104107
if platform == "win32":
105108
suffix = "dll" if self.binding == "generic" else "pyd"
106109
elif platform == "darwin":

0 commit comments

Comments
 (0)