Skip to content

Commit 6af08d0

Browse files
committed
📝 Document PyProjectRecipe usage
Add PyProjectRecipe guidance for modern pyproject.toml packages, including the wheel-oriented build flow and notes on dependency, host build, patch, and environment customization, refs kivy#3326
1 parent a608f59 commit 6af08d0

1 file changed

Lines changed: 46 additions & 7 deletions

File tree

doc/source/recipes.rst

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,11 @@ This is the core of what's necessary to write a recipe, but has not
123123
covered any of the details of how one actually writes code to compile
124124
for android. This is covered in the next sections, including the
125125
`standard mechanisms <standard_mechanisms_>`_ used as part of the
126-
build, and the details of specific recipe classes for Python, Cython,
127-
and some generic compiled recipes. If your module is one of the
128-
latter, you should use these later classes rather than reimplementing
129-
the functionality from scratch.
126+
build, and the details of specific recipe classes for modern Python
127+
packages, older setup.py-based packages, Cython, and some generic
128+
compiled recipes. If your module is one of the latter, you should use
129+
these later classes rather than reimplementing the functionality from
130+
scratch.
130131

131132
.. _standard_mechanisms:
132133

@@ -310,6 +311,10 @@ For reference, the code that accomplishes this is the following::
310311
This combines techniques and tools from the above documentation to
311312
create a generic mechanism for all Python modules.
312313

314+
For Python packages that use ``pyproject.toml``, you should normally use
315+
``PyProjectRecipe`` instead. ``PythonRecipe`` is based on the older
316+
``setup.py install`` flow.
317+
313318
.. note:: The hostpython is the path to the Python binary that should
314319
be used for any kind of installation. You *must* run Python
315320
in a similar way if you need to do so in any of your own
@@ -380,6 +385,43 @@ patching to remove this import or make it fail quietly.
380385
Other than this, these methods follow the techniques in the above
381386
documentation to make a generic recipe for most cython based modules.
382387

388+
Using a PyProjectRecipe
389+
-----------------------
390+
391+
For modern Python packages that contain ``pyproject.toml``, you should
392+
normally use ``PyProjectRecipe``. It builds and installs packages as
393+
wheels, which matches current Python packaging tools more closely than
394+
the older ``setup.py install`` flow.
395+
396+
For instance::
397+
398+
from pythonforandroid.recipe import PyProjectRecipe
399+
400+
class ExampleRecipe(PyProjectRecipe):
401+
version = '1.2.3'
402+
url = 'https://example.com/example-{version}.tar.gz'
403+
depends = ['pycparser', 'libffi']
404+
405+
recipe = ExampleRecipe()
406+
407+
You do not need to include ``python3`` in ``depends``; even when a recipe
408+
overrides ``depends``, ``PythonRecipe`` adds the ``python3`` dependency.
409+
410+
The base class uses a wheel-oriented build and install flow. It can use
411+
a compatible prebuilt Android wheel when that path is enabled and a
412+
matching wheel is available. Otherwise, it installs the host build
413+
requirements, runs ``python -m build --wheel``, applies Android platform
414+
tags to the built wheel, optionally copies the wheel to configured
415+
wheel-save directories, and installs the selected wheel into the target
416+
Python install directory.
417+
418+
You may still need to add normal recipe metadata such as ``depends`` for
419+
libraries or Python packages that must be built first. Packages with
420+
extra host-side build requirements can add ``hostpython_prerequisites``.
421+
Packages that need Android-specific changes may still need patches or a
422+
``get_recipe_env()`` override to adjust compiler flags, include paths, or
423+
other build environment variables.
424+
383425
Using a CompiledComponentsPythonRecipe
384426
--------------------------------------
385427

@@ -506,6 +548,3 @@ how to create your own Recipe subclass.
506548
.. autoclass:: toolchain.Recipe
507549
:members:
508550
:member-order: bysource
509-
510-
511-

0 commit comments

Comments
 (0)