Snapcraft ros2

Hello together, I am trying to snap ros2 foxy as a stand-alone ros-base. I’ve done that by building ros2 foxy using the colcon plugin and snapping the install folder, using the following snapcraft file.

name: ros-base
version: '0.1'
summary: Basic ROS2 listener component
description: |
  Basic ROS2 listener component based on core20

grade: stable
confinement: strict
base: core20
parts:
  dump:
    plugin: colcon
    stage-packages: [
      ros-foxy-ros2launch,
      ros-foxy-ros-core,]
    build-environment:
      - ROS_VERSION: '2'
      - ROS_DISTRO: foxy

slots:
  ros-base:
    interface: content
    content: executables
    read: [/]
    private: false

After that I tried to build an overlay snap (simple Hello World talker node) using the following snapcraft file,

name: overlay
version: '0.1'
summary: Basic ROS2 listener component
description: |
  Basic ROS2 listener component based on core20

grade: stable
confinement: strict
base: core20
parts:
  dump:
    plugin: colcon
    source: src
    build-packages: [make, gcc, g++]
    stage-packages: [ros-foxy-ros2launch, ros-foxy-common-interfaces]
    override-build: |
      snapcraftctl build
    build-environment:
      - ROS_VERSION: '2'
      - ROS_DISTRO: foxy

  wrapper-scripts:
    plugin: dump
    source: ./wrappers/
    organize:
      ./motion_joint.wrapper.sh : usr/bin/ros2-custom-ws


apps:
  app4:
    command: usr/bin/ros2-custom-ws

plugs:
  ros-base:
    interface: content
    content: executables
    target: $SNAP/mohamed
    private: false

My wrapper file looks like that:

#!/bin/bash
ROS_BASE=$SNAP/mohamed

export PYTHONPATH=$PYTHONPATH:$ROS_BASE/usr/lib/python3.8/dist-packages:$PYTHONPATH

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROS_BASE/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROS_BASE/lib/
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROS_BASE/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/blas
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROS_BASE/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/lapack
source $SNAP/mohamed/opt/ros/foxy/setup.bash 
$SNAP/opt/ros/snap/lib/py_pubsub/talker 

After connecting both snaps slots and plugs I can run the overlay snap using the following command: overlay.app4 Howevere, when doing so, I get the following error:

/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
Traceback (most recent call last):
  File "/snap/overlay/x1/opt/ros/snap/lib/py_pubsub/talker", line 6, in <module>
    from pkg_resources import load_entry_point
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3254, in <module>
    def _initialize_master_working_set():
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3237, in _call_aside
    f(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3266, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 584, in _build_master
    ws.require(__requires__)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 901, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 787, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'py-pubsub==0.0.0' distribution was not found and is required by the application

My workspace for my overlay ros snap looks like that:

β”œβ”€β”€ snap
β”‚   └── snapcraft.yaml
β”œβ”€β”€ src
β”‚   └── py_pubsub
β”‚       β”œβ”€β”€ launch
β”‚       β”‚   └── publisher_launch.py
β”‚       β”œβ”€β”€ package.xml
β”‚       β”œβ”€β”€ py_pubsub
β”‚       β”‚   β”œβ”€β”€ __init__.py
β”‚       β”‚   └── publisher_member_function.py
β”‚       β”œβ”€β”€ resource
β”‚       β”‚   └── py_pubsub
β”‚       β”œβ”€β”€ setup.cfg
β”‚       β”œβ”€β”€ setup.py
β”‚       └── test
β”‚           β”œβ”€β”€ test_copyright.py
β”‚           β”œβ”€β”€ test_flake8.py
β”‚           └── test_pep257.py
└── wrappers
    └── motion_joint.wrapper.sh
1 Like

@artivis should be able to help.

Hi @mohamin101, Continuing on our discussion from the ROS Discourse here since this is a more appropriate place. Is your example hosted somewhere publicly? You may still have some sourcing issue but that’s really the tree that masks the forest here as this kind of setup is not supported for ROS 2 at the moment.