gh91321 build a basic c test extension to check that the python c api is compatible with c and does not emit c compiler warnings c compiler flags for gcc and clang gh91321 the purpose of testcppext extension is to check that building a c extension using the python c api does not emit c compiler warnings don t pass any compiler flag to msvc gh105776 when gcc std11 is used as the c compiler stdc11 option emits a c compiler warning remove std11 option from the cc command cc env var overrides sysconfig cc variable in setuptools 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 c compiler flags for gcc and clang gh 91321 the purpose of _testcppext extension is to check that building a c extension using the python c api does not emit c compiler warnings don t pass any compiler flag to msvc gh 105776 when gcc std 11 is used as the c compiler std c11 option emits a c compiler warning remove std11 option from the cc command cc env var overrides sysconfig cc variable in setuptools
import os
import shlex
import sys
import sysconfig
from test import support

from setuptools import setup, Extension


SOURCE = 'extension.cpp'
if not support.MS_WINDOWS:
    
    CPPFLAGS = [
        
        
        
        '-Werror',
    ]
else:
    
    CPPFLAGS = []


def main():
    cppflags = list(CPPFLAGS)
    std = os.environ["CPYTHON_TEST_CPP_STD"]
    name = os.environ["CPYTHON_TEST_EXT_NAME"]

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

    
    
    
    cmd = (sysconfig.get_config_var('CC') or '')
    if cmd is not None:
        cmd = shlex.split(cmd)
        cmd = [arg for arg in cmd if not arg.startswith('-std=')]
        cmd = shlex.join(cmd)
        
        os.environ['CC'] = cmd

    cpp_ext = Extension(
        name,
        sources=[SOURCE],
        language='c++',
        extra_compile_args=cppflags)
    setup(name='internal' + name, version='0.0', ext_modules=[cpp_ext])


if __name__ == "__main__":
    main()