Fixes #359 - Adds a Flatpak backend for Linux packaging#802
Conversation
…of support packages.
| The end user will install the Flatpak into their local app repository; this can | ||
| be done by installing directly from a single file `.flatpak` bundle, or by | ||
| installing from a package repository like `Flathub <https://flathub.org>`__. | ||
| Apps can be installed into user-space, or if the user has sufficient priviliges, |
There was a problem hiding this comment.
typo
priviliges -> privileges
|
|
||
| @classmethod | ||
| def verify(cls, command): | ||
| """Verify that linuxdeploy tool or plugin is available. |
There was a problem hiding this comment.
typo
linuxdeploy tool or plugin -> the Flatpak toolchain
| raise BriefcaseCommandError(f"Unable to start app {app_name}.") from e | ||
|
|
||
| def bundle(self, repo_url, bundle, app_name, version, build_path, output_path): | ||
| """Bubndle a Flatpak for distribution. |
| output_format = "flatpak" | ||
|
|
||
| def binary_path(self, app): | ||
| # Flatpak doesn't really produce an identifiable "binary" as part of it's |
There was a problem hiding this comment.
more cursed apostrophes
it's -> its
|
|
||
| # ``flatpak install`` uses a lot of console animations, and there | ||
| # doesn't appear to be a way to turn off these animations. Use those | ||
| # native animations rather than wrapping in a wait_bar. |
There was a problem hiding this comment.
furthermore, this actually brought up a user prompt for me to clarify which SDK package i wanted to install when I used org.gnome.SDK....not sure input would work with a wait bar.
There was a problem hiding this comment.
Interesting... I didn't get that prompt; what was your project configuration to get that prompt? I got an error if I specified:
flatpak_runtime = "org.gnome.Platform"
flatpak_sdk = "org.gnome.Sdk"
(because there isn't a gnome version 21.08 runtime); if I add flatpak_runtime_version = "42", it installed without a prompt. Did you use something different?
There was a problem hiding this comment.
hmmm....I used the same config. This is also a fairly freshly installed VM too....so I don't think I've added anything crazy to flatpak.
[tool.briefcase.app.flat.linux]
template = "https://github.com/beeware/briefcase-linux-flatpak-template"
template_branch = "dev"
flatpak_runtime = "org.gnome.Platform"
flatpak_runtime_version = "42"
flatpak_sdk = "org.gnome.SDK"
❯ briefcase build linux flatpak
[flat] Ensuring Flatpak runtime for the app is available...
Ensuring Flatpak runtime repo is registered... done
Looking for matches…
Skipping: org.gnome.Platform/x86_64/42 is already installed
Similar refs found for ‘org.gnome.SDK’ in remote ‘flathub’ (user):
1) runtime/org.gnome.Sdk.Compat.i386/x86_64/42
2) runtime/org.gnome.Sdk.Compat.aarch64/x86_64/42
3) runtime/org.gnome.Sdk/x86_64/42
4) runtime/org.gnome.Sdk.Docs/x86_64/42
Which do you want to use (0 to abort)? [0-4]: 0
error: No ref chosen to resolve matches for ‘org.gnome.SDK’
Unable to install Flatpak runtime org.gnome.Platform//42 and SDK org.gnome.SDK//42 from repo flathub.
Log saved to /home/user/tmp/beeware/flat/briefcase.2022_07_26-21_47_37.build.log
There was a problem hiding this comment.
And, to top it off, it asks me every time I build the flatpak which org.gnome.SDK I want to install....:/
There was a problem hiding this comment.
Hrm... I wonder if it might be related to the work you've been doing with i386. If the existence of 2 Platform flatpaks means there's 2 that match org.gnome.SDK//42, perhaps specifying org.gnome.SDK/x86_64/42 will remove the ambiguity...
There was a problem hiding this comment.
@rmartin16 I've just pushed an update that will be explicit about architecture when installing the SDK; does that work better for you?
There was a problem hiding this comment.
same :/
[flat] Ensuring Flatpak runtime for the app is available...
>>> Running Command:
>>> flatpak remote-add --user --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
>>> Return code: 0
Ensuring Flatpak runtime repo is registered... done
>>> Running Command:
>>> flatpak install --assumeyes --user flathub org.gnome.Platform/x86_64/42 org.gnome.SDK/x86_64/42
Looking for matches…
Skipping: org.gnome.Platform/x86_64/42 is already installed
Similar refs found for ‘org.gnome.SDK’ in remote ‘flathub’ (user):
1) runtime/org.gnome.Sdk.Compat.i386/x86_64/42
2) runtime/org.gnome.Sdk.Compat.aarch64/x86_64/42
3) runtime/org.gnome.Sdk/x86_64/42
4) runtime/org.gnome.Sdk.Docs/x86_64/42
Which do you want to use (0 to abort)? [0-4]:
There was a problem hiding this comment.
Ah - there's a typo in your config: org.gnome.SDK - > org.gnome.Sdk.
There was a problem hiding this comment.
:| i see. thanks. that fixed it.
|
Worked out of the box 🦾 Notes Building a flatpak for 32bit appears possible....but I gave up actually getting it to work. It doesn't appear possible to actually build the flatpak on a 32bit system but I don't think that's too surprising. Runtime and SDK versions should probably be updated together but it only fails at attempt to install. This is probably obvious to people more familiar with flatpak but just calling out that only changing I tried to run tutorial 4 but had to add I notice several files are being written without specifying the encoding...while linux is probably much more likely to be using |
| with bin_path.open("w") as f: | ||
| f.write( | ||
| f"""\ | ||
| #!/bin/bash |
There was a problem hiding this comment.
This may be more portable with #!/bin/sh instead.
|
On Debian 10 (Buster) with Flatpak 1.2.5, I was able to run a non-graphical app (Python-support-testbed) with no problems. However, when I tried to run a graphical app, I hit the error message described in flatpak/flatpak#397. This is because I'm forwarding X11 apps over SSH to an X server (VcXsrv) running on on my WIndows desktop. Unfortunately this can't simply be worked around by passing the DISPLAY environment variable into This was fixed only a few months ago in flatpak/flatpak#4706, which is recent enough that it won't be included in any stable version of Debian until version 12 (Bookworm) comes out in 2023. While running X11 over SSH is not that uncommon, it's obviously a lot less common than running a local Linux desktop. So if Flatpak is clearly better than Appimage, I don't think this should block us from making it the default output format on Linux, as long as we keep supporting Appimage as a fallback. |
W00t!
Yeah - I'm happy treating this as a "get it working at all" PR; adding support for 32 bit is something we can tackle later if someone is enthused. As with AppImage, it's likely going to be impeded by CI availability rather than anything technical.
That's a good idea - I'll add a safety around this.
Interesting... Were you able to run any other Toga tutorials? Adding an extra flag to manifest.yml isn't a big deal... except that the Flatpak docs seem to advise against adding that permission unless you really need it
Good catch; I'll add that in. |
|
Running in to issues with the
I saw the same error for the other tutorials as well. Furthermore, a version check of I think previous version of Also, since I didn't see this explicitly stated, is |
|
One more.....once I added |
|
@rmartin16 Can you provide details about the As for a version check - looks like you may be right. YAML support wasn't added until 0.10.10. I'll add in a version check. As for the long term plans for AppImage and Flatpak; for now, we're just adding Flatpak, and AppImage is remaining the default. However, AppImage tooling has proven a bit buggy, is being maintained by a very small team, and doesn't appear to have a huge amount of community support; whereas Flatpak has the full throated support of Redhat, Ubuntu, and others. If Flatpak gives us less headaches than AppImage, we'll likely change the default in future. The webkit thing, however, is... ugh. I don't know how to fix that. I'm guessing there's an SDK we need to include? |
Ahh...I didn't realize the template branch changed. That fixed it. |
|
Another thought....should we support the I can run it with |
|
I have no idea if using a flatpak of flatpak-builder is a good idea - but given that their own tutorial doesn't mention it, my inclination is to stick with what we know works. |
|
I see it referenced here....although the rest of their guide clearly doesn't assume you're using it.
As far as getting a current version of |
|
Looks like the Gnome runtime supports Webkit2 bindings. I guess it makes sense to use Gnome as a base for Toga apps, rather than a more generic FreeDesktop. |
|
Looks like something's wrong with the CI task "Desktop app verification (ubuntu-latest, toga)": it's been running for over an hour with no output. |
|
@mhsmith Yeah - looks like the GTK Linuxdeploy plugin doesn't like being run under CI... |
mhsmith
left a comment
There was a problem hiding this comment.
Commit d592a71 worked fine for me with the current version of the Flatpak template.
The main annoyance I had during this process was having to wait several minutes to recompile Python after every run of briefcase create. It seems like this is something which should be cached outside of the project tree, but I don't know how easy Flatpack would make that.
Of course, this is something that'll affect us developers more than normal users, so it doesn't need to block this PR.
| with pytest.raises( | ||
| BriefcaseConfigError, | ||
| match=r"", |
| with pytest.raises( | ||
| BriefcaseConfigError, | ||
| match=r"", |
| def test_custom_runtime_platform_only(first_app_config, tmp_path): | ||
| """If the user only defines a runtime, accessing the SDK raises an | ||
| error.""" |
There was a problem hiding this comment.
Shouldn't this be called test_custom_runtime_runtime_only?
| def test_verify_linux_no_docker(tmp_path): | ||
| """Verifying on Linux creates an SDK wrapper.""" |
There was a problem hiding this comment.
Docker shouldn't be mentioned here.
| def test_verify_non_linux_no_docker(tmp_path): | ||
| """Verifying on non-Linux raises an error.""" |
There was a problem hiding this comment.
Docker shouldn't be mentioned here.
|
Agreed that the recompilation of Python is annoying; however, I can't see any obvious way to exfiltrate the build products of that step in a way that can be re-used, and Flatpak doesn't appear to have (AFAICT) any concept of "modular" pieces to a build - you either build the entire source tree of every dependency, or you take responsibility for maintaining your own Runtime and SDK. However, as you note - this is something that we see because we recreate and recompile apps all the time, but most users won't need to rebuild apps as often. If we can find an optimisation in the future, it will be a huge win, but I don't think it's a blocker for now. |
Codecov Report
|
Adds a Flatpak backend as an alternative for Linux packaging.
To test:
Install
flatpakandflatpak-builderas Linux system packages. Installation instructions can be found on the flatpack website. On most systems, this should be as straightforward asapt-get install flatpak flatpack-builder(or whatever the OS-appropriate installer tool is).Add the following to the
linuxsection of yourpyproject.toml:Run
briefcase X linux flatpak(where X is create, build, run, or package)This PR doesn't deal with:
These would both be possible, but require building an integration with GPG, which is a whole integration unto itself.
Thanks to @loganasherjones for their extremely helpful blog post, and @nickzoic for an initial draft PR #754.
PR Checklist: