0

I have several launch files in my directory (e.g. "my_script.launch.py") and their content is pretty similar to this file:

import launch
import launch.actions
import launch.substitutions
import launch_ros.actions


def generate_launch_description():
    return launch.LaunchDescription([
        launch.actions.DeclareLaunchArgument(
            'node_prefix',
            default_value=[launch.substitutions.EnvironmentVariable('USER'), '_'],
            description='Prefix for node names'),
        launch_ros.actions.Node(
            package='demo_nodes_py', node_executable='talker', output='screen',
            node_name=[launch.substitutions.LaunchConfiguration('node_prefix'), 'talker']),
    ])

All of them have some imports at the top and a generate_launch_description() function, that returns an object which I want to inspect.

I want to implement this function

def get_generate_launch_description_per_path(path):
   pass

that executes the convenient function of the python file on that path and thus returns the LaunchDescription object so I can manipulate it afterwards. Any idea? Probably will need some kind of reflection or dynamic load.

JnxF
  • 121
  • 5
  • If your launch files are pretty much the same except some data values, you should just store the data in a separate file and using one launch script the reads the data based on some kind of ID it's passed and create and returns the `LaunchDescription` you want. Doing this is would be following the so-called [DRY Principle](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself), – martineau Feb 21 '20 at 11:25
  • @martineau This is part of the ROS architecture, so launch files have a fixed sctructure which I cannot change. I aim to build a linter that work *on top* of those files. – JnxF Feb 21 '20 at 12:07

0 Answers0