@@ -35,39 +35,20 @@ def test_build_cpp03(self):
35
35
# the test uses venv+pip: skip if it's not available
36
36
@support .requires_venv_with_pip ()
37
37
def check_build (self , std_cpp03 , extension_name ):
38
- # Build in a temporary directory
39
- with os_helper . temp_cwd () :
40
- self ._check_build (std_cpp03 , extension_name )
38
+ venv_dir = 'env'
39
+ with support . setup_venv_with_pip_setuptools_wheel ( venv_dir ) as python_exe :
40
+ self ._check_build (std_cpp03 , extension_name , python_exe )
41
41
42
- def _check_build (self , std_cpp03 , extension_name ):
42
+ def _check_build (self , std_cpp03 , extension_name , python_exe ):
43
43
pkg_dir = 'pkg'
44
44
os .mkdir (pkg_dir )
45
45
shutil .copy (SETUP_TESTCPPEXT , os .path .join (pkg_dir , "setup.py" ))
46
46
47
- venv_dir = 'env'
48
- verbose = support .verbose
49
-
50
- # Create virtual environment to get setuptools
51
- cmd = [sys .executable , '-X' , 'dev' , '-m' , 'venv' , venv_dir ]
52
- if verbose :
53
- print ()
54
- print ('Run:' , ' ' .join (cmd ))
55
- subprocess .run (cmd , check = True )
56
-
57
- # Get the Python executable of the venv
58
- python_exe = 'python'
59
- if sys .executable .endswith ('.exe' ):
60
- python_exe += '.exe'
61
- if MS_WINDOWS :
62
- python = os .path .join (venv_dir , 'Scripts' , python_exe )
63
- else :
64
- python = os .path .join (venv_dir , 'bin' , python_exe )
65
-
66
47
def run_cmd (operation , cmd ):
67
48
env = os .environ .copy ()
68
49
env ['CPYTHON_TEST_CPP_STD' ] = 'c++03' if std_cpp03 else 'c++11'
69
50
env ['CPYTHON_TEST_EXT_NAME' ] = extension_name
70
- if verbose :
51
+ if support . verbose :
71
52
print ('Run:' , ' ' .join (cmd ))
72
53
subprocess .run (cmd , check = True , env = env )
73
54
else :
@@ -81,29 +62,23 @@ def run_cmd(operation, cmd):
81
62
self .fail (
82
63
f"{ operation } failed with exit code { proc .returncode } " )
83
64
84
- cmd = [python , '-X' , 'dev' ,
85
- '-m' , 'pip' , 'install' ,
86
- support .findfile ('setuptools-67.6.1-py3-none-any.whl' ),
87
- support .findfile ('wheel-0.40.0-py3-none-any.whl' )]
88
- run_cmd ('Install build dependencies' , cmd )
89
-
90
65
# Build and install the C++ extension
91
- cmd = [python , '-X' , 'dev' ,
66
+ cmd = [python_exe , '-X' , 'dev' ,
92
67
'-m' , 'pip' , 'install' , '--no-build-isolation' ,
93
68
os .path .abspath (pkg_dir )]
94
69
run_cmd ('Install' , cmd )
95
70
96
71
# Do a reference run. Until we test that running python
97
72
# doesn't leak references (gh-94755), run it so one can manually check
98
73
# -X showrefcount results against this baseline.
99
- cmd = [python ,
74
+ cmd = [python_exe ,
100
75
'-X' , 'dev' ,
101
76
'-X' , 'showrefcount' ,
102
77
'-c' , 'pass' ]
103
78
run_cmd ('Reference run' , cmd )
104
79
105
80
# Import the C++ extension
106
- cmd = [python ,
81
+ cmd = [python_exe ,
107
82
'-X' , 'dev' ,
108
83
'-X' , 'showrefcount' ,
109
84
'-c' , f"import { extension_name } " ]
0 commit comments