@@ -74,178 +74,11 @@ when decision is needed.
74
74
*(a)abort *
75
75
Abort pip and return non-zero exit status.
76
76
77
- .. _`build-interface` :
78
-
79
77
80
78
Build System Interface
81
79
======================
82
80
83
- pip builds packages by invoking the build system. By default, builds will use
84
- ``setuptools ``, but if a project specifies a different build system using a
85
- ``pyproject.toml `` file, as per :pep: `517 `, pip will use that instead. As well
86
- as package building, the build system is also invoked to install packages
87
- direct from source. This is handled by invoking the build system to build a
88
- wheel, and then installing from that wheel. The built wheel is cached locally
89
- by pip to avoid repeated identical builds.
90
-
91
- The current interface to the build system is via the ``setup.py `` command line
92
- script - all build actions are defined in terms of the specific ``setup.py ``
93
- command line that will be run to invoke the required action.
94
-
95
- Setuptools Injection
96
- ~~~~~~~~~~~~~~~~~~~~
97
-
98
- When :pep: `517 ` is not used, the supported build system is ``setuptools ``.
99
- However, not all packages use ``setuptools `` in their build scripts. To support
100
- projects that use "pure ``distutils ``", pip injects ``setuptools `` into
101
- ``sys.modules `` before invoking ``setup.py ``. The injection should be
102
- transparent to ``distutils ``-based projects, but 3rd party build tools wishing
103
- to provide a ``setup.py `` emulating the commands pip requires may need to be
104
- aware that it takes place.
105
-
106
- Projects using :pep: `517 ` *must * explicitly use setuptools - pip does not do
107
- the above injection process in this case.
108
-
109
- Build System Output
110
- ~~~~~~~~~~~~~~~~~~~
111
-
112
- Any output produced by the build system will be read by pip (for display to the
113
- user if requested). In order to correctly read the build system output, pip
114
- requires that the output is written in a well-defined encoding, specifically
115
- the encoding the user has configured for text output (which can be obtained in
116
- Python using ``locale.getpreferredencoding ``). If the configured encoding is
117
- ASCII, pip assumes UTF-8 (to account for the behaviour of some Unix systems).
118
-
119
- Build systems should ensure that any tools they invoke (compilers, etc) produce
120
- output in the correct encoding. In practice - and in particular on Windows,
121
- where tools are inconsistent in their use of the "OEM" and "ANSI" codepages -
122
- this may not always be possible. pip will therefore attempt to recover cleanly
123
- if presented with incorrectly encoded build tool output, by translating
124
- unexpected byte sequences to Python-style hexadecimal escape sequences
125
- (``"\x80\xff" ``, etc). However, it is still possible for output to be displayed
126
- using an incorrect encoding (mojibake).
127
-
128
- Under :pep: `517 `, handling of build tool output is the backend's responsibility,
129
- and pip simply displays the output produced by the backend. (Backends, however,
130
- will likely still have to address the issues described above).
131
-
132
- PEP 517 and 518 Support
133
- ~~~~~~~~~~~~~~~~~~~~~~~
134
-
135
- As of version 10.0, pip supports projects declaring dependencies that are
136
- required at install time using a ``pyproject.toml `` file, in the form described
137
- in :pep: `518 `. When building a project, pip will install the required
138
- dependencies locally, and make them available to the build process.
139
- Furthermore, from version 19.0 onwards, pip supports projects specifying the
140
- build backend they use in ``pyproject.toml ``, in the form described in
141
- :pep: `517 `.
142
-
143
- When making build requirements available, pip does so in an *isolated
144
- environment *. That is, pip does not install those requirements into the user's
145
- ``site-packages ``, but rather installs them in a temporary directory which it
146
- adds to the user's ``sys.path `` for the duration of the build. This ensures
147
- that build requirements are handled independently of the user's runtime
148
- environment. For example, a project that needs a recent version of setuptools
149
- to build can still be installed, even if the user has an older version
150
- installed (and without silently replacing that version).
151
-
152
- In certain cases, projects (or redistributors) may have workflows that
153
- explicitly manage the build environment. For such workflows, build isolation
154
- can be problematic. If this is the case, pip provides a
155
- ``--no-build-isolation `` flag to disable build isolation. Users supplying this
156
- flag are responsible for ensuring the build environment is managed
157
- appropriately (including ensuring that all required build dependencies are
158
- installed).
159
-
160
- By default, pip will continue to use the legacy (direct ``setup.py `` execution
161
- based) build processing for projects that do not have a ``pyproject.toml `` file.
162
- Projects with a ``pyproject.toml `` file will use a :pep: `517 ` backend. Projects
163
- with a ``pyproject.toml `` file, but which don't have a ``build-system `` section,
164
- will be assumed to have the following backend settings::
165
-
166
- [build-system]
167
- requires = ["setuptools>=40.8.0", "wheel"]
168
- build-backend = "setuptools.build_meta:__legacy__"
169
-
170
- .. note ::
171
-
172
- ``setuptools `` 40.8.0 is the first version of setuptools that offers a
173
- :pep: `517 ` backend that closely mimics directly executing ``setup.py ``.
174
-
175
- If a project has ``[build-system] ``, but no ``build-backend ``, pip will also use
176
- ``setuptools.build_meta:__legacy__ ``, but will expect the project requirements
177
- to include ``setuptools `` and ``wheel `` (and will report an error if the
178
- installed version of ``setuptools `` is not recent enough).
179
-
180
- If a user wants to explicitly request :pep: `517 ` handling even though a project
181
- doesn't have a ``pyproject.toml `` file, this can be done using the
182
- ``--use-pep517 `` command line option. Similarly, to request legacy processing
183
- even though ``pyproject.toml `` is present, the ``--no-use-pep517 `` option is
184
- available (although obviously it is an error to choose ``--no-use-pep517 `` if
185
- the project has no ``setup.py ``, or explicitly requests a build backend). As
186
- with other command line flags, pip recognises the ``PIP_USE_PEP517 ``
187
- environment veriable and a ``use-pep517 `` config file option (set to true or
188
- false) to set this option globally. Note that overriding pip's choice of
189
- whether to use :pep: `517 ` processing in this way does *not * affect whether pip
190
- will use an isolated build environment (which is controlled via
191
- ``--no-build-isolation `` as noted above).
192
-
193
- Except in the case noted above (projects with no :pep: `518 ` ``[build-system] ``
194
- section in ``pyproject.toml ``), pip will never implicitly install a build
195
- system. Projects **must ** ensure that the correct build system is listed in
196
- their ``requires `` list (this applies even if pip assumes that the
197
- ``setuptools `` backend is being used, as noted above).
198
-
199
- .. _pep-518-limitations :
200
-
201
- **Historical Limitations **:
202
-
203
- * ``pip<18.0 ``: only supports installing build requirements from wheels, and
204
- does not support the use of environment markers and extras (only version
205
- specifiers are respected).
206
-
207
- * ``pip<18.1 ``: build dependencies using .pth files are not properly supported;
208
- as a result namespace packages do not work under Python 3.2 and earlier.
209
-
210
- Future Developments
211
- ~~~~~~~~~~~~~~~~~~~
212
-
213
- :pep: `426 ` notes that the intention is to add hooks to project metadata in
214
- version 2.1 of the metadata spec, to explicitly define how to build a project
215
- from its source. Once this version of the metadata spec is final, pip will
216
- migrate to using that interface. At that point, the ``setup.py `` interface
217
- documented here will be retained solely for legacy purposes, until projects
218
- have migrated.
219
-
220
- Specifically, applications should *not * expect to rely on there being any form
221
- of backward compatibility guarantees around the ``setup.py `` interface.
222
-
223
-
224
- Build Options
225
- ~~~~~~~~~~~~~
226
-
227
- The ``--global-option `` and ``--build-option `` arguments to the ``pip install ``
228
- and ``pip wheel `` inject additional arguments into the ``setup.py `` command
229
- (``--build-option `` is only available in ``pip wheel ``). These arguments are
230
- included in the command as follows:
231
-
232
- .. tab :: Unix/macOS
233
-
234
- .. code-block :: console
235
-
236
- python setup.py <global_options> BUILD COMMAND <build_options>
237
-
238
- .. tab :: Windows
239
-
240
- .. code-block :: shell
241
-
242
- py setup.py < global_options> BUILD COMMAND < build_options>
243
-
244
- The options are passed unmodified, and presently offer direct access to the
245
- distutils command line. Use of ``--global-option `` and ``--build-option ``
246
- should be considered as build system dependent, and may not be supported in the
247
- current form if support for alternative build systems is added to pip.
248
-
81
+ This is now covered in :doc: `../reference/build-system/index `.
249
82
250
83
.. _`General Options` :
251
84
0 commit comments