Skip to content

Fixes #359 - Implement Linux/Flatpak output for Briefcase#754

Closed
nickzoic wants to merge 7 commits into
beeware:mainfrom
nickzoic:nickzoic-linux-flatpak
Closed

Fixes #359 - Implement Linux/Flatpak output for Briefcase#754
nickzoic wants to merge 7 commits into
beeware:mainfrom
nickzoic:nickzoic-linux-flatpak

Conversation

@nickzoic

@nickzoic nickzoic commented Jun 3, 2022

Copy link
Copy Markdown

Following this comment by Russell I thought I'd have a look into packaging as Flatpak. This is kind of a workaround for #718 maybe, but also having support for multiple Linux packaging solutions is a good thing in its own right.

Early days yet and this is very much a work in progress.
It builds the helloworld app and that's about it!

Much more work needs to be done to generate a good Flatpak manifest from the information in the pyproject.toml file but I thought it would be nice to have a PR for this work to live in.

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

@nickzoic

nickzoic commented Jun 3, 2022

Copy link
Copy Markdown
Author

Next steps:

  • Fix the code style issues to make CI happy :-)
  • Generate more information for the FlatPak manifest directly from pyproject.toml
    • system_requires?
  • generate a requirements.txt from the requires sections for use by flatpack-pip-generator
  • add check / installer for tools (flatpak, flatpak-builder, flatpack-pip-generator)
  • Eliminate flatpak-pip-generator so manifest is created directly from pyproject.toml
    • it'd be helpful if this was a python library not an executable
    • an executable tool would be helpful for non-briefcase flatpak users though.

@danyeaw

danyeaw commented Jun 3, 2022

Copy link
Copy Markdown
Member

@nickzoic I am really excited about this feature!

Eliminate flatpak-pip-generator so manifest is created directly from pyproject.toml

When we were developing Flatpak support in Gaphor, we didn't have much luck with getting reliable builds using flatpak-pip-generator. Instead we created a simple bash script that pip installed the needed packages and then put them in to a manifest in the right format. You might be able to take some inspiration from this and implement something similar in Python.

@nickzoic

nickzoic commented Jun 3, 2022

Copy link
Copy Markdown
Author

When we were developing Flatpak support in Gaphor, we didn't have much luck with getting reliable builds using flatpak-pip-generator.

Yeah, I don't know if it'll prove to be a good approach. I just hand-created the requirements.txt for now, but had some issues with versioning I think, where the local build had 0.3.0dev34 and the flatpak build had 0.2.15 and that wasn't quite right, but hopefully that's resolvable.

I think if we were to use the flatpak-pip-generator -like approach we'd have to mostly rewrite it but it's a good start on manifest generation & I went with that for now in an attempt to get something at least partially working.

I'll have a look at your script too, thanks! Looks a lot simpler than what it's currently doing ...

# * flatpak-pip-generator is a python program which translates requirements.txt
# files into includable "python3-requirements.json" module *but* it isn't
# distributed on pypi, isn't a library and doesn't load pyproject.toml so I
# suspect we're better off doing this stuff here instead.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What Python version is being used here? One of the implied contracts of Briefcase packaging is that it uses the same Python version as the one doing the packaging. If I package this app on Ubuntu 22.04 (which uses Python 3.9 as a system Python IIRC), and then deploy on Fedora 28 which uses Python 3.6... what happens? What happens if my code uses the walrus operator? I'm not seeing anything in this flatpak definition that references a Python version.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, the python version comes from the flatpak "runtime", which is kind of a base image for the flatpak, itself also a flatpak.

The runtime is specified in the flatpak manifest https://github.com/beeware/briefcase/pull/754/files#diff-c3953738384a9db4f1f0e7c5000448f194a3906c3260fd510190dfb02a05d887R131-R136 ...
I'm just using an arbitrary one, but I'd considered using a --option to let the user choose one.

We could also pick the appropriate runtime to match the python version being used for packaging, plus it doesn't look too difficult to create custom runtimes based on the existing ones so we could make & publish our own ones per python version (though I haven't tried this yet)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the line between "tool provided by the Runtime" and "binary dependency required to make the app run"?

In particular - how would the introduction of something like #628 interact with the choice of runtime?

@codecov

codecov Bot commented Jun 4, 2022

Copy link
Copy Markdown

Codecov Report

Merging #754 (aabe485) into main (1e7d5b6) will decrease coverage by 0.92%.
The diff coverage is 56.52%.

❗ Current head aabe485 differs from pull request most recent head 7ca865e. Consider uploading reports for the commit 7ca865e to get more accurate results

Impacted Files Coverage Δ
src/briefcase/platforms/linux/flatpak.py 56.52% <56.52%> (ø)

"--socket=fallback-x11",
"--socket=wayland",
],
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be part of a flatpak template, or is doing this in code a conscious decision?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be templated instead (like linux/appimage is) but this was the quickest & simplest way to get a first implementation up and running as a proof of concept.

self.logger.info()
self.logger.info(f"[{app.app_name}] Building Flatpak...")
try:
self.subprocess.run(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this call need to be dockerized - if only so that we can guarantee the existence of flatpak-builder et al?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, maybe ... as you say, that way the dockerized build system is a known quantity. And have the same --no-docker flag as linux/appimage.

# * flatpak-pip-generator is a python program which translates requirements.txt
# files into includable "python3-requirements.json" module *but* it isn't
# distributed on pypi, isn't a library and doesn't load pyproject.toml so I
# suspect we're better off doing this stuff here instead.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the line between "tool provided by the Runtime" and "binary dependency required to make the app run"?

In particular - how would the introduction of something like #628 interact with the choice of runtime?

@freakboy3742 freakboy3742 changed the title Implement Linux/Flatpak output for Briefcase Fixes #359 - Implement Linux/Flatpak output for Briefcase Jun 16, 2022
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants