To build a Python hello world example application with setuptools, we would use a meta-custom/recipes-python/python-helloworld/python-helloworld_1.0.bb recipe, as follows:
DESCRIPTION = "Simple Python setuptools hello world application" SECTION = "examples" LICENSE = "MIT" LIC_FILES_CHKSUM =
"file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4
f302" SRC_URI = "file://setup.py file://python-helloworld.py file://helloworld/__init__.py file://helloworld/main.py" S = "${WORKDIR}" inherit setuptools do_install_append () { install -d ${D}${bindir} install -m 0755 python-helloworld.py ${D}${bindir} }
To create an example hello world package, we create the directory structure shown in the following screenshot:
Here is the code for the same directory structure:
$ mkdir -p meta-custom/recipes-python/python-helloworld/python-
helloworld-1.0/helloworld/
$ touch meta-custom/recipes-python/python-helloworld/python-
helloworld-1.0/helloworld/__init__.py
You will also need to create the following meta-custom/recipes-python/python-helloworld/python-helloworld-1.0/setup.py Python setup file:
import sys from setuptools import setup setup( name = "helloworld", version = "0.1", packages=["helloworld"], author="Alex Gonzalez", author_email = "[email protected]", description = "Hello World packaging example", license = "MIT", keywords= "example", url = "", )
You will also need the meta-custom/recipes-python/python-helloworld/python-helloworld-1.0/helloworld/main.py python file:
import sys def main(argv=None): if argv is None: argv = sys.argv print "Hello world!" return 0
And finally a meta-custom/recipes-python/python-helloworld/python-helloworld-1.0/python-helloworld.py test script that makes use of the module:
#!/usr/bin/env python import sys import helloworld.main if __name__ == '__main__': sys.exit(helloworld.main.main())
We can then add it to our image with the following addition to the conf/local.conf or image file:
IMAGE_INSTALL_append = " python-helloworld"
Then, we can build it using the following:
$ cd /opt/yocto/fsl-community-bsp/
$ source setup-environment wandboard
$ bitbake core-image-minimal
Once programmed and booted, we can test the module by running the example script:
# /usr/bin/python-helloworld.py
Hello world!