scripts/generate-dependency-queue.py: rewrite

This commit is contained in:
Ryan Heywood 2024-05-16 14:56:31 -04:00
parent d759982853
commit c65ddbf119
Signed by: ryan
GPG Key ID: 8E401478A3FBEF72
1 changed files with 28 additions and 11 deletions

View File

@ -4,15 +4,32 @@ import sys
priority_queue = [] priority_queue = []
packages = json.load(sys.stdin)["packages"] packages = json.load(sys.stdin)["packages"]
def iter_packages(package_name): def sort_graph(unsorted):
package = next((package for package in packages if package["name"] == package_name), None) sorted = []
if package is not None and package["source"] is None: while unsorted:
for dependency in package["dependencies"]: deadlock = True
iter_packages(dependency["name"]) for node, edges in list(unsorted.items()):
if package_name not in priority_queue: for edge in edges:
priority_queue.append(package_name) if edge in unsorted:
break
else:
del unsorted[node]
sorted.append((node, edges))
deadlock = False
if deadlock:
raise Exception("deadlock")
return sorted
iter_packages("keyfork") packages_dict = {
for package_name in priority_queue: package["name"]: [
package = next((package for package in packages if package["name"] == package_name), None) dep["name"] for dep in package["dependencies"]
print(" ".join([package["name"], package["version"]])) if dep["kind"] is None
]
for package in packages if package["source"] is None
}
# iter_packages("keyfork")
priority_queue = sort_graph(packages_dict.copy())
for key, _ in priority_queue:
version = next(p["version"] for p in packages if p["name"] == key)
print(" ".join([key, version]))