bosdyn-mission 4.1.1__py3-none-any.whl → 5.0.1__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,7 +182,7 @@ 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
188
  if isinstance(var, bool):
@@ -191,29 +193,72 @@ def python_var_to_value(var):
191
193
  value.float_value = var
192
194
  elif isinstance(var, str):
193
195
  value.string_value = var
196
+ elif isinstance(var, util_pb2.ConstantValue):
197
+ value.CopyFrom(var)
194
198
  elif isinstance(var, google.protobuf.message.Message):
195
199
  value.msg_value.Pack(var)
200
+ elif isinstance(var, collections.abc.Mapping):
201
+ for key, val in var.items():
202
+ value.dict_value.values[key].CopyFrom(python_var_to_value(val))
203
+ elif isinstance(var, collections.abc.Iterable):
204
+ value.list_value.values.extend([python_var_to_value(v) for v in var])
196
205
  else:
197
206
  raise Error('Invalid type "{}"'.format(type(var)))
198
207
  return value
199
208
 
200
209
 
201
- def python_type_to_pb_type(var):
210
+ def python_type_to_pb_type(var) -> util_pb2.VariableDeclaration.Type.ValueType:
202
211
  """Returns the protobuf-schema variable type that corresponds to the given variable."""
203
212
  if isinstance(var, bool):
204
213
  return util_pb2.VariableDeclaration.TYPE_BOOL
205
214
  elif isinstance(var, int):
206
215
  return util_pb2.VariableDeclaration.TYPE_INT
207
216
  elif isinstance(var, float):
208
- # Python floating point is typically a C double.
209
217
  return util_pb2.VariableDeclaration.TYPE_FLOAT
210
218
  elif isinstance(var, str):
211
219
  return util_pb2.VariableDeclaration.TYPE_STRING
220
+ # Special case for List and Dict value to allow using this function
221
+ # with ConstantValue.WhichOneof() to return the correct pb type.
222
+ elif isinstance(var, util_pb2.ConstantValue.ListValue):
223
+ return util_pb2.VariableDeclaration.TYPE_LIST
224
+ elif isinstance(var, util_pb2.ConstantValue.DictValue):
225
+ return util_pb2.VariableDeclaration.TYPE_DICT
212
226
  elif isinstance(var, google.protobuf.message.Message):
213
227
  return util_pb2.VariableDeclaration.TYPE_MESSAGE
228
+ elif isinstance(var, collections.abc.Mapping):
229
+ return util_pb2.VariableDeclaration.TYPE_DICT
230
+ elif isinstance(var, collections.abc.Iterable):
231
+ return util_pb2.VariableDeclaration.TYPE_LIST
214
232
  raise InvalidConversion(var, util_pb2.VariableDeclaration.Type.DESCRIPTOR.full_name)
215
233
 
216
234
 
235
+ def python_type_to_variable_decl_info(
236
+ var) -> typing.Tuple[int, util_pb2.VariableDeclaration.SubType | None]:
237
+ var_type = python_type_to_pb_type(var)
238
+ sub_type = None
239
+ match var_type:
240
+ case util_pb2.VariableDeclaration.TYPE_LIST:
241
+ if len(var) != 0:
242
+ sub_var_type, sub_recurse = python_type_to_variable_decl_info(var[0])
243
+ sub_type = util_pb2.VariableDeclaration.SubType(type=sub_var_type,
244
+ sub_type=sub_recurse)
245
+ case util_pb2.VariableDeclaration.TYPE_DICT:
246
+ if len(var) != 0:
247
+ sub_var_type, sub_recurse = python_type_to_variable_decl_info(
248
+ next(iter(var.values())))
249
+ sub_type = util_pb2.VariableDeclaration.SubType(type=sub_var_type,
250
+ sub_type=sub_recurse)
251
+ case _:
252
+ pass
253
+ return var_type, sub_type
254
+
255
+
256
+ def python_var_to_variable_decl(var,
257
+ name: typing.Optional[str] = None) -> util_pb2.VariableDeclaration:
258
+ var_type, sub_type = python_type_to_variable_decl_info(var)
259
+ return util_pb2.VariableDeclaration(type=var_type, sub_type=sub_type, name=name)
260
+
261
+
217
262
  def is_string_identifier(string):
218
263
  if hasattr(string, 'isidentifier'):
219
264
  return string.isidentifier()
@@ -222,10 +267,13 @@ def is_string_identifier(string):
222
267
 
223
268
  def field_desc_to_pb_type(field_desc):
224
269
  """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):
270
+ if field.label == FieldDescriptor.LABEL_REPEATED:
271
+ return util_pb2.VariableDeclaration.TYPE_LIST
272
+ elif field_desc.type in (field_desc.TYPE_UINT32, field_desc.TYPE_UINT64,
273
+ field_desc.TYPE_FIXED32, field_desc.TYPE_FIXED64,
274
+ field_desc.TYPE_INT32, field_desc.TYPE_INT64, field_desc.TYPE_SFIXED64,
275
+ field_desc.TYPE_SINT32, field_desc.TYPE_SINT64,
276
+ field_desc.TYPE_SFIXED32):
229
277
  return util_pb2.VariableDeclaration.TYPE_INT
230
278
  elif field_desc.type in (field_desc.TYPE_DOUBLE, field_desc.TYPE_FLOAT):
231
279
  return util_pb2.VariableDeclaration.TYPE_FLOAT
@@ -234,6 +282,8 @@ def field_desc_to_pb_type(field_desc):
234
282
  elif field_desc.type == field_desc.TYPE_STRING:
235
283
  return util_pb2.VariableDeclaration.TYPE_STRING
236
284
  elif field_desc.type == field_desc.TYPE_MESSAGE:
285
+ if field.message_type.GetOptions().map_entry:
286
+ return util_pb2.VariableDeclaration.TYPE_DICT
237
287
  return util_pb2.VariableDeclaration.TYPE_MESSAGE
238
288
  raise InvalidConversion(field_desc.type, util_pb2.VariableDeclaration.Type.DESCRIPTOR.full_name)
239
289
 
@@ -359,7 +409,8 @@ safe_pb_enum_to_string = moved_to(_bosdyn_client_safe_pb_enum_to_string, version
359
409
 
360
410
 
361
411
  def create_value(
362
- var: Union[bool, int, float, str, google.protobuf.message.Message]) -> util_pb2.Value:
412
+ var: Union[bool, int, float, str, google.protobuf.message.Message, list,
413
+ dict]) -> util_pb2.Value:
363
414
  """Returns a Value message containing a ConstantValue with the appropriate oneof set.
364
415
  """
365
416
  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.1
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.1)
19
+ Requires-Dist: bosdyn-api (==5.0.1)
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=n7ODM0E-4I25BHutzV6ThrgmZHpkWB5YdXDYfexmxcc,19489
9
+ bosdyn_mission-5.0.1.dist-info/METADATA,sha256=ynX9UBtCLe-Mkd48quGZzW2IoffekWC2NGt5qB4HeYE,1733
10
+ bosdyn_mission-5.0.1.dist-info/WHEEL,sha256=AtBG6SXL3KF_v0NxLf0ehyVOh0cold-JbJYXNGorC6Q,92
11
+ bosdyn_mission-5.0.1.dist-info/top_level.txt,sha256=an2OWgx1ej2jFjmBjPWNQ68ZglvUfKhmXWW-WhTtDmA,7
12
+ bosdyn_mission-5.0.1.dist-info/RECORD,,