Flatpak and Python

Mathieu Bridon bochecha at daitauha.fr
Sun Jul 8 10:22:03 UTC 2018


Salut à toi,

On Sun, 2018-07-08 at 11:08 +0200, Goffi wrote:
> I'm trying to package my software for Flatpak (https://salut-a-
> toi.org), and I'm run into a couple of issues (flatpak version:
> 0.99.2)  :
> 
> 1) it's using Python, I've run into this page:
> https://www.loganasherjones.com/2018/05/using-flatpak-with-python/
> which is installing Python manually (while it's already in 
> org.freedesktop.Platform runtime), then activating network for 
> installation, but http://docs.flatpak.org/en/latest/python.html says
> to download depencies separately then install without network.
> Is the way with network activation OK ?

It works, but it's definitely not the preferred way of buiding things.

I'm pretty sure the app wouldn't pass review on Flathub if it enables
network access during the build. (although that doesn't seem to be
written in the app requirements)

> 2) the project is using Python 2. The flatpak-pip-generator script
> use the --prefix option with pip, but the pip2 available in the image
> is too old  (7.1.0 while last version is 10.0.1) and doesn't have
> this option. Would is be possible to update it in the runtime ?

Updating pip in the Sdk would be good, but in the meantime, you should
be able to use `python2 setup.py install --prefix=/app` instead.

> 3) I try to update myself pip, then to install my dependencies, you
> can see my manifest attached. I keep getting a "No matching
> distribution found for setuptools" while I explictly install
> setuptools

You're not installing setuptools, just downloading and extracting its
tarball.

You should have one module for each tarball instead.

See for example: https://github.com/flathub/org.musicbrainz.Picard/blob
/master/org.musicbrainz.Picard.json#L153-L223

> 4) there is a FS issue, /app/lib/python2.7/site-packages/easy-
> install.pth can't be updated:
> % flatpak-builder build-dir org.salutatoi.SAT.json --force-clean --
> build-
> shell=sat
> Downloading sources
> =====================================================================
> ===
> Building module sat in /home/goffi/dev/sat_docs/flatpak/.flatpak-
> builder/
> build/sat-43
> =====================================================================
> ===
> sh-4.3$ cd /app/lib/python2.7/site-packages/
> sh-4.3$ cat easy-install.pth 
> import sys; sys.__plen = len(sys.path)
> ./lxml-3.7.3-py2.7-linux-x86_64.egg
> import sys; new = sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p
> = 
> getattr(sys, '__egginsert', 0); sys.path[p:p] = new; sys.__egginsert
> = p + 
> len(new)
> sh-4.3$ echo test >> easy-install.pth 
> sh: easy-install.pth: Read-only file system
> sh-4.3$ 

That's because at this point the file has already been installed by a
previous module, and as such is read-only for future modules.

It's really bad that some buildsystems want to modify files already on
the system, instead of just installing new files… But when that
happens, you can get out of it with ensure-writable, sprinkled where
needed in your manifest: https://github.com/flathub/org.musicbrainz.Pic
ard/blob/master/org.musicbrainz.Picard.json#L173-L175


-- 
Mathieu


More information about the Flatpak mailing list