Skip to content

Commit bedeacf

Browse files
committed
TST: refactor to add a cython build that uses cpp
1 parent e290d1c commit bedeacf

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

.github/workflows/emscripten.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ jobs:
7171
pyodide venv .venv-pyodide
7272
source .venv-pyodide/bin/activate
7373
pip install dist/*.whl
74+
python -c "import sys; print(sys.platform)"
7475
pip install -r test_requirements.txt
7576
- name: Test
7677
run: |

numpy/random/tests/test_extending.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ def test_cython(tmp_path):
103103
include_directories: [npy_include_path],
104104
dependencies: [npyrandom_lib, npymath_lib],
105105
)
106+
py.extension_module(
107+
'extending_cpp',
108+
'extending_distributions.pyx',
109+
install: false,
110+
override_options : ['cython_language=cpp'],
111+
cython_args: ['--module-name', 'extending_cpp'],
112+
include_directories: [npy_include_path],
113+
dependencies: [npyrandom_lib, npymath_lib],
114+
)
106115
"""))
107116
target_dir = build_dir / "build"
108117
os.makedirs(target_dir, exist_ok=True)
@@ -132,15 +141,19 @@ def test_cython(tmp_path):
132141
"wrong pxd used".format(txt_to_find))
133142
# import without adding the directory to sys.path
134143
suffix = sysconfig.get_config_var('EXT_SUFFIX')
135-
so1 = (target_dir / "extending").with_suffix(suffix)
136-
so2 = (target_dir / "extending_distributions").with_suffix(suffix)
137-
spec1 = spec_from_file_location("extending", so1)
138-
spec2 = spec_from_file_location("extending_distributions", so2)
139-
extending = module_from_spec(spec1)
140-
spec1.loader.exec_module(extending)
141-
extending_distributions = module_from_spec(spec2)
142-
spec2.loader.exec_module(extending_distributions)
144+
145+
def load(modname):
146+
so = (target_dir / modname).with_suffix(suffix)
147+
spec = spec_from_file_location(modname, so)
148+
mod = module_from_spec(spec)
149+
spec.loader.exec_module(mod)
150+
return mod
151+
152+
# test that the module can be imported
153+
load("extending")
154+
load("extending_cpp")
143155
# actually test the cython c-extension
156+
extending_distributions = load("extending_distributions")
144157
from numpy.random import PCG64
145158
values = extending_distributions.uniforms_ex(PCG64(0), 10, 'd')
146159
assert values.shape == (10,)

0 commit comments

Comments
 (0)