Skip to content

Commit d79d6a6

Browse files
committed
Revert "pythongh-95299: Rework test_cppext.py to not invoke setup.py directly"
This reverts commit 41c5a66.
1 parent 63d691c commit d79d6a6

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

Diff for: Lib/test/cppextdata/setup.py renamed to Lib/test/setup_testcppext.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
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.
3-
import os
43
import sys
54
from test import support
65

@@ -26,8 +25,14 @@
2625

2726
def main():
2827
cppflags = list(CPPFLAGS)
29-
std = os.environ["CPYTHON_TEST_CPP_STD"]
30-
name = os.environ["CPYTHON_TEST_EXT_NAME"]
28+
if '-std=c++03' in sys.argv:
29+
sys.argv.remove('-std=c++03')
30+
std = 'c++03'
31+
name = '_testcpp03ext'
32+
else:
33+
# Python currently targets C++11
34+
std = 'c++11'
35+
name = '_testcpp11ext'
3136

3237
cppflags = [*CPPFLAGS, f'-std={std}']
3338

Diff for: Lib/test/test_cppext.py

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
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.
33
import os.path
4-
try:
5-
import ssl
6-
except ImportError:
7-
ssl = None
84
import sys
95
import unittest
106
import subprocess
@@ -15,7 +11,8 @@
1511

1612
MS_WINDOWS = (sys.platform == 'win32')
1713

18-
PKG_CPPEXTDATA = os.path.join(os.path.dirname(__file__), "cppextdata")
14+
15+
SETUP_TESTCPPEXT = support.findfile('setup_testcppext.py')
1916

2017

2118
@support.requires_subprocess()
@@ -34,8 +31,6 @@ def test_build_cpp03(self):
3431
@unittest.skipIf(
3532
'-fsanitize' in (sysconfig.get_config_var('PY_CFLAGS') or ''),
3633
'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')
3934
# the test uses venv+pip: skip if it's not available
4035
@support.requires_venv_with_pip()
4136
def check_build(self, std_cpp03, extension_name):
@@ -64,15 +59,11 @@ def _check_build(self, std_cpp03, extension_name):
6459
python = os.path.join(venv_dir, 'bin', python_exe)
6560

6661
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
7062
if verbose:
7163
print('Run:', ' '.join(cmd))
72-
subprocess.run(cmd, check=True, env=env)
64+
subprocess.run(cmd, check=True)
7365
else:
7466
proc = subprocess.run(cmd,
75-
env=env,
7667
stdout=subprocess.PIPE,
7768
stderr=subprocess.STDOUT,
7869
text=True)
@@ -81,9 +72,16 @@ def run_cmd(operation, cmd):
8172
self.fail(
8273
f"{operation} failed with exit code {proc.returncode}")
8374

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
8583
cmd = [python, '-X', 'dev',
86-
'-m', 'pip', 'install', PKG_CPPEXTDATA]
84+
SETUP_TESTCPPEXT, 'install']
8785
run_cmd('Install', cmd)
8886

8987
# Do a reference run. Until we test that running python

0 commit comments

Comments
 (0)