Skip to content

Commit

Permalink
Add namespace wheel test.
Browse files Browse the repository at this point in the history
  • Loading branch information
HexDecimal committed Sep 20, 2021
1 parent b54bd7b commit 317b3d9
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 0 deletions.
Binary file not shown.
17 changes: 17 additions & 0 deletions delocate/tests/test_wheelies.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def _collect_wheel(globber):
PURE_WHEEL = _collect_wheel('fakepkg2-1.0-py*.whl')
RPATH_WHEEL = _collect_wheel('fakepkg_rpath-1.0-cp*.whl')
TOPLEVEL_WHEEL = _collect_wheel('fakepkg_toplevel-1.0-cp*.whl')
NAMESPACE_WHEEL = _collect_wheel('fakepkg_namespace-1.0-cp*.whl')
STRAY_LIB = pjoin(DATA_PATH, 'libextfunc.dylib')
# The install_name in the wheel for the stray library
STRAY_LIB_DEP = realpath(STRAY_LIB)
Expand Down Expand Up @@ -365,3 +366,19 @@ def test_fix_toplevel() -> None:
assert delocate_wheel(TOPLEVEL_WHEEL, 'out.whl') == stray_libs
with InWheel("out.whl") as wheel_path:
assert "fakepkg_toplevel.dylibs" in os.listdir(wheel_path)


def test_fix_namespace() -> None:
# Test wheels which are organized with a namespace.
with InTemporaryDirectory():
# The module was set to expect its dependency in the libs/ directory
os.makedirs("libs")
shutil.copy(pjoin(DATA_PATH, "libextfunc2_rpath.dylib"), "libs")

dep_mod = 'namespace/subpkg/module2.abi3.so'
dep_path = '@rpath/libextfunc2_rpath.dylib'
stray_libs = {
realpath('libs/libextfunc2_rpath.dylib'): {dep_mod: dep_path},
}

assert delocate_wheel(NAMESPACE_WHEEL, 'out.whl') == stray_libs
3 changes: 3 additions & 0 deletions wheel_makers/fakepkg_namespace/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This contains a single compiled module stored in a subpackage of a namespace.

This reuses the `libextfunc2.dylib` library from the `fakepkg_rpath` wheel.
4 changes: 4 additions & 0 deletions wheel_makers/fakepkg_namespace/libs/extfunc2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
int extfunc2()
{
return 3;
}
Empty file.
32 changes: 32 additions & 0 deletions wheel_makers/fakepkg_namespace/namespace/subpkg/module2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#define PY_SSIZE_T_CLEAN
#include <Python.h>

int extfunc2(void); /*proto*/

static PyObject* func2(PyObject* self) {
return PyLong_FromLong(2);
}

static PyObject* func3(PyObject* self) {
return PyLong_FromLong((long)extfunc2());
}

static PyMethodDef module2_methods[] = {
{"func2", (PyCFunction)func2, METH_NOARGS, NULL},
{"func3", (PyCFunction)func3, METH_NOARGS, NULL},
{NULL, NULL, 0, NULL} /* sentinel */
};

static struct PyModuleDef module2 = {
PyModuleDef_HEAD_INIT,
"module2",
NULL,
-1,
module2_methods
};

PyMODINIT_FUNC
PyInit_module2(void)
{
return PyModule_Create(&module2);
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from namespace.subpkg.module2 import func2, func3 # type: ignore


def test_fakepkg():
assert func2() == 2
assert func3() == 3
43 changes: 43 additions & 0 deletions wheel_makers/fakepkg_namespace/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import subprocess
from pathlib import Path

from setuptools import Extension, setup # type: ignore

HERE = Path(__file__).parent.resolve(strict=True)
LIBS = HERE / "libs"
ARCH_FLAGS = ["-arch", "arm64", "-arch", "x86_64"] # Dual architecture.

subprocess.run(
[
"cc",
str(LIBS / "extfunc2.c"),
"-dynamiclib",
"-install_name",
"@rpath/libextfunc2_rpath.dylib",
"-o",
str(LIBS / "libextfunc2_rpath.dylib"),
]
+ ARCH_FLAGS,
check=True,
)

ext_modules = [
Extension(
"namespace.subpkg.module2",
["namespace/subpkg/module2.c"],
libraries=["extfunc2_rpath"],
extra_compile_args=ARCH_FLAGS,
extra_link_args=[f"-L{LIBS}", "-rpath", "libs/"],
py_limited_api=True,
)
]

setup(
ext_modules=ext_modules,
name="fakepkg_namespace",
version="1.0",
packages=[
'namespace.subpkg',
'namespace.subpkg.tests',
],
)
4 changes: 4 additions & 0 deletions wheel_makers/make_wheels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ cd fakepkg_toplevel
python setup.py clean bdist_wheel --py-limited-api=cp36
cd -

cd fakepkg_namespace
python setup.py clean bdist_wheel --py-limited-api=cp36
cd -

OUT_PATH=../delocate/tests/data
rm $OUT_PATH/fakepkg*.whl
cp */dist/*.whl $OUT_PATH
Expand Down

0 comments on commit 317b3d9

Please sign in to comment.