mirror of https://github.com/python/cpython
gh-95299: Rework test_cppext.py to not invoke setup.py directly (#103316)
* gh-95299: Rework test_cppext.py to not invoke setup.py directly * Add tests/cppextdata data to `TESTSUBDIRS` * Revert "Add tests/cppextdata data to `TESTSUBDIRS`" This reverts commit635492e539
. * Revert "gh-95299: Rework test_cppext.py to not invoke setup.py directly" This reverts commit41c5a667b5
. * Build and install the extension in a temporary directory instead * Pull in wheels for setuptools and wheel for testing extension builds
This commit is contained in:
parent
fb38c1b52e
commit
9e677406ee
|
@ -1,5 +1,6 @@
|
||||||
# gh-91321: Build a basic C++ test extension to check that the Python C API is
|
# 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.
|
# compatible with C++ and does not emit C++ compiler warnings.
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
from test import support
|
from test import support
|
||||||
|
|
||||||
|
@ -25,14 +26,8 @@ else:
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
cppflags = list(CPPFLAGS)
|
cppflags = list(CPPFLAGS)
|
||||||
if '-std=c++03' in sys.argv:
|
std = os.environ["CPYTHON_TEST_CPP_STD"]
|
||||||
sys.argv.remove('-std=c++03')
|
name = os.environ["CPYTHON_TEST_EXT_NAME"]
|
||||||
std = 'c++03'
|
|
||||||
name = '_testcpp03ext'
|
|
||||||
else:
|
|
||||||
# Python currently targets C++11
|
|
||||||
std = 'c++11'
|
|
||||||
name = '_testcpp11ext'
|
|
||||||
|
|
||||||
cppflags = [*CPPFLAGS, f'-std={std}']
|
cppflags = [*CPPFLAGS, f'-std={std}']
|
||||||
|
|
||||||
|
|
Binary file not shown.
|
@ -1,6 +1,7 @@
|
||||||
# gh-91321: Build a basic C++ test extension to check that the Python C API is
|
# 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.
|
# compatible with C++ and does not emit C++ compiler warnings.
|
||||||
import os.path
|
import os.path
|
||||||
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
import subprocess
|
import subprocess
|
||||||
|
@ -39,6 +40,10 @@ class TestCPPExt(unittest.TestCase):
|
||||||
self._check_build(std_cpp03, extension_name)
|
self._check_build(std_cpp03, extension_name)
|
||||||
|
|
||||||
def _check_build(self, std_cpp03, extension_name):
|
def _check_build(self, std_cpp03, extension_name):
|
||||||
|
pkg_dir = 'pkg'
|
||||||
|
os.mkdir(pkg_dir)
|
||||||
|
shutil.copy(SETUP_TESTCPPEXT, os.path.join(pkg_dir, "setup.py"))
|
||||||
|
|
||||||
venv_dir = 'env'
|
venv_dir = 'env'
|
||||||
verbose = support.verbose
|
verbose = support.verbose
|
||||||
|
|
||||||
|
@ -59,11 +64,15 @@ class TestCPPExt(unittest.TestCase):
|
||||||
python = os.path.join(venv_dir, 'bin', python_exe)
|
python = os.path.join(venv_dir, 'bin', python_exe)
|
||||||
|
|
||||||
def run_cmd(operation, cmd):
|
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:
|
if verbose:
|
||||||
print('Run:', ' '.join(cmd))
|
print('Run:', ' '.join(cmd))
|
||||||
subprocess.run(cmd, check=True)
|
subprocess.run(cmd, check=True, env=env)
|
||||||
else:
|
else:
|
||||||
proc = subprocess.run(cmd,
|
proc = subprocess.run(cmd,
|
||||||
|
env=env,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
text=True)
|
text=True)
|
||||||
|
@ -72,16 +81,16 @@ class TestCPPExt(unittest.TestCase):
|
||||||
self.fail(
|
self.fail(
|
||||||
f"{operation} failed with exit code {proc.returncode}")
|
f"{operation} failed with exit code {proc.returncode}")
|
||||||
|
|
||||||
# Build the C++ extension
|
|
||||||
cmd = [python, '-X', 'dev',
|
cmd = [python, '-X', 'dev',
|
||||||
SETUP_TESTCPPEXT, 'build_ext', '--verbose']
|
'-m', 'pip', 'install',
|
||||||
if std_cpp03:
|
support.findfile('setuptools-67.6.1-py3-none-any.whl'),
|
||||||
cmd.append('-std=c++03')
|
support.findfile('wheel-0.40.0-py3-none-any.whl')]
|
||||||
run_cmd('Build', cmd)
|
run_cmd('Install build dependencies', cmd)
|
||||||
|
|
||||||
# Install the C++ extension
|
# Build and install the C++ extension
|
||||||
cmd = [python, '-X', 'dev',
|
cmd = [python, '-X', 'dev',
|
||||||
SETUP_TESTCPPEXT, 'install']
|
'-m', 'pip', 'install', '--no-build-isolation',
|
||||||
|
os.path.abspath(pkg_dir)]
|
||||||
run_cmd('Install', cmd)
|
run_cmd('Install', cmd)
|
||||||
|
|
||||||
# Do a reference run. Until we test that running python
|
# Do a reference run. Until we test that running python
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue