Skip to content

Commit

Permalink
Expose Python code generation via rosidl generate CLI
Browse files Browse the repository at this point in the history
Signed-off-by: Michel Hidalgo <[email protected]>
  • Loading branch information
hidmic committed Feb 9, 2021
1 parent eb8d406 commit b413229
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions rosidl_generator_py/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<buildtool_export_depend>rosidl_typesupport_interface</buildtool_export_depend>

<exec_depend>python3-numpy</exec_depend>
<exec_depend>rosidl_cli</exec_depend>
<exec_depend>rosidl_generator_c</exec_depend>
<exec_depend>rosidl_parser</exec_depend>
<exec_depend>rosidl_runtime_c</exec_depend>
Expand Down
49 changes: 49 additions & 0 deletions rosidl_generator_py/rosidl_generator_py/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright 2021 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os

from ament_index_python import get_package_share_directory
from ament_index_python import get_resources

from rosidl_cli.command.generate.extensions import GenerateCommandExtension
from rosidl_cli.command.generate.helpers import legacy_generator_arguments_file

from rosidl_generator_py import generate_py


class GeneratePython(GenerateCommandExtension):

def generate(
self,
package_name,
interface_files,
include_paths,
output_path
):
package_share_path = \
get_package_share_directory(
'rosidl_generator_py'
)
templates_path = os.path.join(
package_share_path, 'resource'
)
typesupport_implementations = ['rosidl_typesupport_c']
typesupport_implementations.extend(get_resources('rosidl_typesupport_c'))
with legacy_generator_arguments_file(
package_name, interface_files,
include_paths, templates_path,
output_path
) as path_to_arguments_file:
generate_py(path_to_arguments_file, typesupport_implementations)
3 changes: 3 additions & 0 deletions rosidl_generator_py/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[options.entry_points]
rosidl_cli.command.generate.type_extensions =
py = rosidl_generator_py.cli:GeneratePython

0 comments on commit b413229

Please sign in to comment.