为一个 Python 应用程序在 Yocto 中编写配方

7
我是一个有用的助手,可以为您翻译文本。

我有一个简单的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          

上述内容是使用以下命令生成的: pip3 install pynmea2 pyserial influxdb
在OpenEmbedded层索引中,我已经找到了Python3的pyserial包。这意味着在板子上,我只需要执行pip3 install pynmea2 influxdb命令。
考虑到上述所有pip依赖项,您如何编写我的应用程序配方?
我没有找到编写Python应用程序配方的任何教程。(相反,Node应用程序在Yocto的wiki页面上有一些指导)。
在检查meta-python层中的一些配方时,我发现了一些.inc文件,但不确定该如何进行操作。

bitbake 中,使用 .inc 文件来支持食谱之间的共享功能 - 示例 - lukaszgard
当遇到像http://cgit.openembedded.org/meta-openembedded/tree/meta-python/recipes-devtools/python/python3-pyserial_3.4.bb?h=master中的.inc文件时,您可以认为是在.bb文件中扩展了.inc文件。对于你列出的要求,请将它们放在.bb/.inc文件中的RDEPENDS_${PN}中。参见http://cgit.openembedded.org/meta-openembedded/tree/meta-python/recipes-devtools/python/python-pyserial.inc#n33。 - Kai
1个回答

19

创建无法在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

上述步骤会在您的$BUILD_DIR中创建一个名为workspace的文件夹,并为存储库创建自动生成的配方。

  1. 编辑配方

    devtool edit-recipe influxdb-python

  2. 根据需要添加或检查配方中的DEPEND_${PN}RDEPENDS_${PN}。 我将所有influxdb-pythonrequirements.txt添加到RDEPENDS_${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"

我在 influxdb_python_5.2.0.bb 文件中添加了如下代码:

inherit setuptools3 pypi                              
require influxdb-python.inc

注意:我添加了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"

针对pynmea2_1.7.1.bb

inherit setuptools3 pypi
require pynmea2.inc

烘焙配方

您可以使用bitbake -k influxdb-pythonbitbake -k pynmea2或者devtool build influxdb-pythondevtool build pynmea2来测试它们。

如果没有错误,您就可以将其部署到目标设备上:

devtool deploy-target influxdb-python user@machineIP:dest_folder

检查

您可以通过启动Python shell进行检查。

# python3 

 >> import influxdb-python
 >> import pyserial

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

最终步骤

  • 您可以卸载模块:devtool undeploy-target recipe_name [address of target]

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

注意:如果您使用的是krogoth或更低版本,那么您必须手动将您的配方移动到您的元层中

  • 现在在您的conf/local.conf中包含这些配方IMAGE_INSTALL_append = " influxdb-python pynmea2"bitbake -k your-image-name

定制应用程序

尚未测试。

但我认为我会像在YoctoCookBook存储库中提到的那样使用我的应用程序,并搭配我的meta层。

NUGGETS


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接