From 5565213cc2f3e783c91bcc89501c7c958ff8d083 Mon Sep 17 00:00:00 2001 From: Ayaz Salikhov Date: Sat, 1 Nov 2025 01:08:09 +0000 Subject: [PATCH] Improve setup.py --- src/setup.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/setup.py b/src/setup.py index 0fc8c55..d1fc432 100644 --- a/src/setup.py +++ b/src/setup.py @@ -9,7 +9,12 @@ language = "c++" std = "c++17" -default_compile_args = sysconfig.get_config_var("CFLAGS").split() +# Handle case where CFLAGS might be None +if args := sysconfig.get_config_var("CFLAGS"): + default_compile_args = args.split() +else: + default_compile_args = [] + extra_compile_args = [f"-std={std}", "-Wall", "-Wextra", "-Werror", "-DNDEBUG", "-O3"] print(f"Default compile arguments: {default_compile_args}") @@ -17,21 +22,30 @@ cpython_extension = Extension( "cpython_sieve", - sources=[THIS_DIR / "cpython_wrapper.cpp", THIS_DIR / "cpp_impl/sieve.cpp"], + sources=[ + str(THIS_DIR / "cpython_wrapper.cpp"), + str(THIS_DIR / "cpp_impl/sieve.cpp"), + ], extra_compile_args=extra_compile_args, language=language, + include_dirs=[str(THIS_DIR / "cpp_impl")], ) cython_extension = Extension( "cython_sieve", - sources=[THIS_DIR / "cython_wrapper/wrapper.pyx", THIS_DIR / "cpp_impl/sieve.cpp"], + sources=[ + str(THIS_DIR / "cython_wrapper/wrapper.pyx"), + str(THIS_DIR / "cpp_impl/sieve.cpp"), + ], extra_compile_args=extra_compile_args, language=language, + include_dirs=[str(THIS_DIR / "cpp_impl")], ) -setup( +_ = setup( name="cpp_python_extension", - version="1.0", - description="This is Example module written in C++", + version="1.0.0", + description="Example module written in C++ with Python bindings", ext_modules=cythonize([cython_extension]) + [cpython_extension], + zip_safe=False, )