You are not logged in.

#1 2020-12-02 10:55:07

flying sheep
Member
Registered: 2012-02-29
Posts: 93

Script: rebuilding all your python AUR packages

Hi, I just encountered the problem that I have a lot of manually installed AUR Python packages, and some that are dependencies.
Since a new Python release breaks all of them, one needs to manually reinstall them, and I wanted to see in which order they need to be reinstalled.

This script uses the graphviz dot algorithm because I forgot how that layer concept is called in graph theory.
Basically it outputs directly installed packages, then dependencies of those, then dependencies of those …

import re
from subprocess import check_output

import networkx as nx
from networkx.drawing.nx_agraph import graphviz_layout

import matplotlib.pyplot as plt


def get_tree(package: str):
    edges = [
        l.split(' -> ') for l in
        check_output(['pactree', '--graph', package], encoding='utf-8').splitlines()
        if ' -> ' in l
    ]
    g = nx.DiGraph()
    for a, b in edges:
        a = re.sub(r'"([\w-]+)(?:>?=[\w.]+)?"', r'\1', a.strip())
        b = re.sub(r'"([\w-]+)(?:>?=[\w.]+)?".*', r'\1', b.strip())
        g.add_edge(a, b)
    return g

packages = check_output(['pacman', '-Qoq', '/usr/lib/python3.8/site-packages/'], encoding='utf-8').splitlines()
trees = list(map(get_tree, packages))

joined = nx.DiGraph()
joined.add_edges_from(e for g in trees for e in g.edges())
simplified = joined.subgraph(packages + ['START'])

# Comment this out if you don’t want to visualize it:
plt.figure(figsize=(15, 25))
nx.draw_networkx(simplified, graphviz_layout(simplified, 'dot', args='-Grankdir="LR"'), bbox={})

layers = {}
for name, (_, x) in graphviz_layout(simplified, 'dot').items():
    layers.setdefault(x, set()).add(name)
for l in sorted(layers, reverse=True)[1:]:
    print(*layers[l])
    print()

Offline

#2 2020-12-02 11:58:32

schard
Forum Moderator
From: Hannover
Registered: 2016-05-06
Posts: 2,127
Website

Re: Script: rebuilding all your python AUR packages

I just did it manually with my packages.
Fortunately only few of them has another custom package as a dependency.
Anyways, thanks for the script.


Inofficial first vice president of the Rust Evangelism Strike Force

Offline

Board footer

Powered by FluxBB