11# gh-91321: Build a basic C++ test extension to check that the Python C API is 
22# compatible with C++ and does not emit C++ compiler warnings. 
33import  os .path 
4+ try :
5+     import  ssl 
6+ except  ImportError :
7+     ssl  =  None 
48import  sys 
59import  unittest 
610import  subprocess 
1115
1216MS_WINDOWS  =  (sys .platform  ==  'win32' )
1317
14- 
15- SETUP_TESTCPPEXT  =  support .findfile ('setup_testcppext.py' )
18+ PKG_CPPEXTDATA  =  os .path .join (os .path .dirname (__file__ ), "cppextdata" )
1619
1720
1821@support .requires_subprocess () 
@@ -31,6 +34,8 @@ def test_build_cpp03(self):
3134    @unittest .skipIf ( 
3235        '-fsanitize'  in  (sysconfig .get_config_var ('PY_CFLAGS' ) or  '' ), 
3336        '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' ) 
3439    # the test uses venv+pip: skip if it's not available 
3540    @support .requires_venv_with_pip () 
3641    def  check_build (self , std_cpp03 , extension_name ):
@@ -59,11 +64,15 @@ def _check_build(self, std_cpp03, extension_name):
5964            python  =  os .path .join (venv_dir , 'bin' , python_exe )
6065
6166        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 
6270            if  verbose :
6371                print ('Run:' , ' ' .join (cmd ))
64-                 subprocess .run (cmd , check = True )
72+                 subprocess .run (cmd , check = True ,  env = env )
6573            else :
6674                proc  =  subprocess .run (cmd ,
75+                                       env = env ,
6776                                      stdout = subprocess .PIPE ,
6877                                      stderr = subprocess .STDOUT ,
6978                                      text = True )
@@ -72,16 +81,9 @@ def run_cmd(operation, cmd):
7281                    self .fail (
7382                        f"{ operation }   failed with exit code { proc .returncode }  " )
7483
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 
84+         # Build and install the C++ extension 
8385        cmd  =  [python , '-X' , 'dev' ,
84-                SETUP_TESTCPPEXT , 'install' ]
86+                '-m' , 'pip'  ,  ' install',  PKG_CPPEXTDATA ]
8587        run_cmd ('Install' , cmd )
8688
8789        # Do a reference run. Until we test that running python 
0 commit comments