| 1 |
####################### |
| 2 |
Backend Configuration |
| 3 |
####################### |
| 4 |
|
| 5 |
The ``--config-setting`` (or ``-C``) flag allows you to pass options to your **build backend**. The syntax and available |
| 6 |
options depend entirely on which backend you're using (e.g., `setuptools <https://setuptools.pypa.io/>`_, hatchling, |
| 7 |
`flit <https://flit.pypa.io/>`_). |
| 8 |
|
| 9 |
.. important:: |
| 10 |
|
| 11 |
The ``--config-setting`` flag passes options to the **build backend** that actually builds your package, not to |
| 12 |
build itself. Different backends accept different options. Check your backend's documentation for available |
| 13 |
settings. |
| 14 |
|
| 15 |
************** |
| 16 |
Basic syntax |
| 17 |
************** |
| 18 |
|
| 19 |
The basic syntax is: |
| 20 |
|
| 21 |
.. code-block:: console |
| 22 |
|
| 23 |
$ python -m build -C KEY=VALUE |
| 24 |
|
| 25 |
Or for options without values: |
| 26 |
|
| 27 |
.. code-block:: console |
| 28 |
|
| 29 |
$ python -m build -C KEY= |
| 30 |
|
| 31 |
.. note:: |
| 32 |
|
| 33 |
build also accepts the bare ``-C KEY`` form (without ``=``) and reads it as ``-C KEY=``, but warns you because pip |
| 34 |
rejects it. Write ``-C KEY=`` to keep the command working in both tools. |
| 35 |
|
| 36 |
Multiple settings can be provided: |
| 37 |
|
| 38 |
.. code-block:: console |
| 39 |
|
| 40 |
$ python -m build -C KEY1=VALUE1 -C KEY2=VALUE2 |
| 41 |
|
| 42 |
************ |
| 43 |
Setuptools |
| 44 |
************ |
| 45 |
|
| 46 |
Setuptools requires a special ``--build-option`` wrapper for most settings. |
| 47 |
|
| 48 |
Build numbers |
| 49 |
============= |
| 50 |
|
| 51 |
To add a build number to your wheel: |
| 52 |
|
| 53 |
.. code-block:: console |
| 54 |
|
| 55 |
$ python -m build --wheel \ |
| 56 |
-C--build-option=bdist_wheel \ |
| 57 |
-C--build-option=--build-number \ |
| 58 |
-C--build-option=123 |
| 59 |
|
| 60 |
This creates a wheel named ``package-1.0.0-123-py3-none-any.whl``. |
| 61 |
|
| 62 |
Compiler selection |
| 63 |
================== |
| 64 |
|
| 65 |
To specify a compiler on Windows: |
| 66 |
|
| 67 |
.. code-block:: console |
| 68 |
|
| 69 |
$ python -m build \ |
| 70 |
-C--build-option=build_ext \ |
| 71 |
-C--build-option=--compiler \ |
| 72 |
-C--build-option=mingw32 |
| 73 |
|
| 74 |
.. note:: |
| 75 |
|
| 76 |
Each argument must be a separate ``-C`` flag. Setuptools processes these as separate command-line arguments. |
| 77 |
|
| 78 |
Getting help |
| 79 |
============ |
| 80 |
|
| 81 |
To see available setuptools build options: |
| 82 |
|
| 83 |
.. code-block:: console |
| 84 |
|
| 85 |
$ python -m build -C--build-option=--help |
| 86 |
|
| 87 |
******************* |
| 88 |
scikit-build-core |
| 89 |
******************* |
| 90 |
|
| 91 |
scikit-build-core uses a more intuitive dotted syntax. |
| 92 |
|
| 93 |
CMake options |
| 94 |
============= |
| 95 |
|
| 96 |
.. code-block:: console |
| 97 |
|
| 98 |
$ python -m build \ |
| 99 |
-Ccmake.define.BUILD_TESTING=OFF \ |
| 100 |
-Ccmake.define.CMAKE_BUILD_TYPE=Release |
| 101 |
|
| 102 |
Logging |
| 103 |
======= |
| 104 |
|
| 105 |
.. code-block:: console |
| 106 |
|
| 107 |
$ python -m build -Clogging.level=INFO |
| 108 |
|
| 109 |
Install target |
| 110 |
============== |
| 111 |
|
| 112 |
.. code-block:: console |
| 113 |
|
| 114 |
$ python -m build -Cinstall.strip=false |
| 115 |
|
| 116 |
Multiple options: |
| 117 |
|
| 118 |
.. code-block:: console |
| 119 |
|
| 120 |
$ python -m build \ |
| 121 |
-Clogging.level=DEBUG \ |
| 122 |
-Ccmake.define.USE_CUDA=ON \ |
| 123 |
-Cinstall.components=runtime |
| 124 |
|
| 125 |
************** |
| 126 |
meson-python |
| 127 |
************** |
| 128 |
|
| 129 |
Meson-python passes options directly to meson. |
| 130 |
|
| 131 |
Setup options |
| 132 |
============= |
| 133 |
|
| 134 |
.. code-block:: console |
| 135 |
|
| 136 |
$ python -m build -Csetup-args=-Doption=value |
| 137 |
|
| 138 |
Compile options |
| 139 |
=============== |
| 140 |
|
| 141 |
.. code-block:: console |
| 142 |
|
| 143 |
$ python -m build \ |
| 144 |
-Csetup-args=-Dbuildtype=release \ |
| 145 |
-Csetup-args=-Db_ndebug=true |
| 146 |
|
| 147 |
*********** |
| 148 |
hatchling |
| 149 |
*********** |
| 150 |
|
| 151 |
Hatchling supports various build options. |
| 152 |
|
| 153 |
Reproducible builds |
| 154 |
=================== |
| 155 |
|
| 156 |
.. code-block:: console |
| 157 |
|
| 158 |
$ python -m build -Creproducible=true |
| 159 |
|
| 160 |
Shared data |
| 161 |
=========== |
| 162 |
|
| 163 |
.. code-block:: console |
| 164 |
|
| 165 |
$ python -m build -Cshared-data=/custom/path |
| 166 |
|
| 167 |
*********** |
| 168 |
flit-core |
| 169 |
*********** |
| 170 |
|
| 171 |
Flit-core has minimal configuration options as it focuses on simplicity. |
| 172 |
|
| 173 |
************* |
| 174 |
poetry-core |
| 175 |
************* |
| 176 |
|
| 177 |
Poetry-core currently does not support configuration settings via the command line. |
| 178 |
|
| 179 |
************************* |
| 180 |
Using ``--config-json`` |
| 181 |
************************* |
| 182 |
|
| 183 |
For complex nested configuration, use ``--config-json`` instead: |
| 184 |
|
| 185 |
.. code-block:: console |
| 186 |
|
| 187 |
$ python -m build --config-json='{"cmake": {"define": {"VAR1": "value1", "VAR2": "value2"}}}' |
| 188 |
|
| 189 |
This is particularly useful in CI/CD scripts where configuration can be generated programmatically. |
| 190 |
|
| 191 |
.. note:: |
| 192 |
|
| 193 |
``--config-setting`` and ``--config-json`` cannot be used together. |
| 194 |
|
| 195 |
*************** |
| 196 |
Common Issues |
| 197 |
*************** |
| 198 |
|
| 199 |
Options starting with hyphens |
| 200 |
============================= |
| 201 |
|
| 202 |
If your option starts with a hyphen, you must use the ``=`` syntax to prevent build from interpreting it as its own |
| 203 |
flag: |
| 204 |
|
| 205 |
.. code-block:: console |
| 206 |
|
| 207 |
$ python -m build -C=--my-setting |
| 208 |
|
| 209 |
Not ``-C --my-setting`` which would fail. |
| 210 |
|
| 211 |
Backend not recognizing options |
| 212 |
=============================== |
| 213 |
|
| 214 |
If your backend doesn't recognize an option: |
| 215 |
|
| 216 |
1. Check your backend's documentation for the correct syntax |
| 217 |
2. Verify you're using the latest version of the backend |
| 218 |
3. Some backends only support certain options in newer versions |
| 219 |
|
| 220 |
******************************* |
| 221 |
Finding backend documentation |
| 222 |
******************************* |
| 223 |
|
| 224 |
- `Setuptools <https://setuptools.pypa.io/>`_ |
| 225 |
- `scikit-build-core <https://scikit-build-core.readthedocs.io/>`_ |
| 226 |
- `meson-python <https://meson-python.readthedocs.io/>`_ |
| 227 |
- `hatchling <https://hatch.pypa.io/latest/config/build/>`_ |
| 228 |
- `flit-core <https://flit.pypa.io/>`_ |
| 229 |
- `poetry-core <https://python-poetry.org/docs/>`_ |
| 230 |
- `pdm-backend <https://pdm-backend.fming.dev/>`_ |
| 231 |
|
| 232 |
********** |
| 233 |
See also |
| 234 |
********** |
| 235 |
|
| 236 |
- :doc:`basic-usage` for general build commands |
| 237 |
- :doc:`../reference/cli` for all command-line options |
| 238 |
- :doc:`../explanation/build-backends` to understand how backends work |