1
1
# gh-91321: Build a basic C++ test extension to check that the Python C API is
2
2
# compatible with C++ and does not emit C++ compiler warnings.
3
3
import os .path
4
- try :
5
- import ssl
6
- except ImportError :
7
- ssl = None
8
4
import sys
9
5
import unittest
10
6
import subprocess
15
11
16
12
MS_WINDOWS = (sys .platform == 'win32' )
17
13
18
- PKG_CPPEXTDATA = os .path .join (os .path .dirname (__file__ ), "cppextdata" )
14
+
15
+ SETUP_TESTCPPEXT = support .findfile ('setup_testcppext.py' )
19
16
20
17
21
18
@support .requires_subprocess ()
@@ -34,8 +31,6 @@ def test_build_cpp03(self):
34
31
@unittest .skipIf (
35
32
'-fsanitize' in (sysconfig .get_config_var ('PY_CFLAGS' ) or '' ),
36
33
'test does not work with analyzing builds' )
37
- # the test uses pip which needs a TLS connection to PyPI
38
- @unittest .skipIf (ssl is None , 'No ssl module' )
39
34
# the test uses venv+pip: skip if it's not available
40
35
@support .requires_venv_with_pip ()
41
36
def check_build (self , std_cpp03 , extension_name ):
@@ -64,15 +59,11 @@ def _check_build(self, std_cpp03, extension_name):
64
59
python = os .path .join (venv_dir , 'bin' , python_exe )
65
60
66
61
def run_cmd (operation , cmd ):
67
- env = os .environ .copy ()
68
- env ['CPYTHON_TEST_CPP_STD' ] = 'c++03' if std_cpp03 else 'c++11'
69
- env ['CPYTHON_TEST_EXT_NAME' ] = extension_name
70
62
if verbose :
71
63
print ('Run:' , ' ' .join (cmd ))
72
- subprocess .run (cmd , check = True , env = env )
64
+ subprocess .run (cmd , check = True )
73
65
else :
74
66
proc = subprocess .run (cmd ,
75
- env = env ,
76
67
stdout = subprocess .PIPE ,
77
68
stderr = subprocess .STDOUT ,
78
69
text = True )
@@ -81,9 +72,16 @@ def run_cmd(operation, cmd):
81
72
self .fail (
82
73
f"{ operation } failed with exit code { proc .returncode } " )
83
74
84
- # Build and install the C++ extension
75
+ # Build the C++ extension
76
+ cmd = [python , '-X' , 'dev' ,
77
+ SETUP_TESTCPPEXT , 'build_ext' , '--verbose' ]
78
+ if std_cpp03 :
79
+ cmd .append ('-std=c++03' )
80
+ run_cmd ('Build' , cmd )
81
+
82
+ # Install the C++ extension
85
83
cmd = [python , '-X' , 'dev' ,
86
- '-m' , 'pip' , ' install', PKG_CPPEXTDATA ]
84
+ SETUP_TESTCPPEXT , 'install' ]
87
85
run_cmd ('Install' , cmd )
88
86
89
87
# Do a reference run. Until we test that running python
0 commit comments