make env var parser discrete
This commit is contained in:
parent
c1b9227035
commit
23c61ef49e
@ -4,7 +4,7 @@ import os
|
|||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
|
|
||||||
from funcy import filter, juxt, first, rest, compose
|
from funcy import juxt, first, rest, compose
|
||||||
|
|
||||||
from image_prediction.config import CONFIG
|
from image_prediction.config import CONFIG
|
||||||
from image_prediction.exceptions import ParsingError
|
from image_prediction.exceptions import ParsingError
|
||||||
@ -131,11 +131,9 @@ def build_image_info(data: dict) -> dict:
|
|||||||
@lru_cache(maxsize=None)
|
@lru_cache(maxsize=None)
|
||||||
def parse_env_var(prefix, table=None):
|
def parse_env_var(prefix, table=None):
|
||||||
table = table or os.environ
|
table = table or os.environ
|
||||||
head, tail = juxt(first, compose(list, rest))(filter(prefix, table))
|
head = first(filter(lambda s: s == prefix, table))
|
||||||
if not head:
|
if not head:
|
||||||
logger.warning(f"Found no environment variable with prefix '{prefix}'.")
|
logger.warning(f"Found no environment variable with prefix '{prefix}'.")
|
||||||
elif tail:
|
|
||||||
logger.warning(f"Found multiple candidates for environment variable with prefix '{prefix}'.")
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
return parse_env_var_value(table[head])
|
return parse_env_var_value(table[head])
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user