Skip to content

Commit

Permalink
feat(130): Type hinting and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kazmiekr committed Jan 9, 2024
1 parent 1d4a5be commit 2609702
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/biocommons/seqrepo/config.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import os
from typing import Optional


def parse_caching_env_var(env_name, env_default):
seqrepo_env_var = os.environ.get(env_name, env_default)
if seqrepo_env_var.lower() == "none":
def parse_caching_env_var(env_name: str, env_default: str) -> Optional[int]:
caching_env_var = os.environ.get(env_name, env_default)
if caching_env_var.lower() == "none":
return None

try:
seqrepo_env_var_int = int(seqrepo_env_var)
caching_env_var_int = int(caching_env_var)
except ValueError:
raise ValueError(
f"{env_name} must be a valid int, none, or not set, "
"currently it is " + seqrepo_env_var
"currently it is " + caching_env_var
)
return seqrepo_env_var_int
return caching_env_var_int


SEQREPO_LRU_CACHE_MAXSIZE = parse_caching_env_var("SEQREPO_LRU_CACHE_MAXSIZE", "1000000")
# Using a default value here of -1 to differentiate not setting this value and an explicit None (unbounded cache)
# Using a default value here of -1 to differentiate not setting this env var and an explicit None (unbounded cache)
SEQREPO_FD_CACHE_MAXSIZE = parse_caching_env_var("SEQREPO_FD_CACHE_MAXSIZE", "-1")

0 comments on commit 2609702

Please sign in to comment.