bosdyn-mission 4.1.1__py3-none-any.whl → 5.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
bosdyn/mission/util.py CHANGED
@@ -4,11 +4,13 @@
4
4
  # is subject to the terms and conditions of the Boston Dynamics Software
5
5
  # Development Kit License (20191101-BDSDK-SL).
6
6
 
7
+ import collections
7
8
  import copy
8
9
  import json
9
10
  import logging
10
11
  import operator
11
12
  import re
13
+ import typing
12
14
  from builtins import str as text
13
15
  from typing import Dict, Union
14
16
 
@@ -180,40 +182,87 @@ def proto_from_tuple(tup, pack_nodes=True):
180
182
 
181
183
 
182
184
 
183
- def python_var_to_value(var):
185
+ def python_var_to_value(var) -> util_pb2.ConstantValue:
184
186
  """Returns a ConstantValue with the appropriate oneof set."""
185
187
  value = util_pb2.ConstantValue()
186
- if isinstance(var, bool):
187
- value.bool_value = var
188
- elif isinstance(var, int):
189
- value.int_value = var
190
- elif isinstance(var, float):
191
- value.float_value = var
192
- elif isinstance(var, str):
193
- value.string_value = var
194
- elif isinstance(var, google.protobuf.message.Message):
195
- value.msg_value.Pack(var)
196
- else:
197
- raise Error('Invalid type "{}"'.format(type(var)))
188
+ match var:
189
+ case bool():
190
+ value.bool_value = var
191
+ case int():
192
+ value.int_value = var
193
+ case float():
194
+ value.float_value = var
195
+ case str():
196
+ value.string_value = var
197
+ case util_pb2.ConstantValue():
198
+ value.CopyFrom(var)
199
+ case google.protobuf.message.Message():
200
+ value.msg_value.Pack(var)
201
+ case _:
202
+ if isinstance(var, collections.abc.Mapping):
203
+ for key, val in var.items():
204
+ value.dict_value.values[key].CopyFrom(python_var_to_value(val))
205
+ elif isinstance(var, collections.abc.Iterable):
206
+ value.list_value.values.extend([python_var_to_value(v) for v in var])
207
+ else:
208
+ raise Error('Invalid type "{}"'.format(type(var)))
198
209
  return value
199
210
 
200
211
 
201
- def python_type_to_pb_type(var):
212
+ def python_type_to_pb_type(var) -> util_pb2.VariableDeclaration.Type.ValueType:
202
213
  """Returns the protobuf-schema variable type that corresponds to the given variable."""
203
- if isinstance(var, bool):
204
- return util_pb2.VariableDeclaration.TYPE_BOOL
205
- elif isinstance(var, int):
206
- return util_pb2.VariableDeclaration.TYPE_INT
207
- elif isinstance(var, float):
208
- # Python floating point is typically a C double.
209
- return util_pb2.VariableDeclaration.TYPE_FLOAT
210
- elif isinstance(var, str):
211
- return util_pb2.VariableDeclaration.TYPE_STRING
212
- elif isinstance(var, google.protobuf.message.Message):
213
- return util_pb2.VariableDeclaration.TYPE_MESSAGE
214
+ match var:
215
+ case bool():
216
+ return util_pb2.VariableDeclaration.TYPE_BOOL
217
+ case int():
218
+ return util_pb2.VariableDeclaration.TYPE_INT
219
+ case float():
220
+ return util_pb2.VariableDeclaration.TYPE_FLOAT
221
+ case str():
222
+ return util_pb2.VariableDeclaration.TYPE_STRING
223
+ # Special case for List and Dict value to allow using this function
224
+ # with ConstantValue.WhichOneof() to return the correct pb type.
225
+ case util_pb2.ConstantValue.ListValue():
226
+ return util_pb2.VariableDeclaration.TYPE_LIST
227
+ case util_pb2.ConstantValue.DictValue():
228
+ return util_pb2.VariableDeclaration.TYPE_DICT
229
+ case google.protobuf.message.Message():
230
+ return util_pb2.VariableDeclaration.TYPE_MESSAGE
231
+ case _:
232
+ if isinstance(var, collections.abc.Mapping):
233
+ return util_pb2.VariableDeclaration.TYPE_DICT
234
+ elif isinstance(var, collections.abc.Iterable):
235
+ return util_pb2.VariableDeclaration.TYPE_LIST
214
236
  raise InvalidConversion(var, util_pb2.VariableDeclaration.Type.DESCRIPTOR.full_name)
215
237
 
216
238
 
239
+ def python_type_to_variable_decl_info(
240
+ var) -> typing.Tuple[int, util_pb2.VariableDeclaration.SubType | None]:
241
+ var_type = python_type_to_pb_type(var)
242
+ sub_type = None
243
+ match var_type:
244
+ case util_pb2.VariableDeclaration.TYPE_LIST:
245
+ if len(var) != 0:
246
+ sub_var_type, sub_recurse = python_type_to_variable_decl_info(var[0])
247
+ sub_type = util_pb2.VariableDeclaration.SubType(type=sub_var_type,
248
+ sub_type=sub_recurse)
249
+ case util_pb2.VariableDeclaration.TYPE_DICT:
250
+ if len(var) != 0:
251
+ sub_var_type, sub_recurse = python_type_to_variable_decl_info(
252
+ next(iter(var.values())))
253
+ sub_type = util_pb2.VariableDeclaration.SubType(type=sub_var_type,
254
+ sub_type=sub_recurse)
255
+ case _:
256
+ pass
257
+ return var_type, sub_type
258
+
259
+
260
+ def python_var_to_variable_decl(var,
261
+ name: typing.Optional[str] = None) -> util_pb2.VariableDeclaration:
262
+ var_type, sub_type = python_type_to_variable_decl_info(var)
263
+ return util_pb2.VariableDeclaration(type=var_type, sub_type=sub_type, name=name)
264
+
265
+
217
266
  def is_string_identifier(string):
218
267
  if hasattr(string, 'isidentifier'):
219
268
  return string.isidentifier()
@@ -222,10 +271,13 @@ def is_string_identifier(string):
222
271
 
223
272
  def field_desc_to_pb_type(field_desc):
224
273
  """Returns the protobuf-schema variable type that corresponds to the given descriptor."""
225
- if field_desc.type in (field_desc.TYPE_UINT32, field_desc.TYPE_UINT64, field_desc.TYPE_FIXED32,
226
- field_desc.TYPE_FIXED64, field_desc.TYPE_INT32, field_desc.TYPE_INT64,
227
- field_desc.TYPE_SFIXED64, field_desc.TYPE_SINT32, field_desc.TYPE_SINT64,
228
- field_desc.TYPE_SFIXED32):
274
+ if field.label == FieldDescriptor.LABEL_REPEATED:
275
+ return util_pb2.VariableDeclaration.TYPE_LIST
276
+ elif field_desc.type in (field_desc.TYPE_UINT32, field_desc.TYPE_UINT64,
277
+ field_desc.TYPE_FIXED32, field_desc.TYPE_FIXED64,
278
+ field_desc.TYPE_INT32, field_desc.TYPE_INT64, field_desc.TYPE_SFIXED64,
279
+ field_desc.TYPE_SINT32, field_desc.TYPE_SINT64,
280
+ field_desc.TYPE_SFIXED32):
229
281
  return util_pb2.VariableDeclaration.TYPE_INT
230
282
  elif field_desc.type in (field_desc.TYPE_DOUBLE, field_desc.TYPE_FLOAT):
231
283
  return util_pb2.VariableDeclaration.TYPE_FLOAT
@@ -234,6 +286,8 @@ def field_desc_to_pb_type(field_desc):
234
286
  elif field_desc.type == field_desc.TYPE_STRING:
235
287
  return util_pb2.VariableDeclaration.TYPE_STRING
236
288
  elif field_desc.type == field_desc.TYPE_MESSAGE:
289
+ if field.message_type.GetOptions().map_entry:
290
+ return util_pb2.VariableDeclaration.TYPE_DICT
237
291
  return util_pb2.VariableDeclaration.TYPE_MESSAGE
238
292
  raise InvalidConversion(field_desc.type, util_pb2.VariableDeclaration.Type.DESCRIPTOR.full_name)
239
293
 
@@ -359,7 +413,8 @@ safe_pb_enum_to_string = moved_to(_bosdyn_client_safe_pb_enum_to_string, version
359
413
 
360
414
 
361
415
  def create_value(
362
- var: Union[bool, int, float, str, google.protobuf.message.Message]) -> util_pb2.Value:
416
+ var: Union[bool, int, float, str, google.protobuf.message.Message, list,
417
+ dict]) -> util_pb2.Value:
363
418
  """Returns a Value message containing a ConstantValue with the appropriate oneof set.
364
419
  """
365
420
  return util_pb2.Value(constant=python_var_to_value(var))
@@ -1,22 +1,22 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: bosdyn-mission
3
- Version: 4.1.1
3
+ Version: 5.0.0
4
4
  Summary: Boston Dynamics mission code
5
5
  Home-page: https://dev.bostondynamics.com/
6
6
  Author: Boston Dynamics
7
7
  Author-email: support@bostondynamics.com
8
8
  Project-URL: Documentation, https://dev.bostondynamics.com/
9
9
  Project-URL: Source, https://github.com/boston-dynamics/spot-sdk/
10
- Classifier: Programming Language :: Python :: 3.6
11
10
  Classifier: Programming Language :: Python :: 3.7
12
11
  Classifier: Programming Language :: Python :: 3.8
13
12
  Classifier: Programming Language :: Python :: 3.9
14
13
  Classifier: Programming Language :: Python :: 3.10
15
14
  Classifier: License :: Other/Proprietary License
16
15
  Classifier: Operating System :: OS Independent
16
+ Requires-Python: >=3.7
17
17
  Description-Content-Type: text/markdown
18
- Requires-Dist: bosdyn-client (==4.1.1)
19
- Requires-Dist: bosdyn-api (==4.1.1)
18
+ Requires-Dist: bosdyn-client (==5.0.0)
19
+ Requires-Dist: bosdyn-api (==5.0.0)
20
20
 
21
21
  <!--
22
22
  Copyright (c) 2023 Boston Dynamics, Inc. All rights reserved.
@@ -5,8 +5,8 @@ bosdyn/mission/constants.py,sha256=oSsl0XR1-fNzHASGNqs541YEO8qi64eewvbY9ICKaxE,4
5
5
  bosdyn/mission/exceptions.py,sha256=UqGT0XK3zA6Bgwo_7KNC44yi_MvW9h3c8_pHKML8ELQ,3941
6
6
  bosdyn/mission/remote_client.py,sha256=quGWyqLzpASgrR6MlnEPoRFCmnTMSBZ6tmr-Wyy9YW0,12190
7
7
  bosdyn/mission/server_util.py,sha256=xd9D5VwP6mjbxUcUGCV4gN2AvsmRpL9wyvMpKR6Bmxk,1505
8
- bosdyn/mission/util.py,sha256=JzufUi49GwganMKR5L03X1j-rp3clt1tObhS3nofGNs,16938
9
- bosdyn_mission-4.1.1.dist-info/METADATA,sha256=xy4YS79GpBMgndsSsw3iiWrWf-0gvCSO5FLcvKsLOz8,1760
10
- bosdyn_mission-4.1.1.dist-info/WHEEL,sha256=AtBG6SXL3KF_v0NxLf0ehyVOh0cold-JbJYXNGorC6Q,92
11
- bosdyn_mission-4.1.1.dist-info/top_level.txt,sha256=an2OWgx1ej2jFjmBjPWNQ68ZglvUfKhmXWW-WhTtDmA,7
12
- bosdyn_mission-4.1.1.dist-info/RECORD,,
8
+ bosdyn/mission/util.py,sha256=UViwcp0BXPI7JM43OYxuLb63w8a6U03xf4xfm98Mx_0,19556
9
+ bosdyn_mission-5.0.0.dist-info/METADATA,sha256=FaQGhpKx0Ppkm4mPn1YnRQYjYxtrpQ6bbiovpVIDrdE,1733
10
+ bosdyn_mission-5.0.0.dist-info/WHEEL,sha256=AtBG6SXL3KF_v0NxLf0ehyVOh0cold-JbJYXNGorC6Q,92
11
+ bosdyn_mission-5.0.0.dist-info/top_level.txt,sha256=an2OWgx1ej2jFjmBjPWNQ68ZglvUfKhmXWW-WhTtDmA,7
12
+ bosdyn_mission-5.0.0.dist-info/RECORD,,