Amount of code developed by Purism for the L5

I got curious how much code Purism has developed for the Librem 5, so I wrote a little Python script to download the source code from the projects that Purism has created and run it through cloc and then sum the total.

So here is what I get:

$ python3 locPurism.py
Lines of code in Purism projects for the Librem 5:
	libhandy: 47730
	libadwaita: 51270
	calls: 20745
	chatty: 49661
	squeekboard: 17993
	libcall-ui: 4426
	phoc: 15277
	phosh: 48301
	feedbackd: 5970
	feedbackd-device-themes: 603
	gtherm: 1734
	haegtesse: 2105
	wys: 2442
Total lines of code: 268257

This excludes PO translation files and Markdown documentation files. Of course, a number of people outside of Purism have contributed to these projects, such as the GNOME community, Mobian, postmarketOS, etc., but I would guesstimate that to only be about 10% of the total. We also have to take into account the code that Purism has contributed to other projects (Linux kernel, wlroots, GTK and roughly 20 GTK/GNOME apps).

Over a quarter of a million lines of code is a pretty big contribution to the Linux ecosystem. When we consider that Purism is providing a way for the GTK/GNOME ecosystem to run on mobile devices and Phosh is now packaged in nearly every major distro family except Gentoo, Purism is making a huge contribution to Linux as a whole. Because of Purism’s dev work, Debian->Ubuntu->Mint, Fedora, openSUSE and Arch->Manjaro will be able to run on mobile devices that are supported by the Linux kernel. Of course, KDE Plasma Mobile and Lomiri are working on the same goal, but Phosh got packaged faster in the major distros, because it was designed as a thin overlay on top of a desktop stack, so it is easier to integrate in the desktop distros. Even people who use desktop GTK/GNOME are seeing the benefits of libhandy/libadwaita. Calls and Chats/Chatty are also going to be useful for many desktop users as well.

I thought I would mention this, because I see a lot of people bashing Purism on this forum lately, so it is important to keep in mind the positives, and not only focus on the negatives.

Below is the script, just in case anyone wants to run it in the future to see how much code has been added. If you want all the gory details, run it as: python3 locPurism.py -d

# locPurism.py counts lines of code developed by Purism for the Librem 5
#
# Author: Amos Batto <amosbatto@yahoo.com>
# License: public domain 
# Requires Python 3.6 or later. Needs the "cloc" package installed. In Debian family: sudo apt install cloc

import shutil, subprocess, tempfile, re, os, os.path, sys
from urllib.request import urlretrieve
from urllib.parse import urlparse


projectUrls = {
	"libhandy"   : "https://gitlab.gnome.org/GNOME/libhandy/-/archive/master/libhandy-master.tar.bz2",
	"libadwaita" : "https://gitlab.gnome.org/GNOME/libadwaita/-/archive/main/libadwaita-main.tar.bz2",
	"calls"      : "https://gitlab.gnome.org/GNOME/calls/-/archive/master/calls-master.tar.bz2",
	"chatty"     : "https://source.puri.sm/Librem5/chatty/-/archive/master/chatty-master.tar.bz2",
	"squeekboard": "https://gitlab.gnome.org/World/Phosh/squeekboard/-/archive/master/squeekboard-master.tar.bz2",
	"libcall-ui" : "https://gitlab.gnome.org/World/Phosh/libcall-ui/-/archive/main/libcall-ui-main.tar.bz2",
	"phoc"       : "https://gitlab.gnome.org/World/Phosh/phoc/-/archive/master/phoc-master.tar.bz2",
	"phosh"      : "https://gitlab.gnome.org/World/Phosh/phosh/-/archive/main/phosh-main.tar.bz2",
	"feedbackd"  : "https://source.puri.sm/Librem5/feedbackd/-/archive/master/feedbackd-master.tar.bz2",
	"feedbackd-device-themes": "https://source.puri.sm/Librem5/feedbackd-device-themes/-/archive/master/feedbackd-device-themes-master.tar.bz2",
	"gtherm"     : "https://source.puri.sm/Librem5/gtherm/-/archive/master/gtherm-master.tar.bz2",
	"haegtesse"  : "https://source.puri.sm/Librem5/haegtesse/-/archive/master/haegtesse-master.tar.bz2",
	"wys"        : "https://source.puri.sm/Librem5/wys/-/archive/master/wys-master.tar.bz2" 
}

def main():
	print("Lines of code in Purism's projects for the Librem 5:")
	
	totalLoc = 0; #running total of lines of code
	
	for projName, projUrl in projectUrls.items():
		
		tmpDir = tempfile.mkdtemp(prefix="loc-")
		
		a = urlparse(projUrl) 
		compressedFilename = os.path.basename(a.path)
		pathToFileName = os.path.join(tmpDir, compressedFilename)  
		fileName, headers = urlretrieve(projUrl, filename = pathToFileName)
		
		#Get the LOC sum:
		output = subprocess.check_output(["cloc", "--exclude-lang=Markdown,PO File", fileName])
		found = re.search( r'^SUM:.*?\s+(\d+)$', output.decode('utf-8'), re.M)
		
		if found:
			loc = int(found.group(1))
			totalLoc += loc
		else:
			print(f"Error: no SUM of the lines of code in {projName}.")
			sys.exit();
		
		if "-d" in sys.argv[1:] :
			print(projName)
			os.system("cloc --exclude-lang='PO File,Markdown' " + fileName); 
			print('');
		else:
			print(f"\t{projName}: {loc}")
		
		shutil.rmtree(tmpDir) 
	
	print("Total lines of code: " + str(totalLoc));
 
 
if __name__ == "__main__":
	main()
23 Likes

See also how much of the code is not upstreamed for Librem 5 yet:
https://mainline.space/

1 Like

@amosbatto So to be clear here: this only includes projects that Purism initiated?

Not projects that Purism contributed to; kernel, drivers, modemmanager, patches to existing apps, etc?

2 Likes

Impressive :sunglasses:

That refers to the code that (for different reasons) is not yet upstreamed to the mainline Linux kernel. At the moment it is around 35K lines of code.

A large chunk of it, 22K lines of code is de driver for the wifi/bt module. There will be a switch to the mainline one which will reduce 22K LOC from that diff.
Also the driver for the selfie cam was recently upstream to the linux-next branch which will lower that diff even more:

2 Likes

I guess they no longer pay in lines of code per hour.

1 Like

Only 32 SLOC/hour over the last 4 years divided by how many devs? :stuck_out_tongue:

1 Like

ok, gonna take that bait. Add to your math:

  • developers that also make contributions and also upstream patches to other projects that already exist, like: modemmanager, wlroots. geoclue, linux kernel and bunch of other apps.

Which I am kinda sure will add a few more lines of code. Considering that just for the Linux kernel the diff with Kernel 4.18.11 was 111501 lines of code that needed to be maintained, and now it is “only” 35K.
And the kernel is only one example. There are many others that add a lot of Lines of Code. But as menationed above this only has LoC for projects that Purism started, not pre-existing projects that Purism contributed to.

  • Also, with the help of other others upstreaming stuff to debian so that it is easier to maintain. And in the end also helps mobile based distributions
  • Troubleshooting and sometimes fixing issues reported by other distributions

Also did you subtracted hours to sleep and eat in your math?

:smiley:

4 Likes

Right. If we added all that code, it would be a lot more. But a lot harder to calculate all that.

I just added this article to my blog and made it clear that this is just projects that Purism started:

3 Likes

@amosbatto

r/Purism

You should replace your link to this one: https://teddit.net/r/Purism, to save people from the bloat of the Reddit website.

2 Likes

To be honest, in my experience the most time intensive tasks usually resulted in very low amount of code. Everyone can write a line of code, but is it the line that you need? :wink:

So honestly, LOC is a very poor metric that doesn’t really measure anything meaningful, but if we insist on counting it anyway then we should probably note that some projects like phoc or squeekboard were initially forked off some other projects, so even if they diverged significantly by now there’s probably still some non-negligible amount of inherited code there.

13 Likes

Yes, every developer knows that productivity is explicitly measured in lines of code per hour. /s

2 Likes

If you really want to take the bait, you can join me in the “Software Metrics” room on the librem.one matrix server. :wink:

My comment was more aimed at the irrelevant nature of SLOC, than to call the Purism devs slackers. :slight_smile:

1 Like

Unmarked sarcasm on the Internet? That’s risky! :smiley:

1 Like

@lwriemen ^^^ ya that kinda is risky! I am sorry for misunderstanding.

I didn’t realize that phoc was forked from a prior project. Can you provide a link to the previous project? I want to add that caveat to my blog article.

The stuck tongue wasn’t sufficient? Any smiley in a storm, I say. :smiley:

We have initially used a slightly patched copy of rootston with phosh, which then evolved into phoc which is slowly shedding its rootston heritage from the codebase now.

1 Like

@amosbatto I’d also like to point out this toot by mobian project.

1 Like

There’s no need to rely on probabilities, I actually checked that recently: https://fosstodon.org/@dcz/107434869735742522

The numbers seem a bit low but anyway.

3 Likes