This question is similar to Python Setuptools Distribute: Optimize Option in setup.py?, but the question was asked 11 years ago and I hope that the python ecosystem developed further. We have a code where we would like to use assert for checks of invariants that have sometimes expensive scaling.¹ We can use assert for small problem sizes in a test suite, but do not want the asserts in production code. I know that one could execute python -O when invoking our code, but is there a way to strip asserts away at installation time? (Similar to -DCMAKE_BUILD_TYPE=Debug vs. -DCMAKE_BUILD_TYPE=Release for compiled languages.) Continue reading...