@@ -49,7 +49,9 @@ def string(self, extension) -> str:
4949 def string_list (self , extension ) -> List [str ]:
5050 return [
5151 text
52- for text in (str (value ).strip () for value in self ._options .Extensions [extension ])
52+ for text in (
53+ str (value ).strip () for value in self ._options .Extensions [extension ]
54+ )
5355 if text
5456 ]
5557
@@ -88,7 +90,9 @@ def __init__(
8890 self ._package_name = package_name
8991 self ._proto_enums = proto_enums
9092 self ._context = context
91- self ._service_full_name = RequestContext .full_service_name (package_name , service .name )
93+ self ._service_full_name = RequestContext .full_service_name (
94+ package_name , service .name
95+ )
9296
9397 @classmethod
9498 def _options_view (cls , options ):
@@ -108,19 +112,28 @@ def _build(self) -> ServiceModel:
108112 opts_pb2 = get_arduino_opts_pb2 ()
109113 service_opts = self ._options_view (self ._service .options )
110114
111- ifc_header = service_opts .string (opts_pb2 .ifc_header_name ).strip () or f"{ self ._snake_case (self ._service .name )} _interface.hpp"
115+ ifc_header = (
116+ service_opts .string (opts_pb2 .ifc_header_name ).strip ()
117+ or f"{ self ._snake_case (self ._service .name )} _interface.hpp"
118+ )
112119 if ifc_header .endswith ("_interface.hpp" ):
113120 stem = ifc_header [: - len ("_interface.hpp" )]
114121 else :
115122 stem = PurePosixPath (ifc_header ).stem
116123
117124 options = self ._ResolvedServiceOptions (
118- ifc_name = service_opts .string (opts_pb2 .ifc_class_name ).strip () or f"{ self ._service .name } Interface" ,
119- api_name = service_opts .string (opts_pb2 .api_class_name ).strip () or f"{ self ._service .name } Api" ,
120- service_name = service_opts .string (opts_pb2 .service_class_name ).strip () or f"{ self ._service .name } Service" ,
121- service_impl_name = service_opts .string (opts_pb2 .service_impl_class_name ).strip ()
125+ ifc_name = service_opts .string (opts_pb2 .ifc_class_name ).strip ()
126+ or f"{ self ._service .name } Interface" ,
127+ api_name = service_opts .string (opts_pb2 .api_class_name ).strip ()
128+ or f"{ self ._service .name } Api" ,
129+ service_name = service_opts .string (opts_pb2 .service_class_name ).strip ()
130+ or f"{ self ._service .name } Service" ,
131+ service_impl_name = service_opts .string (
132+ opts_pb2 .service_impl_class_name
133+ ).strip ()
122134 or f"{ self ._service .name } ServiceImpl" ,
123- api_member_name = service_opts .string (opts_pb2 .api_member_name ).strip () or "api_" ,
135+ api_member_name = service_opts .string (opts_pb2 .api_member_name ).strip ()
136+ or "api_" ,
124137 generate_api = service_opts .bool (opts_pb2 .generate_api_class , False ),
125138 generate_service = service_opts .bool (opts_pb2 .generate_service_class , False ),
126139 generate_service_impl = service_opts .bool (
@@ -201,7 +214,9 @@ def _build(self) -> ServiceModel:
201214 if options .generate_api :
202215 service_impl_includes .insert (1 , api_header )
203216
204- namespace_name = "::" .join (part for part in self ._package_name .split ("." ) if part )
217+ namespace_name = "::" .join (
218+ part for part in self ._package_name .split ("." ) if part
219+ )
205220
206221 return ServiceModel (
207222 include_list = include_list ,
@@ -253,7 +268,9 @@ def _method_spec_from_descriptor(
253268 source_virtual = options .bool (opts_pb2 .source_virtual , True )
254269 emit_api = options .bool (opts_pb2 .emit_api , True )
255270 emit_service = options .bool (opts_pb2 .emit_service , True )
256- visibility = options .string (opts_pb2 .method_visibility ).strip ().lower () or "public"
271+ visibility = (
272+ options .string (opts_pb2 .method_visibility ).strip ().lower () or "public"
273+ )
257274 if visibility not in {"public" , "protected" , "private" }:
258275 raise ValueError (
259276 f"{ method .name } : unsupported method_visibility '{ visibility } ' "
@@ -264,11 +281,12 @@ def _method_spec_from_descriptor(
264281
265282 def resolve_field (field : FieldDescriptorProto ) -> Tuple [str , str ]:
266283 field_opts = cls ._options_view (field .options )
267- field_type = (
268- field_opts .string (opts_pb2 .cpp_type ).strip ()
269- or cls ._default_types .get (field .type , "int32_t" )
284+ field_type = field_opts .string (
285+ opts_pb2 .cpp_type
286+ ).strip () or cls ._default_types .get (field .type , "int32_t" )
287+ field_name = (
288+ field_opts .string (opts_pb2 .field_cpp_name ).strip () or field .name
270289 )
271- field_name = field_opts .string (opts_pb2 .field_cpp_name ).strip () or field .name
272290 return field_type , field_name
273291
274292 return_type = options .string (opts_pb2 .cpp_return ).strip ()
@@ -435,9 +453,13 @@ def _collect_lineage_includes(self, lineage: List[str]) -> List[str]:
435453 def _snake_case (name : str ) -> str :
436454 chars : List [str ] = []
437455 for index , char in enumerate (name ):
438- if char .isupper () and index > 0 and (
439- not name [index - 1 ].isupper ()
440- or (index + 1 < len (name ) and name [index + 1 ].islower ())
456+ if (
457+ char .isupper ()
458+ and index > 0
459+ and (
460+ not name [index - 1 ].isupper ()
461+ or (index + 1 < len (name ) and name [index + 1 ].islower ())
462+ )
441463 ):
442464 chars .append ("_" )
443465 chars .append (char .lower ())
@@ -458,7 +480,8 @@ def _build_planned_methods(
458480 in_ifc = spec .decl in own_virtual_decls ,
459481 in_api = spec .emit_api and spec .source_virtual ,
460482 in_service = in_service ,
461- in_service_impl = in_service and spec .call_name in service_impl_callable ,
483+ in_service_impl = in_service
484+ and spec .call_name in service_impl_callable ,
462485 )
463486 )
464487 return methods
0 commit comments