Adds a loader to the script. If the loader is a duplicate, returns the existing loader instead. Args: loader_str (str): A string constructing the loader. For security reasons, this must be generated using
(self, loader_str, loader_id)
| 313 | return Script.DATA_LOADER_NAME |
| 314 | |
| 315 | def add_loader(self, loader_str, loader_id): |
| 316 | """ |
| 317 | Adds a loader to the script. |
| 318 | If the loader is a duplicate, returns the existing loader instead. |
| 319 | |
| 320 | Args: |
| 321 | loader_str (str): |
| 322 | A string constructing the loader. |
| 323 | For security reasons, this must be generated using |
| 324 | ``make_invocable`` or ``make_invocable_if_nondefault``. |
| 325 | loader_id (str): |
| 326 | A short human-readable identifier for the loader. |
| 327 | |
| 328 | Returns: |
| 329 | str: The name of the loader added. |
| 330 | """ |
| 331 | loader_str = ensure_safe(loader_str).unwrap() |
| 332 | |
| 333 | if loader_str in self.loaders: |
| 334 | return self.loaders[loader_str] |
| 335 | |
| 336 | unique_name = loader_id |
| 337 | if self.loader_count[unique_name]: |
| 338 | unique_name = f"{unique_name}_{self.loader_count[loader_id]}" |
| 339 | unique_name = Script.String(unique_name, safe=True, inline=True) |
| 340 | |
| 341 | self.loader_count[loader_id] += 1 |
| 342 | self.loaders[loader_str] = unique_name |
| 343 | return unique_name |
| 344 | |
| 345 | def get_runners(self): |
| 346 | return Script.String("runners", safe=True, inline=True) |
no test coverage detected