@@ -103,6 +103,15 @@ def test_cython(tmp_path):
103
103
include_directories: [npy_include_path],
104
104
dependencies: [npyrandom_lib, npymath_lib],
105
105
)
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
+ )
106
115
""" ))
107
116
target_dir = build_dir / "build"
108
117
os .makedirs (target_dir , exist_ok = True )
@@ -132,15 +141,19 @@ def test_cython(tmp_path):
132
141
"wrong pxd used" .format (txt_to_find ))
133
142
# import without adding the directory to sys.path
134
143
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" )
143
155
# actually test the cython c-extension
156
+ extending_distributions = load ("extending_distributions" )
144
157
from numpy .random import PCG64
145
158
values = extending_distributions .uniforms_ex (PCG64 (0 ), 10 , 'd' )
146
159
assert values .shape == (10 ,)
0 commit comments