#!/usr/bin/python3.13

import argparse
import os
import sys

try:
    from rosidl_generator_py import generate_py
except ImportError:
    # modifying sys.path and importing the Python package with the same
    # name as this script does not work on Windows
    rosidl_generator_py_root = os.path.dirname(os.path.dirname(__file__))
    rosidl_generator_py_module = os.path.join(
        rosidl_generator_py_root, 'rosidl_generator_py', '__init__.py')
    if not os.path.exists(rosidl_generator_py_module):
        raise
    from importlib.machinery import SourceFileLoader

    loader = SourceFileLoader('rosidl_generator_py', rosidl_generator_py_module)
    rosidl_generator_py = loader.load_module()
    generate_py = rosidl_generator_py.generate_py


def main(argv=sys.argv[1:]):
    parser = argparse.ArgumentParser(description='Generate the Python ROS interfaces.')
    parser.add_argument(
        '--generator-arguments-file',
        required=True,
        help='The location of the file containing the generator arguments')
    parser.add_argument(
        '--typesupport-impls',
        required=True,
        help='All the available typesupport implementations')
    args = parser.parse_args(argv)

    generate_py(args.generator_arguments_file, args.typesupport_impls.split(';'))
    return 0

if __name__ == '__main__':
    sys.exit(main())
