scripts/generate-dependency-queue.py: rewrite
This commit is contained in:
parent
d759982853
commit
c65ddbf119
|
@ -4,15 +4,32 @@ import sys
|
|||
priority_queue = []
|
||||
packages = json.load(sys.stdin)["packages"]
|
||||
|
||||
def iter_packages(package_name):
|
||||
package = next((package for package in packages if package["name"] == package_name), None)
|
||||
if package is not None and package["source"] is None:
|
||||
for dependency in package["dependencies"]:
|
||||
iter_packages(dependency["name"])
|
||||
if package_name not in priority_queue:
|
||||
priority_queue.append(package_name)
|
||||
def sort_graph(unsorted):
|
||||
sorted = []
|
||||
while unsorted:
|
||||
deadlock = True
|
||||
for node, edges in list(unsorted.items()):
|
||||
for edge in edges:
|
||||
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")
|
||||
for package_name in priority_queue:
|
||||
package = next((package for package in packages if package["name"] == package_name), None)
|
||||
print(" ".join([package["name"], package["version"]]))
|
||||
packages_dict = {
|
||||
package["name"]: [
|
||||
dep["name"] for dep in package["dependencies"]
|
||||
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]))
|
||||
|
|
Loading…
Reference in New Issue