|
| 1 | +import json |
| 2 | +import requests |
| 3 | +import networkx as nx |
| 4 | + |
| 5 | +packages_to_migrate = ["libopencv"] |
| 6 | +distro = "noetic" |
| 7 | + |
| 8 | +arches = ["linux-64", "linux-aarch64", "win-64", "osx-64", "osx-arm64"] |
| 9 | +arches = ["linux-64"] |
| 10 | + |
| 11 | +for arch in arches: |
| 12 | + url = f"https://conda.anaconda.org/robostack/{arch}/repodata.json" |
| 13 | + print("URL: ", url) |
| 14 | + # return |
| 15 | + repodata = requests.get(url).json() |
| 16 | + packages = repodata["packages"] |
| 17 | + to_migrate = set() |
| 18 | + ros_pkgs = set() |
| 19 | + ros_prefix = f"ros-{distro}" |
| 20 | + for pkey in packages: |
| 21 | + if not pkey.startswith(ros_prefix): |
| 22 | + continue |
| 23 | + |
| 24 | + pname = pkey.rsplit('-', 2)[0] |
| 25 | + ros_pkgs.add(pname) |
| 26 | + |
| 27 | + p = packages[pkey] |
| 28 | + |
| 29 | + for d in p.get("depends", []): |
| 30 | + if d.split()[0] in packages_to_migrate: |
| 31 | + # print(f"need to migrate {pkey}") |
| 32 | + to_migrate.add(pname) |
| 33 | + |
| 34 | + # print(to_migrate) |
| 35 | + # print(ros_pkgs) |
| 36 | + |
| 37 | + latest = {} |
| 38 | + for pkg in ros_pkgs: |
| 39 | + current = current_version = None |
| 40 | + for pkey in packages: |
| 41 | + if packages[pkey]["name"] == pkg: |
| 42 | + tmp = packages[pkey]["version"].split('.') |
| 43 | + version = [] |
| 44 | + for el in tmp: |
| 45 | + if el.isdecimal(): |
| 46 | + version.append(int(el)) |
| 47 | + else: |
| 48 | + x = re.search(r'[^0-9]', version).start() |
| 49 | + version.append(int(el[:x])) |
| 50 | + |
| 51 | + version = tuple(version) |
| 52 | + |
| 53 | + if not current or version > current_version: |
| 54 | + current_version = version |
| 55 | + current = pkey |
| 56 | + latest[pkg] = current |
| 57 | + |
| 58 | + # print(latest) |
| 59 | + |
| 60 | + # now we can build the graph ... |
| 61 | + |
| 62 | + G = nx.DiGraph() |
| 63 | + for pkg, pkgkey in latest.items(): |
| 64 | + full_pkg = packages[pkgkey] |
| 65 | + for dep in full_pkg.get("depends", []): |
| 66 | + req = dep.split(' ')[0] |
| 67 | + G.add_node(pkg) |
| 68 | + if req.startswith(ros_prefix): |
| 69 | + G.add_edge(pkg, req) |
| 70 | + |
| 71 | + gsorted = nx.topological_sort(G) |
| 72 | + gsorted = list(reversed([g for g in gsorted])) |
| 73 | + |
| 74 | + to_migrate = sorted(to_migrate, key=lambda x: gsorted.index(x)) |
| 75 | + |
| 76 | + print("Sorted to migrate: ", to_migrate) |
| 77 | + |
| 78 | + # import matplotlib.pyplot as plt |
| 79 | + # nx.draw(G, with_labels=True, font_weight='bold') |
| 80 | + # plt.show() |
| 81 | + |
| 82 | + |
0 commit comments