Skip to content

Refactor jig_auto_package python install to use ament_python_install_package #28

Description

@claudepad

Background

jig_auto_package.cmake currently installs the per-package Python tree by hand:

  • _jig_create_top_level_python_package writes a generated __init__.py and uses raw install(FILES …) to drop it under ${PYTHON_INSTALL_DIR}/${PROJECT_NAME}/.
  • _jig_generate_python_node does the same for each node's user .py files and the codegen output, again with raw install(FILES …).

ament_cmake_python only registers the pythonpath.sh / pythonpath.dsv environment hook from inside ament_python_install_package / ament_python_install_module. Neither of those is called by the auto-package flow, so the hook never gets registered.

This was invisible on jazzy/kilted because there PYTHON_INSTALL_DIR resolves to lib/python${PYV}/site-packages, which ament_export_pythonpath adds to PYTHONPATH by default. On humble, PYTHON_INSTALL_DIR resolves to local/lib/python3.10/dist-packages (Debian Python convention), which the default exported pythonpath hook does not cover — so source install/setup.bash left the package off PYTHONPATH and every launched Python node failed with ModuleNotFoundError: No module named '<pkg>'.

What we did as a stopgap

_jig_create_top_level_python_package now calls the private idempotent macro _ament_cmake_python_register_environment_hook() after the manual install. This is the same macro that ament_python_install_package uses internally, and its definition is identical across humble/jazzy/kilted in ament_cmake_python-extras.cmake. Verified: humble dagger run no longer reports No module named 'jig_example'.

That patch is tactical — it relies on a private ament macro and leaves the bespoke install flow in place.

What this ticket is for

Replace the manual install(FILES …) calls in _jig_create_top_level_python_package and _jig_generate_python_node with a single ament_python_install_package(\${PROJECT_NAME} PACKAGE_DIR <staging>) call.

Sketch

  1. Stage the assembled package tree under \${CMAKE_CURRENT_BINARY_DIR}/python_staging/\${PROJECT_NAME}/:
    • top-level generated __init__.py
    • <node>/ subdir per Python node containing user .py files (symlinked from source via file(CREATE_LINK … SYMBOLIC) to preserve --symlink-install ergonomics) and the codegen output (interface.py, parameters.py, _parameters.py, generated __init__.py).
  2. Redirect the per-node codegen add_custom_command outputs to write directly into the staging dir.
  3. Wrap the staging steps in an add_custom_target(jig_python_staging ALL DEPENDS …).
  4. Drop every Python install(FILES …) call from the two macros. Keep the wrapper-executable install (install(PROGRAMS … DESTINATION lib/\${PROJECT_NAME})) — that part is fine.
  5. Call ament_python_install_package(\${PROJECT_NAME} PACKAGE_DIR \${staging}/\${PROJECT_NAME}) once from jig_auto_package, before ament_auto_package.
  6. Remove the _ament_cmake_python_register_environment_hook() call added as the stopgap.

Why it's worth doing

  • Drops a dependency on a private _-prefixed ament macro (_ament_cmake_python_register_environment_hook). It's stable today but isn't API.
  • Aligns with the canonical ament path: setuptools-driven install, env hook auto-registered, future-distro-proof.
  • Reduces the surface area of bespoke CMake in the macro.
  • Sets us up to use SETUP_CFG / version metadata if we ever want to publish these as real wheels.

Acceptance criteria

  • dagger call build-and-test --src=. --ros-distro=humble passes (modulo unrelated humble-rclpy compat issues being tracked separately).
  • dagger call build-and-test --src=. --ros-distro=jazzy and …--ros-distro=kilted still pass.
  • colcon build --symlink-install then editing a nodes/<node>/<node>.py file in the source tree takes effect on the next test run without a rebuild.
  • share/<pkg>/environment/pythonpath.sh is generated for any package using jig_auto_package with Python nodes.
  • The _ament_cmake_python_register_environment_hook call and its TODO(jig#NN) comment are removed.

Pointers

  • Stopgap landed in jig/cmake/jig_auto_package.cmake (_jig_create_top_level_python_package macro).
  • Reference impl: ament_cmake_python/cmake/ament_python_install_package.cmake (humble & jazzy share the structure).
  • Branch where the bug surfaced: 23-humble-support (issue humble support #23).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions