Skip to content

Commit 4cce522

Browse files
committed
add vinca-migrate function
1 parent 51976bf commit 4cce522

File tree

3 files changed

+146
-74
lines changed

3 files changed

+146
-74
lines changed

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ console_scripts =
4040
vinca-glab = vinca.generate_gitlab:main
4141
vinca-azure = vinca.generate_azure:main
4242
vinca-dot = vinca.generate_dot:main
43+
vinca-migrate = vinca.migrate:main
4344

4445
[flake8]
4546
import-order-style = google

vinca/generate_azure.py

Lines changed: 86 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -143,40 +143,6 @@ def literal_unicode_representer(dumper, data):
143143
parsed_args = None
144144

145145

146-
def parse_command_line(argv):
147-
parser = argparse.ArgumentParser(
148-
description="Conda recipe Azure pipeline generator for ROS packages"
149-
)
150-
151-
default_dir = "./recipes"
152-
parser.add_argument(
153-
"-d",
154-
"--dir",
155-
dest="dir",
156-
default=default_dir,
157-
help="The recipes directory to process (default: {}).".format(default_dir),
158-
)
159-
160-
parser.add_argument(
161-
"-t", "--trigger-branch", dest="trigger_branch", help="Trigger branch for Azure"
162-
)
163-
164-
parser.add_argument(
165-
"-p",
166-
"--platform",
167-
dest="platform",
168-
default="linux-64",
169-
help="Platform to emit build pipeline for",
170-
)
171-
172-
parser.add_argument(
173-
"-a", "--additional-recipes", action="store_true", help="search for additional_recipes folder?")
174-
175-
arguments = parser.parse_args(argv[1:])
176-
global parsed_args
177-
parsed_args = arguments
178-
return arguments
179-
180146

181147
def normalize_name(s):
182148
s = s.replace("-", "_")
@@ -197,6 +163,7 @@ def chunks(lst, n):
197163
"""Yield successive n-sized chunks from lst."""
198164
for i in range(0, len(lst), n):
199165
yield lst[i:i + n]
166+
200167
i = 0
201168
while i < len(stages):
202169
for build_individually_pkg in build_individually:
@@ -247,8 +214,8 @@ def get_skip_existing(vinca_conf, platform):
247214

248215
return repodatas
249216

250-
def add_additional_recipes(args):
251-
additional_recipes_path = os.path.abspath(os.path.join(args.dir, '..', 'additional_recipes'))
217+
def add_additional_recipes(recipe_dir, platform):
218+
additional_recipes_path = os.path.abspath(os.path.join(recipe_dir, '..', 'additional_recipes'))
252219

253220
print("Searching additional recipes in ", additional_recipes_path)
254221

@@ -258,7 +225,10 @@ def add_additional_recipes(args):
258225
with open("vinca.yaml", "r") as vinca_yaml:
259226
vinca_conf = yaml.safe_load(vinca_yaml)
260227

261-
repodatas = get_skip_existing(vinca_conf, args.platform)
228+
if vinca_conf.get("is_migration"):
229+
return
230+
231+
repodatas = get_skip_existing(vinca_conf, platform)
262232

263233
for recipe_path in glob.glob(additional_recipes_path + '/**/recipe.yaml'):
264234
with open(recipe_path) as recipe:
@@ -276,7 +246,7 @@ def add_additional_recipes(args):
276246

277247
if not skip:
278248
print("Adding ", os.path.dirname(recipe_path))
279-
goal_folder = os.path.join(args.dir, name)
249+
goal_folder = os.path.join(recipe_dir, name)
280250
os.makedirs(goal_folder, exist_ok=True)
281251
copy_tree(os.path.dirname(recipe_path), goal_folder)
282252

@@ -521,7 +491,7 @@ def build_osx_arm64(stages, trigger_branch):
521491
fo.write(yaml.dump(azure_template, sort_keys=False))
522492

523493

524-
def extend_graph(graph, arch='linux-64'):
494+
def extend_graph(graph, arch='linux-64', distro='noetic'):
525495
url = f"https://conda.anaconda.org/robostack/{arch}/repodata.json"
526496
repodata = requests.get(url).json()
527497

@@ -567,19 +537,9 @@ def extend_graph(graph, arch='linux-64'):
567537
if req.startswith(ros_prefix):
568538
graph.add_edge(pkg, req)
569539

570-
def main():
571-
572-
args = parse_command_line(sys.argv)
573-
540+
def generate_pipeline(recipe_dir, platform, trigger_branch, sequential=False):
574541
metas = []
575-
576-
if args.additional_recipes:
577-
add_additional_recipes(args)
578-
579-
if not os.path.exists(args.dir):
580-
print(f"{args.dir} not found. Not generating a pipeline.")
581-
582-
all_recipes = glob.glob(os.path.join(args.dir, "**", "*.yaml"))
542+
all_recipes = glob.glob(os.path.join(recipe_dir, "**", "*.yaml"))
583543
for f in all_recipes:
584544
with open(f) as fi:
585545
metas.append(yaml.safe_load(fi.read()))
@@ -601,7 +561,7 @@ def main():
601561
if r.startswith("ros-"):
602562
G.add_edge(pkg, r)
603563

604-
extend_graph(G, arch=args.platform)
564+
extend_graph(G, arch=platform)
605565
# import matplotlib.pyplot as plt
606566
# nx.draw(G, with_labels=True, font_weight='bold')
607567
# plt.show()
@@ -656,16 +616,77 @@ def main():
656616
if len(filtered):
657617
filtered_stages.append(filtered)
658618

659-
stages = batch_stages(filtered_stages)
660-
print(stages)
661-
662-
if args.platform == "linux-64":
663-
build_linux(stages, args.trigger_branch)
664-
elif args.platform == "linux-aarch64":
665-
build_linux_aarch64(stages, args.trigger_branch)
666-
elif args.platform == "osx-64":
667-
build_osx(stages, args.trigger_branch)
668-
elif args.platform == "osx-arm64":
669-
build_osx_arm64(stages, args.trigger_branch)
670-
elif args.platform == "win-64":
671-
build_win(stages, args.trigger_branch)
619+
if sequential:
620+
single_stage = []
621+
for s in filtered_stages:
622+
single_stage.extend(s)
623+
stages = [[single_stage]]
624+
else:
625+
stages = batch_stages(filtered_stages)
626+
627+
if platform == "linux-64":
628+
build_linux(stages, trigger_branch)
629+
elif platform == "linux-aarch64":
630+
build_linux_aarch64(stages, trigger_branch)
631+
elif platform == "osx-64":
632+
build_osx(stages, trigger_branch)
633+
elif platform == "osx-arm64":
634+
build_osx_arm64(stages, trigger_branch)
635+
elif platform == "win-64":
636+
build_win(stages, trigger_branch)
637+
638+
639+
def parse_command_line(argv):
640+
parser = argparse.ArgumentParser(
641+
description="Conda recipe Azure pipeline generator for ROS packages"
642+
)
643+
644+
default_dir = "./recipes"
645+
parser.add_argument(
646+
"-d",
647+
"--dir",
648+
dest="dir",
649+
default=default_dir,
650+
help="The recipes directory to process (default: {}).".format(default_dir),
651+
)
652+
parser.add_argument(
653+
"--sequential",
654+
dest="sequential",
655+
action="store_true",
656+
help="Don't parallelize stages",
657+
)
658+
parser.add_argument(
659+
"-t", "--trigger-branch", dest="trigger_branch", help="Trigger branch for Azure"
660+
)
661+
662+
parser.add_argument(
663+
"-p",
664+
"--platform",
665+
dest="platform",
666+
default="linux-64",
667+
help="Platform to emit build pipeline for",
668+
)
669+
670+
parser.add_argument(
671+
"-a", "--additional-recipes", action="store_true", help="search for additional_recipes folder?")
672+
673+
arguments = parser.parse_args(argv[1:])
674+
global parsed_args
675+
parsed_args = arguments
676+
return arguments
677+
678+
679+
def main():
680+
681+
args = parse_command_line(sys.argv)
682+
683+
metas = []
684+
685+
if not os.path.exists(args.dir):
686+
print(f"{args.dir} not found. Not generating a pipeline.")
687+
return
688+
689+
if args.additional_recipes:
690+
add_additional_recipes(args.dir, args.platform)
691+
692+
generate_pipeline(args.dir, args.platform, args.trigger_branch, args.sequential)

vinca/migrate.py

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
import json
1+
import yaml
2+
import sys, os
3+
import glob
4+
import argparse
25
import requests
36
import networkx as nx
7+
import subprocess
8+
import shutil
49

510
from vinca.distro import Distro
611

@@ -9,7 +14,6 @@
914
ros_prefix = f"ros-{distro_version}"
1015

1116
arches = ["linux-64", "linux-aarch64", "win-64", "osx-64", "osx-arm64"]
12-
arches = ["linux-64"]
1317

1418
def to_ros_name(distro, pkg_name):
1519
shortname = pkg_name[len(ros_prefix) + 1:]
@@ -20,7 +24,7 @@ def to_ros_name(distro, pkg_name):
2024
else:
2125
raise RuntimeError(f"Couldnt convert {pkg_name} to ROS pkg name")
2226

23-
for arch in arches:
27+
def create_migration_instructions(arch, packages_to_migrate, trigger_branch):
2428
url = f"https://conda.anaconda.org/robostack/{arch}/repodata.json"
2529
print("URL: ", url)
2630
# return
@@ -102,11 +106,57 @@ def to_ros_name(distro, pkg_name):
102106

103107
vinca_conf["packages_select_by_deps"] = ros_names
104108
vinca_conf["skip_all_deps"] = True
105-
with open("vinca_generated.yaml", "w") as fo:
106-
yaml.dump(vinca_conf, fo)
107-
108-
# import matplotlib.pyplot as plt
109-
# nx.draw(G, with_labels=True, font_weight='bold')
110-
# plt.show()
109+
vinca_conf["is_migration"] = True
111110

111+
with open("vinca.yaml", "w") as fo:
112+
yaml.dump(vinca_conf, fo)
112113

114+
if os.path.exists("recipes"):
115+
shutil.rmtree("recipes")
116+
117+
subprocess.check_call(["vinca", "-f", "vinca.yaml", "--multiple", "--platform", arch])
118+
subprocess.check_call(["vinca-azure", "--platform", arch, "--trigger-branch", "buildbranch_linux", "-d", "./recipes", "--additional-recipes", "--sequential"])
119+
120+
def parse_command_line(argv):
121+
parser = argparse.ArgumentParser(
122+
description="Conda recipe Azure pipeline generator for ROS packages"
123+
)
124+
125+
default_dir = "./recipes"
126+
parser.add_argument(
127+
"-d",
128+
"--dir",
129+
dest="dir",
130+
default=default_dir,
131+
help="The recipes directory to process (default: {}).".format(default_dir),
132+
)
133+
134+
parser.add_argument(
135+
"-t", "--trigger-branch", dest="trigger_branch", help="Trigger branch for Azure"
136+
)
137+
138+
parser.add_argument(
139+
"-p",
140+
"--platform",
141+
dest="platform",
142+
default="linux-64",
143+
help="Platform to emit build pipeline for",
144+
)
145+
146+
parser.add_argument(
147+
"-a", "--additional-recipes", action="store_true", help="search for additional_recipes folder?")
148+
149+
arguments = parser.parse_args(argv[1:])
150+
global parsed_args
151+
parsed_args = arguments
152+
return arguments
153+
154+
155+
def main():
156+
args = parse_command_line(sys.argv)
157+
158+
mfile = os.path.join(args.dir + "/migration.yaml")
159+
with open(mfile, "r") as fi:
160+
migration = yaml.safe_load(fi)
161+
print(migration)
162+
create_migration_instructions(args.platform, migration.get('packages', []), args.trigger_branch)

0 commit comments

Comments
 (0)