After cleanup part, command not found in the prime directory, but it's there

I was having trouble with duplicate libraries so I added the cleanup. I am now stuck with an error saying that the command “bin/alpha” was not found in the prime directory, yet it appears to be there:

Skipping stage alpha (already ran)
Staging cleanup 
Staging gnome-3-34-extension 
Priming alpha 
Priming cleanup 
+ cd /snap/core18/current
+ find . -type f,l -exec rm -f /root/prime/{} ;
+ cd /snap/gnome-3-34-1804/current
+ find . -type f,l -exec rm -f /root/prime/{} ;
+ cd /snap/gtk-common-themes/current
+ find . -type f,l -exec rm -f /root/prime/{} ;
Priming gnome-3-34-extension 
The command 'bin/alpha' was not found in the prime directory, it has been changed to '/usr/bin/python3'.
Failed to generate snap metadata: The specified command '/usr/bin/python3 $SNAP/bin/alpha' defined in the app 'alpha' does not match the pattern expected by snapd.
The command must consist only of alphanumeric characters, spaces, and the following special characters: / . _ # : $ -
snapcraft-alpha # ls prime/bin/
alpha  cygdb  cython  cythonize  matchtool  sequencetool

Would anybody know what the problem is here?

Try removing the core18-related lines from the cleanup part, i.e. these two:

cd /snap/core18/current
find . -type f,l -exec rm -f /root/prime/{} ;

The problem is the cleanup part is removing python3 and then snapcraft thinks incorrectly that python3 doesn’t exist because the cleanup part has removed it on the premise that core18 will provide it.

Thanks @lucyllewy. I have the standard cleanup part that I found here: Reducing the size of desktop snaps

  cleanup:
    after:  # Make this part run last; list all your other parts here
      - alpha
    plugin: nil
    build-snaps:  # List all content-snaps and base snaps you're using here
      - core18
      - gnome-3-34-1804
      - gtk-common-themes

    override-prime: |
      set -eux
      for snap in "core18" "gnome-3-34-1804" "gtk-common-themes"; do  # List all content-snaps and base snaps you're using here
          cd "/snap/$snap/current" && find . -type f,l -exec rm -f "$SNAPCRAFT_PRIME/{}" \;
      done

So the way I interpret your advice is to remove the “core18” from the for loop. I’ve tried that and the proble persists.

Skipping prime gnome-3-34-extension (already ran)
The command 'bin/alpha' was not found in the prime directory, it has been changed to '/usr/bin/python3'.
Failed to generate snap metadata: The specified command '/usr/bin/python3 $SNAP/bin/alpha' defined in the app 'alpha' does not match the pattern expected by snapd.
The command must consist only of alphanumeric characters, spaces, and the following special characters: / . _ # : $ -
1 Like

Aha, yes, you are correct that you need to remove “core18” from the loop. Due to the way the script works you’ll need to run snapcraft clean and rebuild from scratch for the change to correctly take effect.

Same problem after snapcraft clean:

Priming cleanup 
+ cd /snap/gnome-3-34-1804/current
+ find . -type f,l -exec rm -f /root/prime/{} ;
+ cd /snap/gtk-common-themes/current
+ find . -type f,l -exec rm -f /root/prime/{} ;
Priming gnome-3-34-extension 
The command 'bin/alpha' was not found in the prime directory, it has been changed to '/usr/bin/python3'.
Failed to generate snap metadata: The specified command '/usr/bin/python3 $SNAP/bin/alpha' defined in the app 'alpha' does not match the pattern expected by snapd.
The command must consist only of alphanumeric characters, spaces, and the following special characters: / . _ # : $ -

I’m wondering by python3 is necessary in the priming step. I understand that it is needed for the build step, but why the priming step?

Also, the error says that “The command ‘bin/alpha’ was not found”. What does this have to do with python being included?

Is the shebang for bin/alpha using python? If so, that is why.

Yes @sergiusens, there is the shebang line in /bin/alpha (#!/usr/bin/env python3). Is there anyway to get around this check during the priming step?

I’m in a situation where I have to include the graphviz libraries that pull in the libpango package, which conflicts with the system installed libgtk. So the cleanup part gets rid of the unwanted libpango, but it also removes python3 which is need, for some reason, in the priming step. I can see two ways forward:

  1. Replace the cleanup part with a part that targets only libpango for removal.
  2. Add another part after the cleanup part that reinstalls python3.

Are there other options?

  1. exclude python from the find call ?
    (have a look at the -iname option)

Good point, I was avoiding learning the bash commands/syntax to implement this logic.

I’ll check out the -iname.

The thing is, I don’t want python3 to be included in my snap, right? Wouldn’t this be unnecessary bloat? In this case, how would I include python3 for the prime step, but not have it included in the snap?

The prime tree is pretty much “what is eventually ended in the snap”, IMHO this is a Snapcraft bug that shouldn’t be dealt with in the packaging.