From 1575889c95db62cb857fbb197153c94f984adae3 Mon Sep 17 00:00:00 2001 From: Kiran Jonnalagadda Date: Wed, 10 Apr 2024 15:01:47 +0530 Subject: [PATCH] Replace star imports with explicit imports and exports --- src/baseframe/__init__.py | 49 ++++++++++++++++++++++++++++++--------- src/baseframe/assets.py | 2 +- src/baseframe/utils.py | 14 ++++++++++- src/baseframe/views.py | 15 +----------- 4 files changed, 53 insertions(+), 27 deletions(-) diff --git a/src/baseframe/__init__.py b/src/baseframe/__init__.py index e8e05ffa..2c00d990 100644 --- a/src/baseframe/__init__.py +++ b/src/baseframe/__init__.py @@ -2,19 +2,32 @@ from typing import cast +from flask_assets import Bundle from flask_babel import gettext, lazy_gettext +from . import ( + blueprint, + deprecated, + errors, + extensions, + filters, + forms, + signals, + utils, + views, +) from ._version import __version__, __version_info__ from .assets import Version, assets -from .blueprint import * # NOQA -from .deprecated import * # NOQA -from .extensions import * # NOQA -from .extensions import GetTextProtocol -from .filters import * # NOQA -from .utils import * # NOQA -from .views import * # NOQA - -from . import forms # isort:skip +from .blueprint import baseframe +from .deprecated import baseframe_css, baseframe_js +from .extensions import GetTextProtocol, babel, baseframe_translations, cache, statsd +from .utils import ( + ctx_has_locale, + localize_timezone, + localized_country_list, + request_checked_xhr, + request_is_xhr, +) # Pretend these return str, not Any or LazyString _ = cast(GetTextProtocol, gettext) @@ -22,21 +35,35 @@ # TODO: baseframe_js and baseframe_css are defined in deprecated.py # and pending removal after an audit of all apps -__all__ = [ # noqa: F405 +__all__ = [ '_', '__', '__version__', '__version_info__', 'assets', 'babel', - 'baseframe', 'baseframe_css', 'baseframe_js', + 'baseframe_translations', + 'baseframe', + 'blueprint', + 'Bundle', 'cache', + 'ctx_has_locale', + 'deprecated', + 'errors', + 'extensions', + 'filters', + 'filters', + 'forms', 'forms', 'localize_timezone', 'localized_country_list', + 'request_checked_xhr', 'request_is_xhr', + 'signals', 'statsd', + 'utils', 'Version', + 'views', ] diff --git a/src/baseframe/assets.py b/src/baseframe/assets.py index b4312da3..8fd4feb6 100644 --- a/src/baseframe/assets.py +++ b/src/baseframe/assets.py @@ -2,7 +2,7 @@ from coaster.assets import Version, VersionedAssets -from . import __version__ +from ._version import __version__ __all__ = ['Version', 'assets'] diff --git a/src/baseframe/utils.py b/src/baseframe/utils.py index 0a56969a..3b23b5c8 100644 --- a/src/baseframe/utils.py +++ b/src/baseframe/utils.py @@ -9,7 +9,7 @@ import pycountry from babel import Locale from flask import g, request -from flask_babel import LazyString +from flask_babel import LazyString, _get_current_context from furl import furl from mxsniff import mxsniff from pytz import timezone, utc @@ -169,3 +169,15 @@ def request_is_xhr() -> bool: def request_checked_xhr() -> bool: """Confirm if XHR header was checked for during this request.""" return getattr(request, '_checked_xhr', False) + + +def ctx_has_locale() -> bool: + """ + Report if Babel was used in the current context. + + For setting a ``Vary: Accept-Language`` header in the response. + """ + ctx = _get_current_context() + if ctx is None: + return False + return hasattr(ctx, 'babel_locale') diff --git a/src/baseframe/views.py b/src/baseframe/views.py index 66f94233..51251d70 100644 --- a/src/baseframe/views.py +++ b/src/baseframe/views.py @@ -16,7 +16,6 @@ send_from_directory, ) from flask_assets import Bundle -from flask_babel import _get_current_context from flask_wtf.csrf import generate_csrf from coaster.assets import split_namespec @@ -27,19 +26,7 @@ from .assets import assets as assets_repo from .blueprint import baseframe from .extensions import networkbar_cache -from .utils import request_checked_xhr, request_timestamp - - -def ctx_has_locale() -> bool: - """ - Report if Babel was used in the current context. - - For setting a ``Vary: Accept-Language`` header in the response. - """ - ctx = _get_current_context() - if ctx is None: - return False - return hasattr(ctx, 'babel_locale') +from .utils import ctx_has_locale, request_checked_xhr, request_timestamp @networkbar_cache.cached(key_prefix='networkbar_links')