8000 gh-95299: Rework test_cppext.py to not invoke setup.py directly by pradyunsg · Pull Request #103316 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-95299: Rework test_cppext.py to not invoke setup.py directly #103316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "gh-95299: Rework test_cppext.py to not invoke setup.py directly"
This reverts commit 41c5a66.
  • Loading branch information
pradyunsg committed Apr 6, 2023
commit d79d6a662dfad022c9ce035fe8af2d65c8e23d07
11 changes: 8 additions & 3 deletions Lib/test/cppextdata/setup.py → Lib/test/setup_testcppext.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# gh-91321: Build a basic C++ test extension to check that the Python C API is
# compatible with C++ and does not emit C++ compiler warnings.
import os
import sys
from test import support

Expand All @@ -26,8 +25,14 @@

def main():
cppflags = list(CPPFLAGS)
std = os.environ["CPYTHON_TEST_CPP_STD"]
name = os.environ["CPYTHON_TEST_EXT_NAME"]
if '-std=c++03' in sys.argv:
sys.argv.remove('-std=c++03')
std = 'c++03'
name = '_testcpp03ext'
else:
# Python currently targets C++11
std = 'c++11'
name = '_testcpp11ext'

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

Expand Down
26 changes: 12 additions & 14 deletions Lib/test/test_cppext.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# gh-91321: Build a basic C++ test extension to check that the Python C API is
# compatible with C++ and does not emit C++ compiler warnings.
import os.path
try:
import ssl
except ImportError:
ssl = None
import sys
import unittest
import subprocess
Expand All @@ -15,7 +11,8 @@

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

PKG_CPPEXTDATA = os.path.join(os.path.dirname(__file__), "cppextdata")

SETUP_TESTCPPEXT = support.findfile('setup_testcppext.py')


@support.requires_subprocess()
Expand All @@ -34,8 +31,6 @@ def test_buil 8000 d_cpp03(self):
@unittest.skipIf(
'-fsanitize' in (sysconfig.get_config_var('PY_CFLAGS') or ''),
'test does not work with analyzing builds')
# the test uses pip which needs a TLS connection to PyPI
@unittest.skipIf(ssl is None, 'No ssl module')
# the test uses venv+pip: skip if it's not available
@support.requires_venv_with_pip()
def check_build(self, std_cpp03, extension_name):
Expand Down Expand Up @@ -64,15 +59,11 @@ def _check_build(self, std_cpp03, extension_name):
python = os.path.join(venv_dir, 'bin', python_exe)

def run_cmd(operation, cmd):
env = os.environ.copy()
env['CPYTHON_TEST_CPP_STD'] = 'c++03' if std_cpp03 else 'c++11'
env['CPYTHON_TEST_EXT_NAME'] = extension_name
if verbose:
print('Run:', ' '.join(cmd))
subprocess.run(cmd, check=True, env=env)
subprocess.run(cmd, check=True)
else:
proc = subprocess.run(cmd,
env=env,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True)
Expand All @@ -81,9 +72,16 @@ def run_cmd(operation, cmd):
self.fail(
f"{operation} failed with exit code {proc.returncode}")

# Build and install the C++ extension
# Build the C++ extension
cmd = [python, '-X', 'dev',
SETUP_TESTCPPEXT, 'build_ext', '--verbose']
if std_cpp03:
cmd.append('-std=c++03')
run_cmd('Build', cmd)

# Install the C++ extension
cmd = [python, '-X', 'dev',
'-m', 'pip', 'install', PKG_CPPEXTDATA]
SETUP_TESTCPPEXT, 'install']
run_cmd('Install', cmd)

# Do a reference run. Until we test that running python
Expand Down
0