FORUM CTRLX AUTOMATION
ctrlX World Partner Apps for ctrlX AUTOMATION
Dear Community User! We are updating our platform to a new
system.
Read more: Important
information on the platform change.
06-13-2024 06:53 PM
Hello everyone,
we want to build our own first SNAP. However, we are currently facing issues.
When I execute the code inside the suitable environment, it is working OK. When I build the snap and install it on a virtual ctrlX CORE V2.4, I receive the following information via ssh:
2024-06-13T16:41:33Z systemd[1]: Started Service for snap application lincap.webserver.
2024-06-13T16:41:33Z lincap.webserver[10257]: /snap/lincap/x2/bin/main.py: 1: from: not found
2024-06-13T16:41:33Z lincap.webserver[10257]: /snap/lincap/x2/bin/main.py: 2: from: not found
2024-06-13T16:41:33Z lincap.webserver[10257]: /snap/lincap/x2/bin/main.py: 3: from: not found
: not found16:41:33Z lincap.webserver[10257]: /snap/lincap/x2/bin/main.py: 4:
: not found16:41:33Z lincap.webserver[10257]: /snap/lincap/x2/bin/main.py: 5:
2024-06-13T16:41:33Z lincap.webserver[10257]: /snap/lincap/x2/bin/main.py: 10: Syntax error: "(" unexpected (expecting "then")
2024-06-13T16:41:33Z systemd[1]: snap.lincap.webserver.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
2024-06-13T16:41:33Z systemd[1]: snap.lincap.webserver.service: Failed with result 'exit-code'.
2024-06-13T16:41:42Z systemd[1]: Stopped Service for snap application lincap.webserver.
In these lines 1-3 I try to import from a local package
from src.xmlrpc_server import XmlRpcServer
from src.servos import Servo
from src.control_functions import ControlFunctions
Although I included the packages into the setup.py, they are not recognized. Maybe someone has a hint, thanks a lot!
from setuptools import setup
setup(
name='appname',
version='1.1.0',
description='description',
author='me',
packages=['app', 'appdata', 'motion.core.fbtypes', 'robot.core.fbtypes', 'src', 'src.rtde'],
#src.rtde is used by python script inside the folder src
install_requires=['flask', 'ctrlx-datalayer', 'ctrlx-fbs', 'pyopenssl'],
package_data={},
scripts=['main.py', 'datalayerProvider.py', 'fbsFunction.py'],
license='Copyright (c) 2024'
)
Here is the folder structure:
my_project/
├── snap/
│ └── snapcraft.yaml
├── main.py
├── src/
│ ├── __init__.py
│ ├── module1.py
│ ├── module2.py
│ ├── rtde/
│ │ ├── __init__.py
│ │ ├── submodule1.py
│ │ └── submodule2.py
├── app/
│ ├── __init__.py
├── appdata/
│ ├── __init__.py
├── motion/
│ ├── core/
│ │ ├── __init__.py
│ │ ├── fbtypes.py
├── robot/
│ ├── core/
│ │ ├── __init__.py
│ │ ├── fbtypes.py
└── setup.py
Solved! Go to Solution.
06-13-2024 08:08 PM
Hi @K-Zanaty ,
Can you please provide your snapcraft.yaml? It seems these packages are not being provided in the built application.
Are you including the src/ directory in the snapcraft build? Since these are local modules, you should be able to use the python plugin with the source attribute set to "." as below. So long as these packages are in your setup.py, like you've shown, they should be available in the built snap.
parts:
provider:
plugin: python
source: .
stage-packages:
- libzmq5
- ctrlx-datalayer
python-packages:
- ./whl/pylogix-1.0.0-py2.py3-none-any.whl
- ./whl/pycomm3-1.2.14-py3-none-any.whl
06-14-2024 08:42 AM
Sure, please find below my file content:
name: name
version: 1.0.0
summary: summary
title: title
description: |
description
base: core22
confinement: strict
grade: stable
apps:
webserver:
command: bin/main.py
plugs:
- network
- network-bind
- datalayer
- active-solution
slots:
- package-assets
- package-run
daemon: simple
restart-condition: always
passthrough:
restart-delay: 10s
parts:
webserver:
plugin: python
source: .
stage-packages:
- libzmq5
- ctrlx-datalayer
bfbs:
plugin: dump
source: ./bfbs
organize:
'*': bfbs/
mddb:
plugin: dump
source: ./mddb
organize:
'*': mddb/
templates:
plugin: dump
source: ./templates
organize:
'*': templates/
static:
plugin: dump
source: ./static
organize:
'*': static/
configs:
source: ./configs
plugin: dump
organize:
'package-assets/*': package-assets/${SNAPCRAFT_PROJECT_NAME}/
slots:
package-assets:
interface: content
content: package-assets
source:
read:
- $SNAP/package-assets/${SNAPCRAFT_PROJECT_NAME}
package-run:
interface: content
content: package-run
source:
write:
- $SNAP_DATA/package-run/${SNAPCRAFT_PROJECT_NAME}
plugs:
datalayer:
interface: content
content: datalayer
target: $SNAP_DATA/.datalayer
active-solution:
interface: content
content: solutions
target: $SNAP_COMMON/solutions
project details in name and description are changed
06-14-2024 03:25 PM
When you snap the app, is this portion of your source directory available in the snapcraft /prime folder?
├── src/
│ ├── __init__.py
│ ├── module1.py
│ ├── module2.py
│ ├── rtde/
│ │ ├── __init__.py
│ │ ├── submodule1.py
│ │ └── submodule2.py
06-14-2024 04:09 PM
Hi,
no, I could not see it.
Also, there is an issue in finding additional, non script, files the scripts try to read and parse (e.g. in folder "config/file.xml"). After some debugging, I can see them in the prime folder and also in the snap-extract (using <unsquashfs -d ... >) but the snap keeps reporting that it cannot find the files.
I am assuming that I'm still very unsure about the correct configuration and at which place which file has to live to work as a snap..
06-14-2024 04:59 PM - edited 06-14-2024 05:00 PM
Sorry, I should have specified better. It should be in the prime/lib(64)/python3.8/site-packages directories. Here is an example using modules from the /app source directory.
There are many different ways to build snaps, so there are many "correct" configurations. It's often a matter of preference. Snapcraft has pretty good documentation and debug support but is definitely complex.
06-17-2024 07:50 AM
@K-Zanaty You could have a look to our web-based training "ctrlX AUTOMATION SDK II" and see if it can help you getting more familiar with building apps.