Configuration options (pyproject.toml)#
The main configuration file for py-build-cmake is the standard pyproject.toml
file in the root of your project. All py-build-cmake-specific options live in the [tool.py-build-cmake]
section of the configuration file. Different subsections control different aspects of the build and packaging process, such as [tool.py-build-cmake.sdist]
for source distributions, [tool.py-build-cmake.cmake]
for CMake and other build-related options, and [tool.py-build-cmake.wheel]
for properties of binary Wheel packages. Detailed descriptions of all available sections and options can be found below.
module#
Defines the import name of the module or package, and the directory where it can be found.
Option |
Description |
Type |
Default |
---|---|---|---|
|
Import name in Python (can be different from the name on PyPI, which is defined in the [project] section). |
string |
|
|
Directory containing the Python module/package. |
path |
|
|
Set to true for PEP 420 namespace packages. |
bool |
|
|
Do not try to locate the main module in the source directory, but assume that it is generated by CMake. Dynamic metadata cannot be used when set. |
|
|
editable#
Defines how to perform an editable install (PEP 660). See Editable Install / Development Mode for more information.
Option |
Description |
Type |
Default |
---|---|---|---|
|
Mechanism to use for editable installations. Either write a wrapper |
|
|
|
Automatically re-build any changed files and C extension modules when the package is first imported by Python. It is recommended to use a fast generator like Ninja. Currently, the only mode that supports build hooks is |
bool |
|
sdist#
Specifies the files that should be included in the source distribution for this package.
Option |
Description |
Type |
Default |
---|---|---|---|
|
Files and folders to include in the source distribution. May include the ‘*’ wildcard or ‘**’ for recursive patterns. |
list |
|
|
Files and folders to exclude from the source distribution. May include the ‘*’ wildcard or ‘**’ for recursive patterns. |
list |
|
cmake#
Defines how to build the project to package. If omitted, py-build-cmake will produce a pure Python package.
Option |
Description |
Type |
Default |
---|---|---|---|
|
Minimum required CMake version. Used for policies in the automatically generated CMake cache pre-load files. If this version is not available in the system PATH, it will be installed automatically as a build dependency (using Pip). |
string |
|
|
Build type passed to the configuration step, as |
string |
|
|
Configuration type passed to the build step, as |
list |
|
|
CMake preset to use for configuration. Passed as |
string |
|
|
CMake presets to use for building. Passed as |
list |
|
|
CMake generator to use, passed to the configuration step, as |
string |
|
|
Folder containing CMakeLists.txt. |
path |
|
|
CMake build and cache folder. The placeholder |
path |
|
|
Extra options passed to the configuration step, as |
dict (CMake) |
|
|
Extra arguments passed to the configuration step. |
list+ |
|
|
Specify hints for CMake’s FindPython module. |
bool |
|
|
Specify hints for CMake’s FindPython3 module. |
bool |
|
|
Extra arguments passed to the build step. |
list+ |
|
|
Extra arguments passed to the build tool in the build step (e.g. to Make or Ninja). |
list+ |
|
|
Configuration types passed to the install step, as |
list |
|
|
Extra arguments passed to the install step. |
list+ |
|
|
List of components to install, the install step is executed once for each component, with the option |
list |
|
|
Environment variables to set when running CMake. Supports variable expansion using |
dict |
|
wheel#
Defines how to create the Wheel package.
Option |
Description |
Type |
Default |
---|---|---|---|
|
Indicate that this package contains no platform-specific binaries, only Python scripts and other platform-agnostic files. Setting this value to true causes the Wheel tags to be set to |
bool |
|
|
Override the default Python tag for the Wheel package. |
list |
|
|
Override the default ABI tag for the Wheel package. |
|
|
|
If |
int |
|
|
Override the default ABI tag for the Wheel package. |
list |
|
|
Override the default platform tag for the Wheel package. |
list |
|
|
Add an optional build number to the Wheel package. Must start with a number and cannot contain |
string |
|
stubgen#
If specified, mypy’s stubgen utility will be used to generate typed stubs for the Python files in the package.
Option |
Description |
Type |
Default |
---|---|---|---|
|
List of packages to generate stubs for, passed to stubgen as |
list |
|
|
List of modules to generate stubs for, passed to stubgen as |
list |
|
|
List of files to generate stubs for, passed to stubgen without any flags. |
list |
|
|
List of extra arguments passed to stubgen. |
list+ |
|
linux#
Specific options for Linux.
Option |
Description |
Type |
Default |
---|---|---|---|
|
Linux-specific editable options. |
|
|
|
Linux-specific sdist options. |
|
|
|
Linux-specific CMake options. |
|
|
|
Linux-specific Wheel options. |
|
windows#
Specific options for Windows.
Option |
Description |
Type |
Default |
---|---|---|---|
|
Windows-specific editable options. |
|
|
|
Windows-specific sdist options. |
|
|
|
Windows-specific CMake options. |
|
|
|
Windows-specific Wheel options. |
|
mac#
Specific options for macOS.
Option |
Description |
Type |
Default |
---|---|---|---|
|
macOS-specific editable options. |
|
|
|
macOS-specific sdist options. |
|
|
|
macOS-specific CMake options. |
|
|
|
macOS-specific Wheel options. |
|
cross#
Causes py-build-cmake to cross-compile the project. See Cross-compilation for more information.
Option |
Description |
Type |
Default |
---|---|---|---|
|
Operating system configuration to inherit from. |
|
|
|
Identifier for the Python implementation. |
string |
|
|
Python version, major and minor, without dots. |
string |
|
|
Python ABI. |
string |
|
|
Platform tag, consisting of the operating system and architecture (no dots or dashes, only underscores, all lowercase). |
string |
|
|
Root path of the Python installation. Used to set the |
path |
|
|
Python library file (.so on Linux, .lib on Windows). Used to set the |
filepath |
|
|
Python include directory (containing Python.h). Used to set the |
path |
|
|
CMake toolchain file to use. See https://cmake.org/cmake/help/book/mastering-cmake/chapter/Cross Compiling With CMake.html for more information. |
filepath |
|
|
The value for |
string |
|
|
Override editable options when cross-compiling. |
|
|
|
Override sdist options when cross-compiling. |
|
|
|
Override CMake options when cross-compiling. |
|
|
|
Override Wheel options when cross-compiling. |
|
Combining lists#
Many options are specified as lists of strings. When one of these options inherits from or is overridden by another option, these lists can be merged in different ways.
In the table above, when the data type is list
, the original list of options is simply replaced by the list it is overridden by.
When the data type is list+
, the value of the overriding option is appended to the original value. This is used primarily for combining lists of command-line options.
If you want full control of what happens when overriding a list option, you can use a dictionary with one or more of the following keys:
"="
: replace the original list by this list (default behavior for options of typelist
)"+"
: append the values of this list to the end of the original list (default behavior for options of typelist+
)"-"
: remove the values in this list from the original list (if present)"prepend"
: prepend the values of this list to the beginning of the original list
Some examples:
[cmake]
build_args = ["--verbose", "--clean-first"]
[linux.cmake]
build_args = ["--target", "foo"]
[windows.cmake]
build_args = {"-" = ["--verbose"], "+" = ["--target", "bar"]}
[macos.cmake]
build_args = {"=" = ["--target", "macos"]}
Because linux.cmake
inherits from cmake
, and because build_args
has type list+
, this will result in a value of ["--verbose", "--clean-first", "--target", "foo"]
for the linux.cmake.build_args
option. The value of windows.cmake.build_args
will be ["--clean_first", "--target", "bar"]
, and the value of macos.cmake.build_args
will be ["--target", "macos"]
.
[cmake]
config = ["Debug", "Release"]
[linux.cmake]
config = ["RelWithDebInfo"]
[windows.cmake]
config = {"prepend" = ["RelWithDebInfo"], "-" = ["Debug"], "+" = ["Debug"]}
The build_args
option has type list
, so the value of linux.cmake.config
is simply ["RelWithDebInfo"]
. The value of windows.cmake.config
is ["RelWithDebInfo", "Release", "Debug"]
.
The same rules also apply to CMake options:
[cmake.options]
CMAKE_PREFIX_PATH = "/some/path"
[linux.cmake.options]
CMAKE_PREFIX_PATH = {"prepend" = "/some/linux-specific/path"}
This passes the option -D CMAKE_PREFIX_PATH=/some/linux-specific/path;/some/path
to CMake.