I have created a snap for a commandline program which runs fine in devmode.
In strict confinement mode I am running into AppArmor violations which I am trying to debug.
Your apparmor denials would suggest this is a problem with the use of the /dev/shm folder.
The default policy is that files created in /dev/shm must be namespaced to the snap, such that any temporary files follow the pattern of SNAP.$SNAPNAME.* (or something similar, I can’t 100% remember it ).
There’s a proposal for these kind of issues that might remove this restriction in the future, take a look here, but none of this is available to use yet.
Your options are likely to either use the snapcraft-preload library which can fix this in some situations (by mapping transparently renaming files so they work), but it may be the case that whatever is making this call in Python is actually avoiding the standard shm_open() calls. E.G, Joblib in Python tests if /dev/shm/ exists first by just placing any random file in it, which fails and causes issues. If it’s a case similar to this, you might need to patch the Python file causing the issue (e.g, with sed or patch).
Failed to generate snap metadata: The specified command 'bin/snapcraft-preload $SNAP/bin/python3.9 -m ocrmypdf' defined in the app 'ocrmypdf' does not exist.
Ensure that 'bin/snapcraft-preload $SNAP/bin/python3.9 -m ocrmypdf' is installed with the correct path.
The path /prime/bin/python3.9 does exist when I introspect the build error.
to have the bits installed in the right locations (base: core18 snaps do this automatically, in base: core20 builds prefix and libpath have no defaults set)
Now I have my project generating a snap. Unfortunately snapcraft seems to be ignoring my:
python-packages:
- list items
This problem has appeared because core20 in strict confinement does not seem to have python bundled in (at least I cannot find python anywhere in the snap).
This feels like I am doing something wrong. The documentation here: https://snapcraft.io/docs/python-plugin states that there should be a python interpreter included in core20.
-> Found the solution to this: just use the
python3
command to invoke python and NOT a full path to a python interpreter. This will use the default interpreter in core20
I believe that snapcraft is ignoring my python-packages list ever since I manually included python in the stage-packages…
-> This was an incorrect belief. PIP is not used because of the override-build I used to get snapcraft-preload to work.
apparmor blocks the python code as it is → requires snapcraft-preload to work
snapcraft-preload on core20 is not installed where it is expected and requires override-build symlinking to work
override-build requires explicitely stating snapcraftctl build in the override-build section (see documentation here: https://snapcraft.io/docs/scriptlets)