Merge in RR/image-prediction from RED-5202-port-hotfixes to master
Squashed commit of the following:
commit c1b92270354c764861da0f7782348e9cd0725d76
Author: Matthias Bisping <matthias.bisping@axbit.com>
Date: Mon Sep 12 13:28:44 2022 +0200
fixed statefulness issue with os.environ in tests
commit ad9c5657fe93079d5646ba2b70fa091e8d2daf76
Author: Matthias Bisping <matthias.bisping@axbit.com>
Date: Mon Sep 12 13:04:55 2022 +0200
- Adapted response formatting logic for threshold maps passed via env vars.
- Added test for reading threshold maps and values from env vars.
commit c60e8cd6781b8e0c3ec69ccd0a25375803de26f0
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Mon Sep 12 11:38:01 2022 +0200
add parser for environment variables WIP
commit 101b71726c697f30ec9298ba62d2203bd7da2efb
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Mon Sep 12 09:52:33 2022 +0200
Add typehints, make custom page quotient breach function private since the intention of outsourcing it from build_image_info is to make it testable seperately
commit 04aee4e62781e78cd54c6d20e961dcd7bf1fc081
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Mon Sep 12 09:25:59 2022 +0200
DotIndexable default get method exception made more specific
commit 4584e7ba66400033dc5f1a38473b644eeb11e67c
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Mon Sep 12 08:55:05 2022 +0200
RED-5202 port temporary broken image handling so the hotfix won't be lost by upgrading the service. A proper solution is still desirable (see RED-5148)
commit 5f99622646b3f6d3a842aebef91ff8e082072cd6
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Mon Sep 12 08:47:02 2022 +0200
RED-5202 add per class customizable max image to page quotient setting for signatures, default is 0.4. Can be overwritten by , set to null to use default value or set to value that should be used.
47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
"""Implements a config object with dot-indexing syntax."""
|
|
|
|
|
|
from envyaml import EnvYAML
|
|
|
|
from image_prediction.locations import CONFIG_FILE
|
|
|
|
|
|
def _get_item_and_maybe_make_dotindexable(container, item):
|
|
ret = container[item]
|
|
return DotIndexable(ret) if isinstance(ret, dict) else ret
|
|
|
|
|
|
class DotIndexable:
|
|
def __init__(self, x):
|
|
self.x = x
|
|
|
|
def get(self, item, default=None):
|
|
try:
|
|
return _get_item_and_maybe_make_dotindexable(self.x, item)
|
|
except KeyError:
|
|
return default
|
|
|
|
def __getattr__(self, item):
|
|
return _get_item_and_maybe_make_dotindexable(self.x, item)
|
|
|
|
def __repr__(self):
|
|
return self.x.__repr__()
|
|
|
|
def __getitem__(self, item):
|
|
return self.__getattr__(item)
|
|
|
|
|
|
class Config:
|
|
def __init__(self, config_path):
|
|
self.__config = EnvYAML(config_path)
|
|
|
|
def __getattr__(self, item):
|
|
if item in self.__config:
|
|
return _get_item_and_maybe_make_dotindexable(self.__config, item)
|
|
|
|
def __getitem__(self, item):
|
|
return self.__getattr__(item)
|
|
|
|
|
|
CONFIG = Config(CONFIG_FILE)
|