0

我正在构建一个 snap 来测试 python 脚本和 python SDK 与 snapcraft 的集成,当两个 python“部分”在同一个 snap 中构建时似乎存在冲突。

使用多个 python 模块构建快照的最佳方法是什么?

我有一个简单的脚本,它可以导入 SDK,然后打印一些信息。我在不同的文件夹中也有 python SDK 库(https://help.iotconnect.io/documentation/sdk-reference/device-sdks-flavors/download-python-sdk/ )。

我已经定义了这两个部分,并且每个部分都可以独立构建(snapcraft build PARTNAME),但是在下一步将它们“暂存”在一起时,python 内部似乎存在冲突。

结构的树输出

tree
.
├── basictest
│   ├── basictest.py
│   ├── __init__.py
│   └── setup.py
├── iotconnect-sdk-3.0.1
│   ├── iotconnect
│   │   ├── assets
│   │   │   ├── config.json
│   │   │   └── crt.txt
│   │   ├── client
│   │   │   ├── httpclient.py
│   │   │   ├── __init__.py
│   │   │   ├── mqttclient.py
│   │   │   └── offlineclient.py
│   │   ├── common
│   │   │   ├── data_evaluation.py
│   │   │   ├── infinite_timer.py
│   │   │   ├── __init__.py
│   │   │   └── rule_evaluation.py
│   │   ├── __init__.py
│   │   ├── IoTConnectSDKException.py
│   │   ├── IoTConnectSDK.py
│   │   └── __pycache__
│   │       ├── __init__.cpython-38.pyc
│   │       └── IoTConnectSDK.cpython-38.pyc
│   ├── iotconnect_sdk.egg-info
│   │   ├── dependency_links.txt
│   │   ├── not-zip-safe
│   │   ├── PKG-INFO
│   │   ├── requires.txt
│   │   ├── SOURCES.txt
│   │   └── top_level.txt
│   ├── PKG-INFO
│   ├── README.md
│   ├── setup.cfg
│   └── setup.py
└── snap
    └── snapcraft.yaml

9 directories, 30 files

snapcraft.yaml

name: basictest
base: core20
version: '0.1'
summary: Test snap to verifiy integration with python SDK
description: |
  Test snap to verifiy integration with python SDK

grade: devel
confinement: devmode

apps: 
  basictest:
    command: bin/basictest

parts:
  lib-basictest:
    plugin: python
    source: ./basictest/
    after: [lib-pythonsdk]
    disable-parallel: true
    
  lib-pythonsdk:
    plugin: python
    source: ./iotconnect-sdk-3.0.1/

运行“snapcraft”会显示大量错误,这些错误看起来像是与 python 内部相关的两个“部分”之间的冲突。

快照输出

snapcraft
Launching a VM.
Skipping pull lib-pythonsdk (already ran)
Skipping pull lib-basictest (already ran)
Skipping build lib-pythonsdk (already ran)
Skipping build lib-basictest (already ran)
Failed to stage: Parts 'lib-pythonsdk' and 'lib-basictest' have the following files, but with different contents:
    bin/activate
    bin/activate.csh
    bin/activate.fish
    lib/python3.8/site-packages/_distutils_hack/__pycache__/__init__.cpython-38.pyc
    lib/python3.8/site-packages/_distutils_hack/__pycache__/override.cpython-38.pyc
    lib/python3.8/site-packages/pip-21.3.1.dist-info/RECORD
    lib/python3.8/site-packages/pip/__pycache__/__init__.cpython-38.pyc
    lib/python3.8/site-packages/pip/__pycache__/__main__.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/__pycache__/__init__.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/__pycache__/build_env.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/__pycache__/cache.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/__pycache__/configuration.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/__pycache__/exceptions.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/__pycache__/main.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/__pycache__/pyproject.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/__pycache__/self_outdated_check.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/__pycache__/wheel_builder.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/cli/__pycache__/__init__.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/cli/__pycache__/autocompletion.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/cli/__pycache__/base_command.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/cli/__pycache__/cmdoptions.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/cli/__pycache__/command_context.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/cli/__pycache__/main.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/cli/__pycache__/main_parser.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/cli/__pycache__/parser.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/cli/__pycache__/progress_bars.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/cli/__pycache__/req_command.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/cli/__pycache__/spinners.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/cli/__pycache__/status_codes.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/commands/__pycache__/__init__.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/commands/__pycache__/cache.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/commands/__pycache__/check.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/commands/__pycache__/completion.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/commands/__pycache__/configuration.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/commands/__pycache__/debug.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/commands/__pycache__/download.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/commands/__pycache__/freeze.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/commands/__pycache__/hash.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/commands/__pycache__/help.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/commands/__pycache__/index.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/commands/__pycache__/install.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/commands/__pycache__/list.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/commands/__pycache__/search.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/commands/__pycache__/show.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/commands/__pycache__/uninstall.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/commands/__pycache__/wheel.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/distributions/__pycache__/__init__.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/distributions/__pycache__/base.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/distributions/__pycache__/installed.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/distributions/__pycache__/sdist.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/distributions/__pycache__/wheel.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/index/__pycache__/__init__.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/index/__pycache__/collector.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/index/__pycache__/package_finder.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/index/__pycache__/sources.cpython-38.pyc
    lib/python3.8/site-packages/pip/_internal/locations/__pycache__/__init__.cpython-38.pyc
... Tons more removed

Snapcraft offers some capabilities to solve this by use of the following keywords:
    - `filesets`
    - `stage`
    - `snap`
    - `organize`

To learn more about these part keywords, run `snapcraft help plugins`.
Run the same command again with --debug to shell into the environment if you wish to introspect this failure.

主要问题 使用多个 python 模块构建快照的最佳方法是什么?

4

2 回答 2

0

看起来最好的解决方案是从库中删除有问题的构建文件。“lib-basictest”部分是主要的执行脚本,在那里生成的文件应该包含在 SDK 库版本中

这是更新的 lib-pythonsdk 部分

  lib-pythonsdk:
    plugin: python
    source: ./iotconnect-sdk-3.0.1/
    stage:
      - -lib/python3.8/site-packages/pip/
      - -lib/python3.8/site-packages/setuptools/
      - -lib/python3.8/site-packages/wheel/
      - -lib/python3.8/site-packages/_distutils_hack
      - -lib/python3.8/site-packages/pip-21.3.1.dist-info
      - -lib/python3.8/site-packages/pkg_resources
      - -lib/python3.8/site-packages/wheel-0.37.1.dist-info
      - -bin/activate
      - -bin/activate.csh
      - -bin/activate.fish
      - -pyvenv.cfg

这就是我要使用的,除非我缺少一些“覆盖”参数?

于 2022-01-18T17:40:14.307 回答
0

为了使解决方案更便携并处理不同的版本号,子文件夹可以使用通配符

lib-pythonsdk:
    plugin: python
    source: ./iotconnect-sdk-3.0.1/
    stage:
      - -lib/python3.8/site-packages/pip*
      - -lib/python3.8/site-packages/wheel*
      - -lib/python3.8/site-packages/setuptools/
      - -lib/python3.8/site-packages/_distutils_hack
      - -lib/python3.8/site-packages/pkg_resources
      - -bin/activate
      - -bin/activate.csh
      - -bin/activate.fish
      - -pyvenv.cfg
于 2022-02-01T17:55:06.437 回答