From 40d09048a1ea308b5fae8269b2fb51d67230e45f Mon Sep 17 00:00:00 2001 From: Ezra Brooks Date: Tue, 3 Nov 2026 13:53:30 -0700 Subject: [PATCH] conditional_python_dependency: needs_python override in pkg_additional_info package.xml doesn't always show that a package has Python content: moveit_task_constructor_core ships a CPython extension but depends on moveit_py / py_binding_tools, and plotjuggler embeds libpython without declaring any Python dependency. `needs_python: true|false` in pkg_additional_info.yaml now wins over the heuristic. --- vinca/recipes.py | 16 +++++++++++++++- vinca/test_recipes.py | 21 +++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/vinca/recipes.py b/vinca/recipes.py index f326762..47875bf 100644 --- a/vinca/recipes.py +++ b/vinca/recipes.py @@ -186,6 +186,20 @@ def _package_needs_python(package: catkin_pkg.package.Package, build_type: str) ) +def _needs_python( + shortname: str, + package: catkin_pkg.package.Package, + build_type: str, + vinca_conf: dict[str, Any], +) -> bool: + """``needs_python`` in pkg_additional_info.yaml wins over the heuristic, for + what package.xml can't show (e.g. a package that embeds libpython).""" + override = get_pkg_additional_info(shortname, vinca_conf).get("needs_python") + if override is not None: + return bool(override) + return _package_needs_python(package, build_type) + + def get_depmods( vinca_conf: dict[str, Any], package_name: str, distro: Distro ) -> tuple[Requirements, Requirements]: @@ -471,7 +485,7 @@ def generate_output( conditional_python = _conditional_python(vinca_conf) if not conditional_python or ( - not is_dummy and _package_needs_python(package, build_type) + not is_dummy and _needs_python(shortname, package, build_type, vinca_conf) ): python_dependencies = resolve_pkgname("python", vinca_conf, distro) output["requirements"]["run"].extend(python_dependencies) diff --git a/vinca/test_recipes.py b/vinca/test_recipes.py index 81bdf3d..75251c5 100644 --- a/vinca/test_recipes.py +++ b/vinca/test_recipes.py @@ -305,6 +305,27 @@ def test_needs_python_ament_python_build_type_gets_python_dependency(): assert _host_run_python_markers(output) == (True, True, True, True) +def test_needs_python_override_forces_python_dependency(): + # e.g. plotjuggler: embeds libpython without a Python-flavored dependency + output = build_conditional( + "demo", + depends=[("build_depend", "rclcpp")], + _pkg_additional_info={"demo": {"needs_python": True}}, + ) + + assert _host_run_python_markers(output) == (True, True, True, True) + + +def test_needs_python_override_drops_python_dependency(): + output = build_conditional( + "demo", + build_type="ament_python", + _pkg_additional_info={"demo": {"needs_python": False}}, + ) + + assert _host_run_python_markers(output) == (False, False, False, False) + + def test_needs_python_test_only_dependency_still_counts(): # A test-only dependency still means Python must be importable to run # the test suite during the build, so it counts too.