1- import importlib
1+ from importlib . util import spec_from_file_location , module_from_spec
22import os
33import pathlib
44import pytest
@@ -60,7 +60,9 @@ def test_cython(tmp_path):
6060 # We don't want a wheel build, so do the steps in a controlled way
6161 # The meson.build file is not copied as part of the build, so generate it
6262 with open (build_dir / "meson.build" , "wt" , encoding = "utf-8" ) as fid :
63- fid .write (textwrap .dedent ("""\
63+ get_inc = ('import os; os.chdir(".."); import numpy; '
64+ 'print(os.path.abspath(numpy.get_include() + "../../.."))' )
65+ fid .write (textwrap .dedent (f"""\
6466 project('random-build-examples', 'c', 'cpp', 'cython')
6567
6668 # https://mesonbuild.com/Python-module.html
@@ -77,10 +79,8 @@ def test_cython(tmp_path):
7779 error('tests requires Cython >= 0.29.35')
7880 endif
7981
80- _numpy_abs = run_command(py3,
81- ['-c', 'import os; os.chdir(".."); import numpy; print(os.path.abspath(numpy.get_include() + "../../.."))'],
82- check: true
83- ).stdout().strip()
82+ _numpy_abs = run_command(py3, ['-c', '{ get_inc } '],
83+ check: true).stdout().strip()
8484
8585 npymath_path = _numpy_abs / 'core' / 'lib'
8686 npy_include_path = _numpy_abs / 'core' / 'include'
@@ -123,11 +123,11 @@ def test_cython(tmp_path):
123123 # import without adding the directory to sys.path
124124 so1 = sorted (glob .glob (str (target_dir / "extending.*" )))[0 ]
125125 so2 = sorted (glob .glob (str (target_dir / "extending_distributions.*" )))[0 ]
126- spec1 = importlib . util . spec_from_file_location ("extending" , so1 )
127- spec2 = importlib . util . spec_from_file_location ("extending_distributions" , so2 )
128- extending = importlib . util . module_from_spec (spec1 )
126+ spec1 = spec_from_file_location ("extending" , so1 )
127+ spec2 = spec_from_file_location ("extending_distributions" , so2 )
128+ extending = module_from_spec (spec1 )
129129 spec1 .loader .exec_module (extending )
130- extending_distributions = importlib . util . module_from_spec (spec2 )
130+ extending_distributions = module_from_spec (spec2 )
131131 spec2 .loader .exec_module (extending_distributions )
132132 # actually test the cython c-extension
133133 from numpy .random import PCG64
0 commit comments