This PR adds a function load_from_string. For this, I have split up the existing load function.
Use case
Currently, if you want to modify a raillabel json file before loading it using raillabel's load, you have to save the modified json to disk first. Using load_from_string, you can skip creating a temporary file on disk.
Notes for reviewer
As a side effect of moving most of the code from load into load_from_string, the path variable isn't accessible anymore when printing warnings, so the filename isn't printed anymore. I could have added an optional path variable to load_from_string as a workaround, but I didn't want to expose that workaround to the API. Please suggest an alternative solution if this is a problem.
There already is the option of loading a dictionary, that is only in memory by calling the specific loader class. If you want to load a RailLABEL dict, just call the following:
LoaderRailLabelV2().load(your_dict)
Summary
This PR adds a function
load_from_string
. For this, I have split up the existingload
function.Use case
Currently, if you want to modify a raillabel json file before loading it using raillabel's
load
, you have to save the modified json to disk first. Usingload_from_string
, you can skip creating a temporary file on disk.Notes for reviewer
As a side effect of moving most of the code from
load
intoload_from_string
, thepath
variable isn't accessible anymore when printing warnings, so the filename isn't printed anymore. I could have added an optionalpath
variable toload_from_string
as a workaround, but I didn't want to expose that workaround to the API. Please suggest an alternative solution if this is a problem.