11import os
2+ import shutil
23import subprocess
34import sys
45import sysconfig
89
910import numpy as np
1011from numpy .testing import IS_EDITABLE , IS_WASM , assert_array_equal
12+ from numpy .testing ._private .utils import run_subprocess
1113
1214# This import is copied from random.tests.test_extending
1315try :
@@ -40,8 +42,17 @@ def install_temp(tmpdir_factory):
4042 if IS_WASM :
4143 pytest .skip ("No subprocess" )
4244
43- srcdir = os .path .join (os .path .dirname (__file__ ), 'examples' , 'cython' )
44- build_dir = tmpdir_factory .mktemp ("cython_test" ) / "build"
45+ # Build against a copy of the sources placed next to the build dir:
46+ # meson refers to sources via paths relative to the build dir, and on
47+ # Windows the unnormalized cwd + `..` chain joining the deeply nested
48+ # pytest tmp dir and site-packages can exceed MAX_PATH, failing the
49+ # compile with "Cannot open source file".
50+ tmp_root = tmpdir_factory .mktemp ("cython_test" )
51+ srcdir = str (tmp_root / "src" )
52+ shutil .copytree (
53+ os .path .join (os .path .dirname (__file__ ), 'examples' , 'cython' ),
54+ srcdir )
55+ build_dir = tmp_root / "build"
4556 os .makedirs (build_dir , exist_ok = True )
4657 # Ensure we use the correct Python interpreter even when `meson` is
4758 # installed in a different Python environment (see gh-24956)
@@ -58,27 +69,16 @@ def install_temp(tmpdir_factory):
5869 if sysconfig .get_platform () == "win-arm64" :
5970 pytest .skip ("Meson unable to find MSVC linker on win-arm64" )
6071 if sys .platform == "win32" :
61- subprocess .check_call (["meson" , "setup" ,
62- "--buildtype=release" ,
63- "--vsenv" , "--native-file" , native_file ,
64- str (srcdir )],
65- cwd = build_dir ,
66- )
72+ run_subprocess (["meson" , "setup" ,
73+ "--buildtype=release" ,
74+ "--vsenv" , "--native-file" , native_file ,
75+ str (srcdir )],
76+ build_dir )
6777 else :
68- subprocess .check_call (["meson" , "setup" ,
69- "--native-file" , native_file , str (srcdir )],
70- cwd = build_dir
71- )
72- try :
73- subprocess .check_call (["meson" , "compile" , "-vv" ], cwd = build_dir )
74- except subprocess .CalledProcessError :
75- print ("----------------" )
76- print ("meson build failed when doing" )
77- print (f"'meson setup --native-file { native_file } { srcdir } '" )
78- print ("'meson compile -vv'" )
79- print (f"in { build_dir } " )
80- print ("----------------" )
81- raise
78+ run_subprocess (["meson" , "setup" ,
79+ "--native-file" , native_file , str (srcdir )],
80+ build_dir )
81+ run_subprocess (["meson" , "compile" , "-vv" ], build_dir )
8282
8383 sys .path .append (str (build_dir ))
8484
0 commit comments