Issue while packaging snap

I just made a snap for a project called frog.

name: frog # you probably want to 'snapcraft register <name>'
base: core22 # the base snap is the execution environment for this snap
version: '1.2.0' # just for humans, typically '1.2+git' or '1.3.2'
summary: Single-line elevator pitch for your amazing snap # 79 char long summary
description: |
  This is my-snap's description. You have a paragraph or two to tell the
  most important story about your snap. Keep it under 100 words though,
  we live in tweetspace and your description wants to look good in the snap
  store.

grade: devel # must be 'stable' to release into candidate/stable channels
confinement: devmode # use 'strict' once you have the right plugs and slots

parts:
  frog:
    plugin: meson
    source-type: git
    source: https://github.com/TenderOwl/Frog.git
    source-tag: "1.2.0"
    meson-parameters:
      - --prefix=/usr
      - --buildtype=release
    # See 'snapcraft plugins'
    build-packages:
      - meson
      - ninja-build
      - python3
      - python3-gi 
      - python3-pydbus 
      - python3-tesserocr 
      - python3-pyzbar 
      - tesseract-ocr
      - gettext
      - pkg-config
      - libglib2.0-dev
      - desktop-file-utils
      - appstream
      - libappstream-dev  
apps:
  frog:
    command: desktop-launch /usr/bin/frog
    command-chain: [ bin/desktop-launch ]
    extensions: [gnome]
    environment:
      GTK_USE_PORTAL: 1
    plugs:
      - home
      - desktop
      - desktop-launch
      - XDG_DATA_HOME
plugs:
  XDG_DATA_HOME:
    interface: personal-files
    write:
      - $HOME/.local/share

But whenever I run the snapcraft -v I get this…

Cannot pack snap file: Command '['snap', 'pack', '--filename', 'frog_1.2.0_amd64.snap', '--compression', 'xz', PosixPath('/root/prime'), PosixPath('/root/project')]' returned non-zero exit status 1. (2023/01/31 08:24:00.104721 container.go:215: in snap "frog": path "desktop-launch" does not exist
error: cannot pack "/root/prime": snap is unusable due to missing files)

What can be the issue?

@popey can you help me please.

Remove the command-chain line from your apps block. This is not needed, as you are only using it to specify the desktop-launch script and that is set automatically to the correct value anyway because you are using the gnome extension.

Edit: oh, and also, change your command to remove desktop-launch as well. It should be like this:

apps:
  frog:
    command: usr/bin/frog
    extensions: [gnome]
    ... # snipped

Hey I’m getting this error

frog
Traceback (most recent call last):
  File "/usr/bin/frog", line 59, in <module>
    from frog import main
  File "/usr/local/lib/python3.10/dist-packages/frog/main.py", line 40, in <module>
    from .about_dialog import AboutDialog
  File "/usr/local/lib/python3.10/dist-packages/frog/about_dialog.py", line 29, in <module>
    from frog.config import APP_ID, RESOURCE_PREFIX
  File "/usr/local/lib/python3.10/dist-packages/frog/config.py", line 33, in <module>
    if not os.path.exists(os.path.join(os.environ['XDG_DATA_HOME'], 'tessdata')):
  File "/usr/lib/python3.10/os.py", line 679, in __getitem__
    raise KeyError(key) from None
KeyError: 'XDG_DATA_HOME'

This also happens, when installing via manual compilation

This looks like an error from a non snap, regardless, it might happen because you are not running it in a desktop session.

is XDG_DATA_HOME set in your desktop session at all (it would normally be inherited by the snap if it was, i don’t think anything in the desktop-launch script sets it explicitly for the snap) ?

Does running echo $XDG_DATA_HOME in a terminal on your desktop return anything ?

The $XDG partitions are never preset in Ubuntu. And I am running this from my desktop, which I daily drive

As said before, it gives nothing. We need to set it manually, or via snap we need to do something

right, if your app has a hard requirement for it and your desktop session does not set it either, you should add an environment: block to your apps: section.

Something similar to the below should work:

apps:
  frog:
    command: ...
    extensions: ...
    environment:
      XDG_DATA_HOME: $SNAP_USER_DATA/.local/share 

Hey, this app also requires libadwaita version 1.2.0, but in core22, it’s 1.1.0, what can be done for these?

you could try building it from source in its own part or do a backport of a newer deb in a PPA …

is the XDG_DATA_HOME error gone with the above environment line ?

No I am still getting the same issue

can you do:

$ snap run --shell frog

and run env | grep XDG in that environment and paste the output here ?

Here it’s. I guess it’s showing, but a wrong directory.

snap run --shell frog
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

soumyaxubuntu@soumyas-GF63-Thin-11UC-866IN:/home/soumyaxubuntu/Downloads/Project/frog$ env | grep XDG 
XDG_CONFIG_DIRS=/snap/frog/x1/gnome-platform/etc/xdg:/etc/xdg/xdg-ubuntu:/etc/xdg
XDG_MENU_PREFIX=gnome-
XDG_DATA_HOME=/home/soumyaxubuntu/snap/frog/x1/.local/share
XDG_CONFIG_HOME=/home/soumyaxubuntu/snap/frog/x1/.config
XDG_SESSION_DESKTOP=ubuntu
XDG_SESSION_TYPE=wayland
XDG_CURRENT_DESKTOP=ubuntu:GNOME
XDG_CACHE_HOME=/home/soumyaxubuntu/snap/frog/common/.cache
XDG_SESSION_CLASS=user
XDG_RUNTIME_DIR=/run/user/1000/snap.frog
XDG_DATA_DIRS=/home/soumyaxubuntu/snap/frog/x1/.local/share:/home/soumyaxubuntu/snap/frog/x1:/snap/frog/x1/data-dir:/snap/frog/x1/usr/share:/snap/frog/x1/gnome-platform/usr/share:/usr/share/ubuntu:/home/soumyaxubuntu/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop

no, that is the correct directory for a snap … so you say you are still seeing the KeyError ? that must be an upstream bug with the frog code then since the variable is properly set …

Yes, and no that’s not a bug, because when compiled manually, and using the app with XDG_DATA_DIRs set, then it’s all fine

if the variable is definitely set but the code says it is not set by spitting out a KeyError, this is a bug …

But install it by compiling the code manually, there is no issue. It works fine. EDIT: Also, the flatpak version of it, also works fine

are you probably missing files in there that you are not copying in place (from an install hook or launch wrapper script) ?

Running /snap/bin/frog

/snap/frog/x3/gnome-platform/command-chain/desktop-launch: /snap/frog/x3/usr/bin/frog: /snap/gnome-42-2204-sdk/current/usr/bin/python3: bad interpreter: No such file or directory
/snap/frog/x3/gnome-platform/command-chain/desktop-launch: line 603: /snap/frog/x3/usr/bin/frog: Success

Almost done… Just some few issues, but help please.