@@ -14,13 +14,13 @@ We will give you a quick introduction to what steps releasing a Python package
14
14
consists of, and walk you through them to get started.
15
15
16
16
17
- Create a Meson _ project
18
- =======================
17
+ Creating a Meson project
18
+ ========================
19
19
20
20
To get started, we need a project to publish. As ``meson-python `` is built on
21
- top of Meson , we will create a really simple Meson project. You may already have
22
- a Meson project you wish to publish, in that case, you can simply skip this
23
- step.
21
+ top of Meson _ , we will create a really simple Meson project. You may already
22
+ have a Meson project you wish to publish, in that case, you can simply skip
23
+ this step.
24
24
25
25
26
26
The module
@@ -87,8 +87,7 @@ we want it to build, and how to do it.
87
87
88
88
project('purelib-and-platlib', 'c')
89
89
90
- py_mod = import('python')
91
- py = py_mod.find_installation(pure: false)
90
+ py = import('python').find_installation(pure: false)
92
91
93
92
py.extension_module(
94
93
'our_first_module',
@@ -97,16 +96,16 @@ we want it to build, and how to do it.
97
96
)
98
97
99
98
100
- Here, we use the ` Meson Python module `_ to build our ``our_first_module ``
99
+ Here, we use Meson's ` Python module `_ to build our ``our_first_module ``
101
100
module. We make sure to install it, by passing ``install: true `` to
102
101
``extension_module ``, as ``meson-python `` will only include in the binary
103
102
distribution artifacts targets that Meson would install onto system. Having non
104
103
installed targets allows you to build targets for use within the build, or for
105
104
tests.
106
105
107
106
108
- Configure our Python package
109
- ============================
107
+ Configuring our Python package
108
+ ==============================
110
109
111
110
Now, we need to tell Python packaging tooling what build backend to use to build
112
111
our package. We do this by creating a ``build-system `` section in the
@@ -115,12 +114,10 @@ tooling.
115
114
116
115
Inside the ``build-system `` section, we need to define two keys,
117
116
``build-backend `` and ``requires ``. ``build-backend `` defines which build
118
- backend should be used for the project, in meson-python it should always have
119
- the value of `` mesonpy ``. ``requires `` lets us specify which packages need to be
117
+ backend should be used for the project - set it to `` 'mesonpy' `` to use
118
+ `` meson-python ``. ``requires `` lets us specify which packages need to be
120
119
installed for the build process, it should include ``meson-python `` and any
121
- other dependencies you might need (eg. ``Cython ``), in our case it's just
122
- ``meson-python ``.
123
-
120
+ other dependencies you might need (e.g., ``Cython ``).
124
121
125
122
.. code-block :: toml
126
123
:caption: pyproject.toml
@@ -129,11 +126,9 @@ other dependencies you might need (eg. ``Cython``), in our case it's just
129
126
build-backend = 'mesonpy'
130
127
requires = ['meson-python']
131
128
132
-
133
129
After we specify which backend to use, we'll want to define the package
134
130
metadata. This is done in the ``project `` section, and the format is pretty
135
- self-explanatory by looking at our example.
136
-
131
+ self-explanatory:
137
132
138
133
.. code-block :: toml
139
134
:caption: pyproject.toml
@@ -151,35 +146,20 @@ self-explanatory by looking at our example.
151
146
{name = 'Bowsette Koopa', email = '[email protected] '},
152
147
]
153
148
154
-
155
- .. admonition :: Adding dependencies
156
- :class: seealso
157
-
158
- If you need to add dependencies to the project metadata, you can check our
159
- :ref: `how-to-guides-add-dependencies ` guide.
160
-
161
-
162
149
.. admonition :: Declaring project metadata
163
150
:class: seealso
164
151
165
- Our example doesn't make use of all the fields available, so we recommend you
166
- check out the `PyPA documentation on project metadata `_.
167
-
168
-
169
- .. admonition :: Writing TOML
170
- :class: seealso
171
-
172
- If you are not familiar with the TOML configuration language or need some
173
- help, be sure to check out `toml.io <https://toml.io >`_.
152
+ Our example doesn't make use of all the fields available in the ``[project] ``
153
+ section. Check out the `PyPA documentation on project metadata `_ for more
154
+ examples and details.
174
155
175
156
176
157
Testing the project
177
158
-------------------
178
159
179
- Now we should have a valid Python project, let's test it.
180
-
181
- We will install it with pip _
160
+ Now we should have a valid Python project, so let's test it.
182
161
162
+ We will install it with pip _:
183
163
184
164
.. code-block :: console
185
165
@@ -214,23 +194,22 @@ commonly referred to as *sdists*, and `binary distributions`_, which use a
214
194
custom format named *wheel *, so they're generally referred to as *wheels *.
215
195
216
196
217
- What are the roles of *sdists * and *wheels *
218
- -------------------------------------------
219
-
197
+ What are the roles of sdists and wheels?
198
+ ----------------------------------------
220
199
221
- As you might have figured out by the name, * sdists * contain the source code of
222
- the project, and * wheels * contain a compiled [#pure-wheels ]_ version of the
223
- project, ready to be copied to the file- system.
200
+ As you might have figured out by the name, sdists contain the source code of
201
+ the project, and wheels contain a compiled [#pure-wheels ]_ version of the
202
+ project, ready to be copied to the file system.
224
203
225
- If your project uses Python extension modules, your * wheels * will be specific to
204
+ If your project uses Python extension modules, your wheels will be specific to
226
205
both the platform and the Python version [#stable-abi ]_.
227
206
228
- While distributing * wheels * is not mandatory, they make the
207
+ While distributing wheels is not mandatory, they make the
229
208
user experience much nicer. Unless you have any reason not to, we highly
230
- recommend you distribute * wheels * for at least the most common systems. When
231
- * wheels * are not available for a system, the project can still be installed, be
232
- it needs to be build from the * sdist * , which involves fetching all the build
233
- dependencies and going through the likely expensive build.
209
+ recommend you distribute wheels for at least the most common systems. When
210
+ wheels are not available for a system, the project can still be installed, be
211
+ it needs to be build from the sdist, which involves fetching all the build
212
+ dependencies and going through the likely expensive build process .
234
213
235
214
236
215
.. [#pure-wheels ]
@@ -249,32 +228,26 @@ dependencies and going through the likely expensive build.
249
228
Building the project
250
229
--------------------
251
230
231
+ Before continuing, ensure you have committed the three files we created so far
232
+ to your Git repository - ``meson-python `` will only take into account the files
233
+ that Git knows about.
234
+
252
235
To generate the distribution artifacts we will use the `pypa/build `_ tool. It
253
236
will create a temporary virtual environment, install all the required build
254
237
dependencies, and ask ``meson-python `` to build the artifacts.
255
238
256
-
257
239
.. code-block :: console
258
240
259
241
$ pip install build
260
242
$ python -m build
261
243
262
-
263
244
If the build succeeded, you'll have the binary artifacts in the ``dist `` folder.
264
245
265
-
266
- .. admonition :: Check the pypa/build documentation
267
- :class: seealso
268
-
269
- To learn more about `pypa/build `_, you can check
270
- `their documentation <https://pypa-build.readthedocs.io/ >`__.
271
-
272
-
273
246
.. admonition :: Building wheels for multiple platforms
274
247
:class: tip
275
248
276
- If our project only contains pure-Python (``.py ``) code, the * wheel * we just
277
- built will work on all platforms, as it is a * pure * wheel, but if the
249
+ If our project only contains pure-Python (``.py ``) code, the wheel we just
250
+ built will work on all platforms, as it is a pure wheel, but if the
278
251
project contains native code, it will be specific for our machine's platform.
279
252
280
253
When releasing, you'll usually want to build for at least most of the other
@@ -314,14 +287,6 @@ For this, we will use Twine_.
314
287
You can find more about how to use the `Test PyPI `_ in
315
288
`its PyPA documentation page <https://packaging.python.org/en/latest/guides/using-testpypi/ >`_.
316
289
317
-
318
- .. admonition :: Check the twine documentation
319
- :class: seealso
320
-
321
- To learn more about Twine _, you can check
322
- `their documentation <https://twine.readthedocs.io/ >`__.
323
-
324
-
325
290
After this, your package should be available on PyPI _, and installable with
326
291
pip _.
327
292
@@ -332,8 +297,8 @@ pip_.
332
297
333
298
334
299
335
- .. _Meson : https://github .com/mesonbuild/meson
336
- .. _ Meson Python module : https://mesonbuild.com/Python-module.html
300
+ .. _Meson : https://mesonbuild .com/
301
+ .. _ Python module : https://mesonbuild.com/Python-module.html
337
302
.. _PyPA documentation on project metadata : https://packaging.python.org/en/latest/specifications/declaring-project-metadata/
338
303
.. _source distributions : https://packaging.python.org/en/latest/specifications/source-distribution-format/
339
304
.. _binary distributions : https://packaging.python.org/en/latest/specifications/binary-distribution-format/
0 commit comments