Skip to content

Accept CMake args as env vars for Python setup#3123

Merged
davisking merged 1 commit into
davisking:masterfrom
turicas:enhancement/python-setup-env-vars
Nov 28, 2025
Merged

Accept CMake args as env vars for Python setup#3123
davisking merged 1 commit into
davisking:masterfrom
turicas:enhancement/python-setup-env-vars

Conversation

@turicas

@turicas turicas commented Nov 27, 2025

Copy link
Copy Markdown
Contributor

To facilitate compiling custom Python wheels (partially addressing #3037), I updated setup.py to read environment variables starting with DLIB_. These variables are now automatically added to the CMake invocation as -D<VAR>=<VALUE> arguments. This allows the Python extension to be configured using the same environment variables as the native CMake build.

Why this is important: modern build tools like cibuildwheel use PEP 517 standard commands (python -m build or pip wheel), which do not support passing custom arguments to setup.py (like --set or --no). Without this change, building dlib with specific CMake flags in CI environments requires patching setup.py via scripts (e.g., sed), which is brittle and error-prone.

Environment variables now override default settings defined in setup.py. For example, export DLIB_USE_FFMPEG=ON will override the default OFF setting. The priority order is: CLI arguments > environment variables > default options (hardcoded in setup.py).

@davisking

Copy link
Copy Markdown
Owner

Nice, thanks for the PR :)

@davisking davisking merged commit 49b7cba into davisking:master Nov 28, 2025
2 checks passed
@turicas turicas deleted the enhancement/python-setup-env-vars branch November 28, 2025 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants