-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix 1210 and improves loading of inventory backends
- Loading branch information
Showing
10 changed files
with
153 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,58 @@ | ||
from .inventory import Inventory | ||
|
||
try: | ||
from enum import StrEnum | ||
except ImportError: | ||
from strenum import StrEnum | ||
|
||
from typing import Type | ||
|
||
from .inv_reclass import ReclassInventory | ||
from .inv_reclass_rs import ReclassRsInventory | ||
from .inv_omegaconf.inv_omegaconf import OmegaConfInventory | ||
from .inventory import Inventory | ||
|
||
class InventoryBackends(StrEnum): | ||
""" | ||
Enumeration of available inventory backends. | ||
""" | ||
RECLASS = "reclass" | ||
RECLASS_RS = "reclass-rs" | ||
OMEGACONF = "omegaconf" | ||
DEFAULT = RECLASS | ||
|
||
|
||
def load_reclass_backend(): | ||
""" | ||
Enable the reclass inventory backend. | ||
""" | ||
from .inv_reclass import ReclassInventory | ||
return ReclassInventory | ||
|
||
|
||
def load_reclass_rs_backend(): | ||
""" | ||
Enable the reclass-rs inventory backend. | ||
""" | ||
from .inv_reclass_rs import ReclassRsInventory | ||
return ReclassRsInventory | ||
|
||
|
||
def load_omegaconf_backend(): | ||
""" | ||
Enable the omegaconf inventory backend. | ||
""" | ||
from .inv_omegaconf.inv_omegaconf import OmegaConfInventory | ||
return OmegaConfInventory | ||
|
||
|
||
# Dict mapping values for command line flag `--inventory-backend` to the | ||
# associated `Inventory` subclass. | ||
AVAILABLE_BACKENDS: dict[str, Type[Inventory]] = { | ||
"reclass": ReclassInventory, | ||
"reclass-rs": ReclassRsInventory, | ||
"omegaconf": OmegaConfInventory, | ||
InventoryBackends.RECLASS: load_reclass_backend, | ||
InventoryBackends.RECLASS_RS: load_reclass_rs_backend, | ||
InventoryBackends.OMEGACONF: load_omegaconf_backend, | ||
} | ||
|
||
|
||
def get_inventory_backend(backend_name: str) -> Type[Inventory]: | ||
""" | ||
Get the `Inventory` subclass associated with the given `backend_name`. | ||
""" | ||
return AVAILABLE_BACKENDS.get(backend_name, AVAILABLE_BACKENDS[InventoryBackends.DEFAULT])() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.