2024-05-16 06:01:10 +00:00
|
|
|
import json
|
|
|
|
import sys
|
|
|
|
|
2024-08-01 04:54:53 +00:00
|
|
|
# pipe `cargo metadata --format-version=1` into this
|
|
|
|
|
2024-05-16 06:01:10 +00:00
|
|
|
priority_queue = []
|
|
|
|
packages = json.load(sys.stdin)["packages"]
|
|
|
|
|
2024-05-16 18:56:31 +00:00
|
|
|
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
|
2024-05-16 06:01:10 +00:00
|
|
|
|
2024-05-16 18:56:31 +00:00
|
|
|
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]))
|