在yocto中为python应用程序编写食谱

Sha*_*sai 6 embedded-linux python-3.x yocto

我有一个简单的python应用程序,它可以:

  1. 从GPS获取信息
  2. 解析信息
  3. 将其存储在InfluxDB中

包装要求:

certifi==2018.4.16
chardet==3.0.4
idna==2.6 
influxdb==5.0.0
pynmea2==1.12.0 
pyserial==3.4
python-dateutil==2.7.3
pytz==2018.4
requests==2.18.4
six==1.11.0
urllib3==1.22          
Run Code Online (Sandbox Code Playgroud)

上面是通过使用以下命令生成的:

pip3 install pynmea2 pyserial influxdb

OpenEmbedded Layers Index我已经找到pyserialPython3包中。这暗示着我可能需要做的事情pip3 install pynmea2 influxdb

在考虑所有上述pip依赖关系的情况下,如何继续编写应用程序的配方?

我没有找到有关编写python应用程序食谱的任何教程。(相反,Node应用程序确实在yoctoWiki页面上有一些指导。

在检查meta-python层中的一些配方后,我发现了一些.inc文件,但不确定如何处理

Sha*_*sai 7

为不可用的python应用程序创建食谱

由于influxdb-pythonpynmea2不能作为标准python食谱使用,因此我首先使用为其创建了食谱devtool

脚步

  1. 用于devtool添加influxdb-python

    devtool add influxdb-python https://github.com/influxdata/influxdb-python/archive/v5.2.0.tar.gz

  2. 用于devtool添加pynmea2

    devtool add pynmea2 https://github.com/Knio/pynmea2/archive/1.7.1.tar.gz

上面提到的步骤workspace在您$BUILD_DIR的仓库中创建了一个文件夹,并为该仓库创建了自动生成的配方。

  1. 编辑食谱

    devtool edit-recipe influxdb-python

  2. 添加或检查DEPEND_${PN}并相应RDEPENDS_${PN}地添加到您的食谱中。我添加了所有requirements.txtinfluxdb-pythonRDEPENDS_${PN}

    RDEPEND_${PN} += "${PYTHON_PN}-modules ${PYTHON_PN}-requests ${PYTHON_PN}-dateutil ${PYTHON_PN}-pytz ${PYTHON_PN}-six"

    注意:我尚未添加pandasnumpy因为它们与我的应用程序无关。

  3. DEPENDS_${PN} = "${PYTHON_PN}-modules也加了。

注意:执行相同的操作,pynmea2但是由于没有requirements.txt添加任何内容,RDEPENDS_${PN} = "${PYTHON_PN}-modules"因此目标上所有主要功能均可用。

配方结构

GitHub Gist食谱

我遵循meta-python文件夹的结构,其中每个配方均由以下组成:

  • recipe.inc
  • recipe_version_number.bb

influxdb_python.inc保持从产生的一切东西,devtool

# Recipe created by recipetool
# This is the basis of a recipe and may need further editing in order to be fully functional.
# (Feel free to remove these comments when editing.)
#
# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is
# your responsibility to verify that the values are complete and correct.
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=046523829184aac3703a4c60c0ae2104"

HOMEPAGE = "https://github.com/influxdb/influxdb-python"
SUMMARY = "InfluxDB client"

SRC_URI = "https://github.com/influxdata/influxdb-python/archive/v${PV}.tar.gz"
SRC_URI[md5sum] = "105d88695151e241523b31dd1375096e"
SRC_URI[sha256sum] = "620de85bcca5207b06ec1565884b6d10b4be01d579a78e08b1e922f453fdac05"

DEPENDS_${PN} = "${PYTHON_PN}-modules"
RDEPENDS_${PN} = "${PYTHON_PN}-modules ${PYTHON_PN}-requests ${PYTHON_PN}-dateutil ${PYTHON_PN}-pytz ${PYTHON_PN}-six"
Run Code Online (Sandbox Code Playgroud)

在中,influxdb_python_5.2.0.bb我添加了以下几行:

inherit setuptools3 pypi                              
require influxdb-python.inc
Run Code Online (Sandbox Code Playgroud)

注意:添加是setuptools3因为我希望运行我的应用程序python3.5。对于python2.7使用setuptools

同样,我对pynmea2.inc

# Recipe created by recipetool
# This is the basis of a recipe and may need further editing in order to be fully functional.
# (Feel free to remove these comments when editing.)
#
# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is
# your responsibility to verify that the values are complete and correct.
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=bb5e173bc54080cb25079199959ba6b6"

HOMEPAGE = "https://github.com/Knio/pynmea2"
SUMMARY = "Python library for the NMEA 0183 protcol"

SRC_URI = "https://github.com/Knio/pynmea2/archive/${PV}.tar.gz"
SRC_URI[md5sum] = "a90baf61f4e676bef76099e4bd7c0581"
SRC_URI[sha256sum] = "8f8f68623bd2d5dab7f04a9c31813a3f4aa15467db0373cbce6b9b0ae44ca48e"

#DEPENDS_${PN} = "${PYTHON_PN}-datetime ${PYTHON_PN}-threading ${PYTHON_PN}-io"
DEPENDS_${PN} = "${PYTHON_PN}-modules"
# WARNING: the following rdepends are determined through basic analysis of the
# python sources, and might not be 100% accurate.
RDEPENDS_${PN} = "${PYTHON_PN}-modules"
Run Code Online (Sandbox Code Playgroud)

对于pynmea2_1.7.1.bb

inherit setuptools3 pypi
require pynmea2.inc
Run Code Online (Sandbox Code Playgroud)

烤食谱

您可以使用bitbake -k influxdb-pythonbitbake -k pynmea2 或使用 devtool build influxdb-python和测试它们 devtool build pynmea2

如果没有错误,则可以使用以下命令将其部署在目标上:

devtool deploy-target influxdb-python user@machineIP:dest_folder
Run Code Online (Sandbox Code Playgroud)

支票

您可以通过触发python shell进行检查

# python3 

 >> import influxdb-python
 >> import pyserial
Run Code Online (Sandbox Code Playgroud)

如果导入没有抛出缺少的模块错误,则说明成功!

最后步骤

  • 您可以取消部署模块: devtool undeploy-target recipe_name [address of target]

  • 将食谱发送到您的自定义元层 devtool finish recipe_name ../meta-custom

注意:如果您使用krogoth或降低您的配方,则必须手动将配方移至元层

  • 现在包括这些食谱在您conf/local.confIMAGE_INSTALL_append = " influxdb-python pynmea2"bitbake -k your-image-name

定制应用

尚未测试。

但是我想我会像在YoctoCookBook信息库中hello-world提到的那样,将我的应用程序简单地添加到我的meta图层中。

小块

  • ${PYTHON_PN}-modules真的是救星。我尝试手动添加运行时部门,每次将其部署在板上时,总是会丢失一些依赖项。但是modules在实例中添加已解决的所有缺少的dep问题。

  • 我不确定何时使用,DEPENDS_${PN}但我认为大多数python应用程序都依赖于基本应用程序,python-modules因此我添加了它们。

  • 这不是YOCTO专家,但这只是我最近2周的发现。Yocto中缺少适当的Python示例。希望这对某人有帮助。