Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 44f372e

Browse filesBrowse files
committed
TST: add test package with internal shared library, installed in site-packages
1 parent d034a68 commit 44f372e
Copy full SHA for 44f372e

File tree

Expand file treeCollapse file tree

8 files changed

+121
-0
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+121
-0
lines changed
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# SPDX-FileCopyrightText: 2022 The meson-python developers
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
project('sharedlib-in-package', 'c', version: '1.0.0')
6+
7+
py = import('python').find_installation(pure: false)
8+
9+
subdir('mypkg')
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# SPDX-FileCopyrightText: 2024 The meson-python developers
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import os
6+
7+
8+
def _load_sharedlib():
9+
"""Load the `example_lib.dll` shared library on Windows
10+
11+
This shared library is installed alongside this __init__.py file. Due to
12+
lack of rpath support, Windows cannot find shared libraries installed
13+
within wheels. So pre-load it.
14+
"""
15+
if os.name == "nt":
16+
from ctypes import WinDLL
17+
basedir = os.path.dirname(__file__)
18+
dll_path = os.path.join(basedir, "examplelib.dll")
19+
WinDLL(dll_path)
20+
21+
22+
_load_sharedlib()
23+
24+
25+
from ._example import example_sum
+37Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// SPDX-FileCopyrightText: 2022 The meson-python developers
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
#include <Python.h>
6+
7+
#include "examplelib.h"
8+
9+
static PyObject* example_sum(PyObject* self, PyObject *args)
10+
{
11+
int a, b;
12+
if (!PyArg_ParseTuple(args, "ii", &a, &b)) {
13+
return NULL;
14+
}
15+
16+
long result = sum(a, b);
17+
18+
return PyLong_FromLong(result);
19+
}
20+
21+
static PyMethodDef methods[] = {
22+
{"example_sum", (PyCFunction)example_sum, METH_VARARGS, NULL},
23+
{NULL, NULL, 0, NULL},
24+
};
25+
26+
static struct PyModuleDef module = {
27+
PyModuleDef_HEAD_INIT,
28+
"_example",
29+
NULL,
30+
-1,
31+
methods,
32+
};
33+
34+
PyMODINIT_FUNC PyInit__example(void)
35+
{
36+
return PyModule_Create(&module);
37+
}
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// SPDX-FileCopyrightText: 2022 The meson-python developers
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
int sum(int a, int b) {
6+
return a + b;
7+
}
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// SPDX-FileCopyrightText: 2022 The meson-python developers
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
int sum(int a, int b);
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# SPDX-FileCopyrightText: 2022 The meson-python developers
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
example_lib = shared_library(
6+
'examplelib',
7+
'examplelib.c',
8+
install: true,
9+
install_dir: py.get_install_dir() / 'mypkg',
10+
)
11+
12+
py.extension_module(
13+
'_example',
14+
'_examplemod.c',
15+
link_with: example_lib,
16+
install: true,
17+
subdir: 'mypkg',
18+
install_rpath: '$ORIGIN',
19+
)
20+
21+
py.install_sources(
22+
['__init__.py'],
23+
subdir: 'mypkg',
24+
)
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# SPDX-FileCopyrightText: 2022 The meson-python developers
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
[build-system]
6+
build-backend = 'mesonpy'
7+
requires = ['meson-python']

‎tests/test_wheel.py

Copy file name to clipboardExpand all lines: tests/test_wheel.py
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ def test_local_lib(venv, wheel_link_against_local_lib):
161161
assert int(output) == 3
162162

163163

164+
@pytest.mark.skipif(MESON_VERSION < (0, 64, 0), reason='Meson version too old')
165+
def test_sharedlib_in_package(venv, wheel_sharedlib_in_package):
166+
venv.pip('install', wheel_sharedlib_in_package)
167+
output = venv.python('-c', 'import mypkg; print(mypkg.example_sum(2, 5))')
168+
assert int(output) == 7
169+
170+
164171
@pytest.mark.skipif(sys.platform not in {'linux', 'darwin'}, reason='Not supported on this platform')
165172
def test_rpath(wheel_link_against_local_lib, tmp_path):
166173
artifact = wheel.wheelfile.WheelFile(wheel_link_against_local_lib)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.