Lector icon indicating copy to clipboard operation
Lector copied to clipboard

Provide a Flatpak

Open ghost opened this issue 6 years ago • 14 comments

It would be nice if there would be a Flatpak available, there are already many programs that were submitted to Flathub (https://github.com/flathub/flathub/pulls), so I'd suggest to submit it to Flathub.

ghost avatar Mar 11 '18 09:03 ghost

I'll keep this in mind. Could you summarize flathub to me? Is it a build service or a repo or something similar?

BasioMeusPuga avatar Mar 11 '18 17:03 BasioMeusPuga

It's primary a repo for Flatpaks, but if you add a package you need to provide a Flatpak Builder manifest, so that it can be deterministically built (http://docs.flatpak.org/en/latest/manifests.html). The bot then makes the Flatpak. At best you try to make a Flatpak locally and then submit the manifest. There are already quite many apps available: https://flathub.org/apps/ The advantage of Flatpaks is that they can run on any Linux distro that provides a flatpak package, they also provide isolation if made correctly.

ghost avatar Mar 11 '18 21:03 ghost

I've started writing a manifest, but it doesn't find PyQt yet. I've taken the PyQt module from here: https://github.com/flathub/net.ankiweb.Anki/blob/b62bc0fea594df26fafd112d7d809cdb8782fa91/net.ankiweb.Anki.json#L72

{
	"app-id":"com.github.basiomeuspuga.Lector",
	"runtime":"org.kde.Platform",
	"runtime-version":"5.10",
	"sdk":"org.kde.Sdk",
	"command":"lector",
	"rename-icon":"focuswriter",
	"rename-desktop-file":"focuswriter.desktop",
	"rename-appdata-file":"focuswriter.appdata.xml",
	"finish-args":[
		"--socket=wayland",
		"--socket=x11",
		"--share=ipc"
	],
	"build-options":{
		"cflags":"-O2",
		"cxxflags":"-O2"
	},
	"modules":[
		{
			"name":"pyqt5",
			"config-opts":[
				"--disable-static",
				"--enable-x11"
			],
			"no-autogen":true,
			"buildsystem":"simple",
			"build-commands":[
				"python3 configure.py --assume-shared --confirm-license --no-designer-plugin --no-qml-plugin --sysroot=/app -w --sip=/app/bin/sip --sip-incdir=/app/include -verbose QMAKE_CFLAGS_RELEASE='-I/usr/include/python3.5m/' QMAKE_CXXFLAGS_RELEASE='-I/usr/include/python3.5m/'",
				"make -j `nproc`",
				"make install DESTDIR=/app"
			],
			"sources":[
				{
					"type":"archive",
					"url":"https://sourceforge.net/projects/pyqt/files/PyQt5/PyQt-5.10.1/PyQt5_gpl-5.10.1.tar.gz",
					"sha256":"9932e971e825ece4ea08f84ad95017837fa8f3f29c6b0496985fa1093661e9ef"
				}
			],
			"modules":[
				{
					"name":"sip",
					"sources":[
						{
							"type":"archive",
							"url":"https://sourceforge.net/projects/pyqt/files/sip/sip-4.19.8/sip-4.19.8.tar.gz",
							"sha256":"7eaf7a2ea7d4d38a56dd6d2506574464bddf7cf284c960801679942377c297bc"
						}
					],
					"buildsystem":"simple",
					"build-commands":[
						"python3 configure.py --bindir=/app/bin --destdir=/app/lib/python3.5/site-packages --incdir=/app/include --pyidir=/app/lib/python3.5/site-packages --sipdir=/app/share/sip",
						"make",
						"make install"
					],
					"cleanup":[
						"/bin",
						"/include"
					]
				}
			]
		},
		{
			"name":"beautifulsoup",
			"buildsystem":"simple",
			"sources":[
				{
					"type":"archive",
					"url":"https://pypi.python.org/packages/fa/8d/1d14391fdaed5abada4e0f63543fef49b8331a34ca60c88bd521bcf7f782/beautifulsoup4-4.6.0.tar.gz#md5=c17714d0f91a23b708a592cb3c697728",
					"sha256":"808b6ac932dccb0a4126558f7dfdcf41710dd44a4ef497a0bb59a77f9f078e89"
				}
			],
			"build-commands":[
				"python3 setup.py build",
				"python3 setup.py install --prefix=/app"
			]
		},
		{
			"name":"requests",
			"buildsystem":"simple",
			"build-commands":[
				"/usr/bin/pip3 --disable-pip-version-check install --prefix=/app --no-deps --verbose ."
			],
			"sources":[
				{
					"type":"archive",
					"url":"https://files.pythonhosted.org/packages/source/r/requests/requests-2.18.4.tar.gz",
					"sha256":"9c443e7324ba5b85070c4a818ade28bfabedf16ea10206da1132edaa6dda237e"
				}
			]
		},
		{
			"name":"lector",
			"buildsystem":"simple",
			"ensure-writable":[
				"/lib/python*/site-packages/easy-install.pth"
			],
			"sources":[
				{
					"type":"archive",
					"url":"https://github.com/BasioMeusPuga/Lector/archive/0.2.tar.gz",
					"sha256":"750e226c60fdcaf3459dfde829d8fb49ce75e7023ee51f43f6a375ddf5f2a1a5"
				}
			],
			"build-commands":[
				"python3 setup.py build",
				"python3 setup.py install --prefix=/app"
			]
		}
	]
}

Error message:

Searching for PyQt5>=5.10.1
Reading https://pypi.python.org/simple/PyQt5/
Download error on https://pypi.python.org/simple/PyQt5/: [Errno -3] Temporary failure in name resolution -- Some packages may not be found!
Couldn't find index page for 'PyQt5' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.python.org/simple/
Download error on https://pypi.python.org/simple/: [Errno -3] Temporary failure in name resolution -- Some packages may not be found!
No local packages or download links found for PyQt5>=5.10.1
error: Could not find suitable distribution for Requirement.parse('PyQt5>=5.10.1')

Alexander-Wilms avatar Mar 16 '18 18:03 Alexander-Wilms

This is very likely due to the setup.py reporting version information the way it does. I've since removed version checks from it.

Having said that, I'm a little out of my depth as far as Flatpaks go. I've been reading up and I think I understand the basics - enough to get this to start compiling, anyway. Thing is, it's taking really long and it's also compiling a lot of Qt modules I've no requirement of. Also, the manifest does not currently include references to poppler-qt5, and python-poppler-qt5. Those are needed for pdf support.

BasioMeusPuga avatar Mar 16 '18 19:03 BasioMeusPuga

I don't think there is any need to compile qt as it should be present as a part of KDE SDK and Platform. The other dependancies are just python so there is not need to compile them anyway, you could just download them from a fixed url and untar them. If you need any help let me know, I may be able to help.

adityashah1212 avatar Mar 16 '18 23:03 adityashah1212

PyQt is just Python bindings.

Alexander-Wilms avatar Mar 16 '18 23:03 Alexander-Wilms

Maybe that came out incorrectly. Yes, Qt is part of the KDE runtime. The compilation was for the PyQt bindings. That would be the .sip files in the PyQt5 tar mentioned above. I wonder if there's a flag to be set somewhere about which bindings to leave out.

This is important since I'm told Flathub requires software to be "stable" before being uploaded there. We are quite some way from that.

BasioMeusPuga avatar Mar 17 '18 05:03 BasioMeusPuga

No it doesn't exactly have to be stable, the way to say it is that it has to be reproducible. Something like a release or a commit should be fine. You can't use something like master though.

adityashah1212 avatar Mar 17 '18 05:03 adityashah1212

I'm afraid I'm not having much luck with this. If someone wants to help write a working manifest, well, beer is on me.

BasioMeusPuga avatar Mar 23 '18 05:03 BasioMeusPuga

If someone wants to pick this up, here's a manifest of another PyQt application: https://github.com/flathub/flathub/pull/317/files

Alexander-Wilms avatar Mar 23 '18 10:03 Alexander-Wilms

I've made some progress with this. Using https://pastebin.com/5PGZnMVm < this manifest, I get a running application. With the following caveats:

  • python-poppler-qt5 does not compile. It errors out with sip: Unable to find file "QtCore/QtCoremod.sip" . This means no pdf support.
  • The application does not have filesystem access. There is a --filesystem=host in the manifest.
  • The application swells to ~212 MB in size. This may be because I've had to include Python 3.6 since the 3.5 ostensibly included in the KDE SDK(?) runtime is at 3.5

BasioMeusPuga avatar Mar 24 '18 18:03 BasioMeusPuga

python-poppler-qt5 does not compile. It errors out with sip: Unable to find file "QtCore/QtCoremod.sip". This means no pdf support.

Not sure, on how to solve that. But a great way of trying to find a solution is too search the Flathub repos. For example: https://github.com/search?utf8=%E2%9C%93&q=org%3Aflathub+poppler&type=Code From that you can see on how other people added dependencies, so a great way of adding dependencies is just to copy these, as a template. For example: https://github.com/flathub/org.gnome.Evince/blob/8ca06821591b4cfdf52a5c9192067bed69f21c0c/org.gnome.Evince.json#L58 Which might help you in solving that. It sadly doesn't seem nobody has used python-poppler-qt5 dependency.

The application does not have filesystem access. There is a --filesystem=host in the manifest.

But this means that it would have full access to the FS, wouldn't it? See: http://docs.flatpak.org/en/latest/sandbox-permissions.html#filesystem-access From that: --filesystem=host - access all files on the host

The application swells to ~212 MB in size. This may be because I've had to include Python 3.6 since the 3.5 ostensibly included in the KDE SDK(?) runtime is at 3.5

You can run specific commands at startup when you start a Flatpak, so to run sh for the SDK itself use: flatpak run flatpak run --command=sh org.kde.Platform/x86_64/5.10. This allows you to see what is is included in a Flatpak, and it seems you're right it doesn't seem to include a Python 3.6 interpreter.

ghost avatar Mar 25 '18 18:03 ghost

The application does not have filesystem access. There is a --filesystem=host in the manifest. I don't know why it needs access to the entire fielsystem, but you should be able make it read-only if it absolutely necessary. Though I would say it is better way to avoid that.

Also do you absolutely need python 3.6, won't python 3.5 work. If so then you will have to compile python 3.6 as a part of the application. Also to add to what @Hyleus said about browsing the files, you should be able to look at how the /app directory would look like by browsing the directory that you give a parameter to flatpak-builder. The simple guide line to reduce the size would be to delete any doc related files, any headers and binaries provided as addons not needed by your app.

adityashah1212 avatar Mar 25 '18 19:03 adityashah1212

I don't know why it needs access to the entire fielsystem, but you should be able make it read-only if it absolutely necessary. Though I would say it is better way to avoid that.

For example what if I have a drive mounted over NFS or Samba? Or for example I access an other drive which isn't my main drive, so imo allowing access to the whole FS would maybe the right choice here in this case.

ghost avatar Mar 25 '18 19:03 ghost