62 lines
2.4 KiB
Python
62 lines
2.4 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
# IMPORTS
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
from src.thirdparty.misc import *;
|
|
from src.thirdparty.config import *;
|
|
from src.thirdparty.code import *;
|
|
from src.thirdparty.types import *;
|
|
|
|
from models.generated.config import *;
|
|
from models.generated.commands import *;
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
# EXPORTS
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
__all__ = [
|
|
'INFO',
|
|
'OPTIONS',
|
|
'COMMANDS',
|
|
];
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
# CONSTANTS
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
PATH_ASSETS_CONFIG: str = 'assets/config.yaml';
|
|
PATH_ASSETS_COMMANDS: str = 'assets/commands.yaml';
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
# LAZY LOADED RESOURCES
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
def load_assets_config(path: str) -> Config: # pragma: no cover
|
|
with open(path, 'r') as fp:
|
|
assets = yaml_load(fp, Loader=yaml_FullLoader);
|
|
assert isinstance(assets, dict);
|
|
return Config(**assets);
|
|
|
|
def create_commands(path: str) -> List[Command]: # pragma: no cover
|
|
commands = [];
|
|
with open(path, 'r') as fp:
|
|
assets = yaml_load(fp, Loader=yaml_FullLoader);
|
|
for command in assets:
|
|
match Command(**command).name:
|
|
case EnumAlgorithmNames.tarjan:
|
|
commands.append(CommandTarjan(**command));
|
|
case EnumAlgorithmNames.tsp:
|
|
commands.append(CommandTsp(**command));
|
|
case EnumAlgorithmNames.hirschberg:
|
|
commands.append(CommandHirschberg(**command));
|
|
return commands;
|
|
|
|
# use lazy loaing to ensure that values only loaded (once) when used
|
|
CONFIG: Config = lazy(load_assets_config, path=PATH_ASSETS_CONFIG);
|
|
INFO: Info = lazy(lambda x: x.info, CONFIG);
|
|
OPTIONS: AppOptions = lazy(lambda x: x.options, CONFIG);
|
|
COMMANDS: List[Command] = lazy(create_commands, path=PATH_ASSETS_COMMANDS);
|