@@ -240,7 +240,7 @@ def _get_standard_labware_definition(
240
240
)
241
241
242
242
namespace = namespace .lower ()
243
- def_path = _get_path_to_labware (load_name , namespace , checked_version )
243
+ def_path = _get_path_to_labware (load_name , namespace , version )
244
244
245
245
try :
246
246
with open (def_path , "rb" ) as f :
@@ -254,26 +254,31 @@ def _get_standard_labware_definition(
254
254
255
255
256
256
def _get_path_to_labware (
257
- load_name : str , namespace : str , version : int , base_path : Optional [Path ] = None
257
+ load_name : str ,
258
+ namespace : str ,
259
+ version : Optional [int ] = None ,
260
+ base_path : Optional [Path ] = None ,
258
261
) -> Path :
259
262
if namespace == OPENTRONS_NAMESPACE :
260
263
# all labware in OPENTRONS_NAMESPACE is stored in shared data
261
- schema_3_path = (
262
- get_shared_data_root ()
263
- / STANDARD_DEFS_PATH
264
- / "3"
265
- / load_name
266
- / f"{ version } .json"
267
- )
268
- schema_2_path = (
269
- get_shared_data_root ()
270
- / STANDARD_DEFS_PATH
271
- / "2"
272
- / load_name
273
- / f"{ version } .json"
274
- )
275
- return schema_3_path if schema_3_path .exists () else schema_2_path
264
+ schema_3_dir = get_shared_data_root () / STANDARD_DEFS_PATH / "3" / load_name
265
+ if schema_3_dir .exists ():
266
+ schema_3_files = os .listdir (schema_3_dir )
267
+ version_filename = f"{ version } .json" if version else max (schema_3_files )
268
+ schema_3_path = schema_3_dir / version_filename
269
+ return schema_3_path
270
+ else :
271
+ version_filename = f"{ version } .json" if version else "1.json"
272
+ schema_2_path = (
273
+ get_shared_data_root ()
274
+ / STANDARD_DEFS_PATH
275
+ / "2"
276
+ / load_name
277
+ / f"{ version_filename } .json"
278
+ )
279
+ return schema_2_path
276
280
if not base_path :
277
281
base_path = USER_DEFS_PATH
278
- def_path = base_path / namespace / load_name / f"{ version } .json"
282
+ version_filename = f"{ version } .json" if version else "1.json"
283
+ def_path = base_path / namespace / load_name / f"{ version_filename } .json"
279
284
return def_path
0 commit comments