Skip to content

Allow to specify a different build number for a single package and remove full_rebuild and skip_all_deps options #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 33 additions & 35 deletions vinca/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .distro import Distro

from vinca import config
from vinca.utils import get_repodata
from vinca.utils import get_repodata, get_pkg_build_number

unsatisfied_deps = set()
distro = None
Expand Down Expand Up @@ -218,6 +218,11 @@ def read_vinca_yaml(filepath):

vinca_conf["trigger_new_versions"] = vinca_conf.get("trigger_new_versions", False)

if (Path(filepath).parent / "pkg_additional_info.yaml").exists():
vinca_conf["_pkg_additional_info"] = yaml.load(open(Path(filepath).parent / "pkg_additional_info.yaml"))
else:
vinca_conf["_pkg_additional_info"] = {}

return vinca_conf


Expand Down Expand Up @@ -671,17 +676,16 @@ def get_selected_packages(distro, vinca_conf):
for i in vinca_conf["packages_select_by_deps"]:
i = i.replace("-", "_")
selected_packages = selected_packages.union([i])
if "skip_all_deps" not in vinca_conf or not vinca_conf["skip_all_deps"]:
if i in skipped_packages:
continue
try:
pkgs = distro.get_depends(i, ignore_pkgs=skipped_packages)
except KeyError:
# handle (rare) package names that use "-" as separator
pkgs = distro.get_depends(i.replace("_", "-"))
selected_packages.remove(i)
selected_packages.add(i.replace("_", "-"))
selected_packages = selected_packages.union(pkgs)
if i in skipped_packages:
continue
try:
pkgs = distro.get_depends(i, ignore_pkgs=skipped_packages)
except KeyError:
# handle (rare) package names that use "-" as separator
pkgs = distro.get_depends(i.replace("_", "-"))
selected_packages.remove(i)
selected_packages.add(i.replace("_", "-"))
selected_packages = selected_packages.union(pkgs)

result = sorted(list(selected_packages))
return result
Expand Down Expand Up @@ -864,6 +868,7 @@ def main():
base_dir = os.path.abspath(arguments.dir)
vinca_yaml = os.path.join(base_dir, "vinca.yaml")
vinca_conf = read_vinca_yaml(vinca_yaml)

snapshot = read_snapshot(arguments.snapshot)

from .template import generate_bld_ament_cmake
Expand Down Expand Up @@ -946,19 +951,19 @@ def main():
# only URLs
if "://" in fn:
selected_bn = vinca_conf.get("build_number", 0)
distro = vinca_conf["ros_distro"]
all_pkgs = repodata.get("packages", {})
all_pkgs.update(repodata.get("packages.conda", {}))
for pkg_name, pkg in all_pkgs.items():
if pkg_name.startswith(f"ros-{distro}"):
if pkg_name.rsplit("-", 2)[0] in additional_recipe_names:
print(
f"Skipping additional recipe for build number computation {pkg_name}"
)
continue
selected_bn = max(selected_bn, pkg["build_number"])

print(f"Selected build number: {selected_bn}")
if not vinca_conf.get("use_explicit_build_number", True):
distro = vinca_conf["ros_distro"]
all_pkgs = repodata.get("packages", {})
all_pkgs.update(repodata.get("packages.conda", {}))
for pkg_name, pkg in all_pkgs.items():
if pkg_name.startswith(f"ros-{distro}"):
if pkg_name.rsplit("-", 2)[0] in additional_recipe_names:
print(
f"Skipping additional recipe for build number computation {pkg_name}"
)
continue
selected_bn = max(selected_bn, pkg["build_number"])


explicitly_selected_pkgs = [
f"ros-{distro}-{pkg.replace('_', '-')}"
Expand All @@ -969,16 +974,9 @@ def main():
for _, pkg in all_pkgs.items():
is_built = False
if selected_bn is not None:
if vinca_conf.get("full_rebuild", True):
if pkg["build_number"] == selected_bn:
is_built = True
else:
# remove all packages except explicitly selected ones
if (
pkg["name"] not in explicitly_selected_pkgs
or pkg["build_number"] == selected_bn
):
is_built = True
pkg_build_number = get_pkg_build_number(selected_bn, pkg["name"], vinca_conf)
if pkg["build_number"] == pkg_build_number:
is_built = True
else:
is_built = True

Expand Down
1 change: 0 additions & 1 deletion vinca/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ def create_migration_instructions(arch, packages_to_migrate, trigger_branch):
print("Final names: ", ros_names)

vinca_conf["packages_select_by_deps"] = ros_names
vinca_conf["skip_all_deps"] = True
vinca_conf["is_migration"] = True
vinca_conf["skip_existing"] = []

Expand Down
7 changes: 4 additions & 3 deletions vinca/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from ruamel import yaml
from pathlib import Path

from vinca.utils import get_pkg_build_number

TEMPLATE = """\
# yaml-language-server: $schema=https://raw.githubusercontent.com/prefix-dev/recipe-format/main/schema.json

Expand Down Expand Up @@ -71,7 +73,6 @@ def copyfile_with_exec_permissions(source_file, destination_file):
os.chmod(destination_file, current_permissions | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)

def write_recipe(source, outputs, vinca_conf, single_file=True):
build_number = vinca_conf.get("build_number", 0)
# single_file = False
if single_file:
file = yaml.YAML()
Expand All @@ -84,7 +85,7 @@ def write_recipe(source, outputs, vinca_conf, single_file=True):
meta["package"]["version"] = f"{datetime.datetime.now():%Y.%m.%d}"
meta["recipe"] = meta["package"]
del meta["package"]
meta["build"]["number"] = build_number
meta["build"]["number"] = vinca_conf.get("build_number", 0)
meta["build"]["post_process"] = post_process_items
with open("recipe.yaml", "w") as stream:
file.dump(meta, stream)
Expand All @@ -102,7 +103,7 @@ def write_recipe(source, outputs, vinca_conf, single_file=True):
meta["package"]["name"] = o["package"]["name"]
meta["package"]["version"] = o["package"]["version"]

meta["build"]["number"] = build_number
meta["build"]["number"] = get_pkg_build_number(vinca_conf.get("build_number", 0), o["package"]["name"], vinca_conf)
meta["build"]["post_process"] = post_process_items

if test := vinca_conf["_tests"].get(o["package"]["name"]):
Expand Down
17 changes: 17 additions & 0 deletions vinca/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,20 @@ def get_repodata(url_or_path, platform=None):
with open(fn, "w") as fcache:
fcache.write(content.decode("utf-8"))
return json.loads(content)

def ensure_name_is_without_distro_prefix_and_with_underscores(name, vinca_conf):
"""
Ensure that the name is without distro prefix and with underscores
e.g. "ros-humble-pkg-name" -> "pkg_name"
"""
newname = name.replace("-", "_")
distro_prefix = "ros_" + vinca_conf.get("ros_distro") + "_"
if (newname.startswith(distro_prefix) ):
newname = newname.replace(distro_prefix, "")

return newname

def get_pkg_build_number(default_build_number, pkg_name, vinca_conf):
normalized_name = ensure_name_is_without_distro_prefix_and_with_underscores(pkg_name, vinca_conf)
pkg_additional_info = vinca_conf["_pkg_additional_info"].get(normalized_name, {})
return pkg_additional_info.get("build_number", default_build_number)