Class confinement for Python snaps

Barry Warsaw barry at ubuntu.com
Fri Mar 10 15:14:04 UTC 2017


I'm converting ubuntu-image from a devmode snap to a classic snap, but I'm
running into some problems.  ubuntu-image is a Python 3 application, and I'm
using snapcraft 2.27.1+17.4 on Zesty.

The first problem I'm having is I think directly related to LP: #1670749.  I
ended up reopening this because while Corey found that he ultimately only
needed to set the $PATH environment variable, I still also had to $PYTHONPATH
and I had to make sure the snap versions come before the system versions:

environment:
  PATH: $SNAP/bin/:$PATH
  PYTHONPATH: $SNAP/lib/python3.5/site-packages:$PYTHONPATH

This gets me pretty close, but then I run into my second problem which is that
we depend on pyparted, in Ubuntu as python3-pyparted.  This package contains
both Python source and an extension module and to further complicate things,
its tarball is only released on GitHub, not on PyPI, so adding it to
python-packages in the ubuntu-image part doesn't work.  Further, it doesn't
help to add python3-parted to stage-packages because it appears that with
classic confinement, none of those Python packages end up in the snap.

I tried to add a scriptlet to copy things over, but that also fails.  E.g.:

parts:
  ubuntu-image:
    plugin: python
    source: https://github.com/CanonicalLtd/ubuntu-image.git
    source-type: git
    python-packages:
      - PyYAML
      - attrs
      - voluptuous
    prime:
      - bin/ubuntu-image
      - usr
      - lib
      - sbin
    stage-packages:
      - e2fsprogs
      - mtools
      - python3-debian
      - python3-parted
      - util-linux
    install: |
      cp -a ../install/usr/lib/python3/dist-packages/parted ../stage/lib/python3.5/site-packages
      cp -a ../install/usr/lib/python3/dist-packages/pyparted-*.egg-info ../stage/lib/python3.5/site-packages

$ snapcraft
...
/home/barry/projects/ubuntu/allsnappy/ubuntu-image/parts/ubuntu-image/build
cp: cannot create directory '../stage/lib/python3.5/site-packages': No such file or directory
cp: cannot create regular file '../stage/lib/python3.5/site-packages': No such file or directory
Command '['/bin/sh', '/tmp/tmpfeczxcco', '/tmp/tmp2__1bdau']' returned non-zero exit status 1

This happens because ./stage/ is empty at the point that the install scriptlet
is run.

I can think of a couple of approaches that might be useful.

* Allow python-packages specifications to pip install from repositories other
  than PyPI.

* Allow python-packages to come from git and/or https URLs (I tried this and
  it didn't work).

* Integrate dirtbike and wheels into the Python parts building phases.
  (dirtbike is a tool that Debian/Ubuntu uses in very limited cases to turn
  installed distro packages into .whl files.)

* Provide a scriptlet hook that runs after the normal part installation step.

My current WIP snapcraft.yaml file is here:

https://github.com/CanonicalLtd/ubuntu-image/blob/lp1638645/snapcraft.yaml

I'm going to keep trying a few things, but any suggestions are welcome.  I'm
happy to file bugs as needed.

Cheers,
-Barry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 801 bytes
Desc: OpenPGP digital signature
URL: <https://lists.ubuntu.com/archives/snapcraft/attachments/20170310/3994e35d/attachment.sig>


More information about the Snapcraft mailing list