1717import os
1818import pathlib
1919import tempfile
20+ from typing import Generator , List , Tuple
2021
2122
22- def package_name_from_interface_file_path (path ) :
23+ def package_name_from_interface_file_path (path : pathlib . Path ) -> str :
2324 """
2425 Derive ROS package name from a ROS interface definition file path.
2526
@@ -29,7 +30,7 @@ def package_name_from_interface_file_path(path):
2930 return pathlib .Path (os .path .abspath (path )).parents [1 ].name
3031
3132
32- def dependencies_from_include_paths (include_paths ) :
33+ def dependencies_from_include_paths (include_paths : List [ str ]) -> List [ str ] :
3334 """
3435 Collect dependencies' ROS interface definition files from include paths.
3536
@@ -45,7 +46,7 @@ def dependencies_from_include_paths(include_paths):
4546 })
4647
4748
48- def interface_path_as_tuple (path ) :
49+ def interface_path_as_tuple (path : str ) -> Tuple [ pathlib . Path , pathlib . Path ] :
4950 """
5051 Express interface definition file path as an (absolute prefix, relative path) tuple.
5152
@@ -61,41 +62,43 @@ def interface_path_as_tuple(path):
6162 """
6263 path_as_string = str (path )
6364 if ':' not in path_as_string :
64- prefix = pathlib .Path .cwd ()
65+ prefix_path = pathlib .Path .cwd ()
6566 else :
6667 prefix , _ , path = path_as_string .rpartition (':' )
67- prefix = pathlib .Path (os .path .abspath (prefix ))
68- path = pathlib .Path (path )
69- if path .is_absolute ():
68+ prefix_path = pathlib .Path (os .path .abspath (prefix ))
69+ path_as_path = pathlib .Path (path )
70+ if path_as_path .is_absolute ():
7071 raise ValueError ('Interface definition file path '
71- f"'{ path } ' cannot be absolute" )
72- return prefix , path
72+ f"'{ path_as_path } ' cannot be absolute" )
73+ return prefix_path , path_as_path
7374
7475
75- def idl_tuples_from_interface_files (interface_files ):
76+ def idl_tuples_from_interface_files (
77+ interface_files : List [str ]
78+ ) -> List [str ]:
7679 """
7780 Express ROS interface definition file paths as IDL tuples.
7881
7982 An IDL tuple is a relative path prefixed by an absolute path against
8083 which to resolve it followed by a colon ':'. This function then applies
8184 the same logic as `interface_path_as_tuple`.
8285 """
83- idl_tuples = []
84- for path in interface_files :
85- prefix , path = interface_path_as_tuple (path )
86+ idl_tuples : List [ str ] = []
87+ for interface_path in interface_files :
88+ prefix , path = interface_path_as_tuple (interface_path )
8689 idl_tuples .append (f'{ prefix } :{ path .as_posix ()} ' )
8790 return idl_tuples
8891
8992
9093@contextlib .contextmanager
9194def legacy_generator_arguments_file (
9295 * ,
93- package_name ,
94- interface_files ,
95- include_paths ,
96- templates_path ,
97- output_path
98- ):
96+ package_name : str ,
97+ interface_files : List [ str ] ,
98+ include_paths : List [ str ] ,
99+ templates_path : str ,
100+ output_path : str
101+ ) -> Generator [ str , None , None ] :
99102 """
100103 Generate a temporary rosidl generator arguments file.
101104
@@ -138,10 +141,10 @@ def legacy_generator_arguments_file(
138141
139142def generate_visibility_control_file (
140143 * ,
141- package_name ,
142- template_path ,
143- output_path
144- ):
144+ package_name : str ,
145+ template_path : str ,
146+ output_path : str
147+ ) -> None :
145148 """
146149 Generate a visibility control file from a template.
147150
0 commit comments