diff --git a/setup.cfg b/setup.cfg index 7229a5e..8b43162 100644 --- a/setup.cfg +++ b/setup.cfg @@ -6,9 +6,10 @@ package_dir = zip_safe = True install_requires = - biocommons.seqrepo>=0.6.2 + biocommons.seqrepo~=0.6 coloredlogs - connexion[swagger-ui]>=2.2 + connexion[swagger-ui]~=2.2 + Flask~=2.2 [options.extras_require] dev = diff --git a/src/seqrepo_rest_service/threadglobals.py b/src/seqrepo_rest_service/threadglobals.py index 855f3ab..b8e1555 100644 --- a/src/seqrepo_rest_service/threadglobals.py +++ b/src/seqrepo_rest_service/threadglobals.py @@ -3,24 +3,24 @@ """ import logging -import os from biocommons.seqrepo import SeqRepo -from flask import current_app, g +from flask import current_app _logger = logging.getLogger(__name__) def get_seqrepo(): seqrepo_dir = current_app.config["seqrepo_dir"] - _logger.info(f"Opening {seqrepo_dir=}") + if _get_or_create("seqrepo", None, False) is None: + _logger.info("Opening seqrepo_dir=%s", seqrepo_dir) return _get_or_create("seqrepo", lambda: SeqRepo(root_dir=seqrepo_dir)) -def _get_or_create(k, f): +def _get_or_create(k, f, create=True): k = "_" + k - o = getattr(g, k, None) - if o is None: + o = getattr(_get_or_create, k, None) + if o is None and create: o = f() - setattr(g, k, o) + setattr(_get_or_create, k, o) return o