From 20e73c324f0bfabfa717ec630562dd6c9e5a588f Mon Sep 17 00:00:00 2001 From: Kyle Ferriter Date: Tue, 5 Sep 2023 12:09:46 -0400 Subject: [PATCH 1/3] Use a process-global object for _get_or_create instead of request-scoped flask.g --- src/seqrepo_rest_service/threadglobals.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/seqrepo_rest_service/threadglobals.py b/src/seqrepo_rest_service/threadglobals.py index 855f3ab..fc19c50 100644 --- a/src/seqrepo_rest_service/threadglobals.py +++ b/src/seqrepo_rest_service/threadglobals.py @@ -3,24 +3,22 @@ """ 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=}") return _get_or_create("seqrepo", lambda: SeqRepo(root_dir=seqrepo_dir)) def _get_or_create(k, f): - k = "_" + k - o = getattr(g, k, None) + k = '_' + k + o = getattr(_get_or_create, k, None) if o is None: o = f() - setattr(g, k, o) + setattr(_get_or_create, k, o) return o From 41b6e162e8d83ada938e35aee32d87b3e2ce2fbc Mon Sep 17 00:00:00 2001 From: Kyle Ferriter Date: Tue, 5 Sep 2023 12:32:20 -0400 Subject: [PATCH 2/3] Add back a log when SeqRepo obj is created --- src/seqrepo_rest_service/threadglobals.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/seqrepo_rest_service/threadglobals.py b/src/seqrepo_rest_service/threadglobals.py index fc19c50..b8e1555 100644 --- a/src/seqrepo_rest_service/threadglobals.py +++ b/src/seqrepo_rest_service/threadglobals.py @@ -12,13 +12,15 @@ def get_seqrepo(): seqrepo_dir = current_app.config["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): - k = '_' + k +def _get_or_create(k, f, create=True): + k = "_" + k o = getattr(_get_or_create, k, None) - if o is None: + if o is None and create: o = f() setattr(_get_or_create, k, o) return o From a993a80bdbbf975a57d27ebdcd61c96b38bf2a37 Mon Sep 17 00:00:00 2001 From: Reece Hart Date: Mon, 13 Nov 2023 11:10:16 -0800 Subject: [PATCH 3/3] soft-pinned dependencies in setup.cfg --- setup.cfg | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 =