I've been writing an implementation of kiss in Lua, called bliss, and I just finished a pkg.order function, which performs a topological sort to order packages so that dependencies are built first. This function can also be used to get the full, recursive dependency list of a package, which I think is sort of interesting, so I wrote a quick script.

View the code
#!/usr/bin/env lua
-- Display all dependencies of packages (recursively)
local bliss = require "bliss"
local dirent = require "posix.dirent"

local function lists(env, arg)
    if #arg == 0 then
        for file in dirent.files(env.sys_db) do
            if string.sub(file, 1, 1) ~= "." then
                table.insert(arg, {file, #bliss.order(env, {file})})
        table.sort(arg, function (a,b) return a[2]<b[2] end)
        for _,v in ipairs(arg) do print(v[1],v[2]) end
        local deps = bliss.order(env, {arg[1]})
        for _,v in ipairs(deps) do print(v) end

if arg[1] == "-h" then
    print("usage: "..arg[0].." [pkg]")
    print("  With no args, list installed packages by total number of dependencies")
    print("  With an arg, list full dependencies of pkg")

local env, atexit = bliss.setup()
table.insert(env.PATH, 1, env.sys_db)

lists(env, arg)

Here's what you can do with it.

And no, it's not horribly slow: for my system, the former takes 150ms and the latter 6ms. The listing of all packages could be sped up by caching the dependency lists rather than walking through them all again for each package installed, but it's fast enough for me.

Here's a bar chart of number of total dependencies on my system:

bar chart
And here is a histogram of the same information, emphasizing how many just have 1 "dependency" (themselves).
histogram of the same data

written 2023-06-30


Blog home