From f8827cc84d5ba483282aa0ddaef9b65ff35756e0 Mon Sep 17 00:00:00 2001 From: "Brian D. Caruso" Date: Mon, 16 Sep 2024 16:52:42 -0400 Subject: [PATCH] Alters arxiv.db so it can be used without flask installed --- arxiv/db/__init__.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/arxiv/db/__init__.py b/arxiv/db/__init__.py index bc8818aa..b2b49e2d 100644 --- a/arxiv/db/__init__.py +++ b/arxiv/db/__init__.py @@ -47,8 +47,12 @@ from contextlib import contextmanager from typing import Tuple, Optional -from flask.globals import app_ctx -from flask import has_app_context, Flask +try: + from flask.globals import app_ctx + from flask import has_app_context, Flask +except ImportError: + def has_app_context(): + return False from sqlalchemy import Engine, MetaData, create_engine from sqlalchemy.event import listens_for @@ -200,4 +204,4 @@ def init(settings: Settings=settings) -> None: # late import of arxiv.db.models to avoid loops from arxiv.db.models import configure_db_engine - configure_db_engine(_classic_engine, _latexml_engine) \ No newline at end of file + configure_db_engine(_classic_engine, _latexml_engine)