@@ -14,13 +14,13 @@ We will give you a quick introduction to what steps releasing a Python package
1414consists of, and walk you through them to get started.
1515
1616
17- Create a Meson _ project
18- =======================
17+ Creating a Meson project
18+ ========================
1919
2020To 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.
2424
2525
2626The module
@@ -87,8 +87,7 @@ we want it to build, and how to do it.
8787
8888 project('purelib-and-platlib', 'c')
8989
90- py_mod = import('python')
91- py = py_mod.find_installation(pure: false)
90+ py = import('python').find_installation(pure: false)
9291
9392 py.extension_module(
9493 'our_first_module',
@@ -97,16 +96,16 @@ we want it to build, and how to do it.
9796 )
9897
9998
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 ``
101100module. We make sure to install it, by passing ``install: true `` to
102101``extension_module ``, as ``meson-python `` will only include in the binary
103102distribution artifacts targets that Meson would install onto system. Having non
104103installed targets allows you to build targets for use within the build, or for
105104tests.
106105
107106
108- Configure our Python package
109- ============================
107+ Configuring our Python package
108+ ==============================
110109
111110Now, we need to tell Python packaging tooling what build backend to use to build
112111our package. We do this by creating a ``build-system `` section in the
@@ -115,12 +114,10 @@ tooling.
115114
116115Inside the ``build-system `` section, we need to define two keys,
117116``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
120119installed 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 ``).
124121
125122.. code-block :: toml
126123 :caption: pyproject.toml
@@ -129,11 +126,9 @@ other dependencies you might need (eg. ``Cython``), in our case it's just
129126 build-backend = 'mesonpy'
130127 requires = ['meson-python']
131128
132-
133129 After we specify which backend to use, we'll want to define the package
134130metadata. This is done in the ``project `` section, and the format is pretty
135- self-explanatory by looking at our example.
136-
131+ self-explanatory:
137132
138133.. code-block :: toml
139134 :caption: pyproject.toml
@@ -151,35 +146,20 @@ self-explanatory by looking at our example.
151146 {name = 'Bowsette Koopa', email = 'bowsette@example.com'},
152147 ]
153148
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-
162149 .. admonition :: Declaring project metadata
163150 :class: seealso
164151
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.
174155
175156
176157Testing the project
177158-------------------
178159
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.
182161
162+ We will install it with pip _:
183163
184164.. code-block :: console
185165
@@ -214,23 +194,22 @@ commonly referred to as *sdists*, and `binary distributions`_, which use a
214194custom format named *wheel *, so they're generally referred to as *wheels *.
215195
216196
217- What are the roles of *sdists * and *wheels *
218- -------------------------------------------
219-
197+ What are the roles of sdists and wheels?
198+ ----------------------------------------
220199
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.
224203
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
226205both the platform and the Python version [#stable-abi ]_.
227206
228- While distributing * wheels * is not mandatory, they make the
207+ While distributing wheels is not mandatory, they make the
229208user 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 .
234213
235214
236215.. [#pure-wheels ]
@@ -249,32 +228,26 @@ dependencies and going through the likely expensive build.
249228 Building the project
250229--------------------
251230
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+
252235To generate the distribution artifacts we will use the `pypa/build `_ tool. It
253236will create a temporary virtual environment, install all the required build
254237dependencies, and ask ``meson-python `` to build the artifacts.
255238
256-
257239.. code-block :: console
258240
259241 $ pip install build
260242 $ python -m build
261243
262-
263244 If the build succeeded, you'll have the binary artifacts in the ``dist `` folder.
264245
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-
273246.. admonition :: Building wheels for multiple platforms
274247 :class: tip
275248
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
278251 project contains native code, it will be specific for our machine's platform.
279252
280253 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_.
314287 You can find more about how to use the `Test PyPI `_ in
315288 `its PyPA documentation page <https://packaging.python.org/en/latest/guides/using-testpypi/ >`_.
316289
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-
325290After this, your package should be available on PyPI _, and installable with
326291pip _.
327292
@@ -332,8 +297,8 @@ pip_.
332297
333298
334299
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
337302.. _PyPA documentation on project metadata : https://packaging.python.org/en/latest/specifications/declaring-project-metadata/
338303.. _source distributions : https://packaging.python.org/en/latest/specifications/source-distribution-format/
339304.. _binary distributions : https://packaging.python.org/en/latest/specifications/binary-distribution-format/
0 commit comments