pybind11 icon indicating copy to clipboard operation
pybind11 copied to clipboard

--includes - escape paths with spaces in include list

Open MarkusBauer opened this issue 2 years ago • 0 comments

Description

tl;dr: pybind11 --includes returns invalid arguments when the project's directory contains spaces.

When you build an extension manually, the docs suggest this command: c++ ... $(python3 -m pybind11 --includes) .... However, this command fails when the project's directory contains a space in its path. The command would then expand to c++ ... -I/home/user/a b/c -I/python ..., where /home/user/a is a in invalid include directory, and b/c is an invalid compiler argument.

Even if no manual build is desired this bug might affect users: for example, we're currently building clang-tidy in our project, which requires all include paths.

To solve this issue, this PR escapes include paths of pybind11 --includes before printing. Paths without spaces/special characters are printed as-is, while paths with spaces are wrapped in ''. Thus, the final command line of custom builds will be valid even if spaces occur: c++ ... '-I/home/user/a b/c' -I/python ...

Suggested changelog entry:

MarkusBauer avatar Oct 05 '23 14:10 MarkusBauer