Microprocessors
Programs

Hacking Raspberry Pi 4 with Yocto: Python Packages Not in Meta-OpenEmbedded

11.0 Creating Recipes for Python Packages that Are Not in Meta-OpenEmbedded

In the previous section, we were able to take advantage of the recipes for numpy and paho-mqtt in OE-Core and Meta-OpenEmbedded. But what if we can't find a recipe for the Python package we want?

In this chapter, we'll create a recipe for the pythemis package. You can search around in your meta-openembedded and poky directories for this package. You won't find it. The good news is that we can take advantage of the fact that pythemis is available on PyPI. The even better news is that you can use the techniques in this chapter for any of the packages on PyPI.

11.1 Creating a Recipe for pythemis

We're going to make a recipe for pythemis in our meta-rpilinux layer. First of all, let's take a look at the pythemis page on PyPI. At the time of writing, we see this at the top:


The current version is 0.12.0, so we should use that in the recipe name to be consistent with the conventions used by bitbake. Specifically, we should use [package name]_[version number].bb. This is very important! If we don't use the underscore between the pacakage name and the version number, all hope will be lost. Let's create the recipe file pythemis_0.12.0.bb like so:

$ cd ~/Yocto/meta-rpilinux 
$ mkdir meta-python
$ cd meta-python
$ mkdir pythemis
$ touch pythemis_0.12.0.bb

The contents of the pythemis_0.12.0.bb file should be the following:

SUMMARY = "The pythemis data security package"
    
HOMEPAGE = "https://www.cossacklabs.com/"
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://LICENSE;md5=8cc789b082b3d97e1ccc5261f8594d3f"

SRC_URI[md5sum] = "96ed0d3e8b3ed95b4b2acd8c856a87a6"
SRC_URI[sha256sum] = "76932045a054cc49ccaa6c81036b1aeb5ec0224b8f8f91133f5ee534a11b29b3"

PYPI_PACKAGE = "pythemis"   

inherit pypi setuptools3

Our recipes for a PyPI package should look like the above. Here's a description of what each one of these parameters is and how we populate them based upon the contents of the pythemis package. If you want to follow along, you should download and unzip the pythemis source.

  • SUMMARY - This is some text that describes what the package is all about. I was pretty brief in my synopsis, but I don't think there's any reason to go into great detail here.

  • HOMEPAGE - I chose to use the homepage listed on the PyPI page for pythemis.

  • LICENSE - The LICENSE file in the source says it uses the Apache Version 2.0 license. We should use the poky/meta/conf/licenses.conf file to figure out what string we need to use for this license. "Apache-2.0" is the match.

  • LIC_FILES_CHKSUM - This one is tricky. The first part file://LICENSE indicates the relative path within the source directory for pythemis where the LICENSE file lives. The second part is the md5 checksum of that file, which we can find using the command md5 LICENSE when we're in the source directory that we downloaded. The previous command returns the string 8cc789b082b3d97e1ccc5261f8594d3f. We need to get this right or bitbake won't build it.

  • SRC_URI[md5sum] - We can either run md5 pythemis-0.12.0.tar.gz on the compressed source, or we can click on "Download Files" and then click "View" under "Hashes" from the PyPI page. We need to get this right or bitbake won't build it.

  • SRC_URI[sha256sum] - We can either run sha -a 256 pythemis-0.12.0.tar.gz on the compressed source, or we can click on "Download Files" and then click "View" under "Hashes" from the PyPI page. We need to get this right or bitbake won't build it.

  • PYPI_PACKAGE - This tells bitbake what the name of the package is in PyPI.

  • inherit pypi setuptools3 - This tells bitbake that we need pypi and setuptools3 in order to properly recipe. This is crucial for the recipe to work.

If you want to test out whether or not the recipe was added properly, you can do a quick test like so:

$ cd ~/Yocto/poky
$ source oe-init-build-env
$ bitbake pythemis

If everything went ok, you should pythemis in your build directory. Next we'll include it in our root filesystem.

11.2 Adding pythemis to Our Build

I'm betting that you already know how to include pythemis in our rootfs by now. All we have to do is add it to our IMAGE_INSTALL directive in rpilinux-image.bb like so IMAGE_INSTALL += "python3 python3-numpy python3-paho-mqtt python3-pyzmq pythemis". If we bitbake rpilinux-image, we should have it in our root filesystem.



← Previous    ...    Next →