Skip to content

__init__.py is empty when uing colcon build and generate_parameter_library #255

Open
@val-ba

Description

@val-ba

When building with colcon build instead of colcon build --symlink-install, the init.py in the install folder is empty, even if originally it was not. If it is done with symlink, no problems arise, as it uses the init.py directly from the src folder.

To reproduce the issue with ros2 jazzy:

  • create a package: ros2 pkg create --build-type ament_python --license Apache-2.0 my_package
  • add the following lines to __init__.py in ~/colcon_ws/src/my_package/my_package:
print("Hello World")
  • create a config folder and place a yaml in there (for the parameter library):
    config/my_package_parameters.yaml:
my_package: base_footprint_frame: type: string default_value: base_footprint description: 'The frame of the robot base' read_only: true
  • In the setup.py add the following:
import glob generate_parameter_module( "my_package_parameters", # python module name for parameter library "config/my_package_parameters.yaml", # path to input yaml file ) package_name = 'my_package' setup( name=package_name, version='0.0.0', packages=find_packages(exclude=['test']), data_files=[ ('share/ament_index/resource_index/packages', ['resource/' + package_name]), ('share/' + package_name, ['package.xml']), ("share/" + package_name + "/config", glob.glob("config/*.yaml")), ], install_requires=['setuptools'],
  • Now delete build install log directories first and then build with `colcon build --packages-select my_package
  • Then when doing cat install/my_package/lib/python3.12/site-packages/my_package/__init__.py, it should show an empty file. If we do not perform the generate_parameter_module() method, it is not empty.

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