3
0
Fork 0

fix: improve backward compat for util.get_liburl()

ready to drop the old logic from tailbone
This commit is contained in:
Lance Edgar 2024-08-15 23:03:39 -05:00
parent f5ac66f264
commit 429f3c69b5
2 changed files with 60 additions and 6 deletions

View file

@ -27,6 +27,7 @@ Web Utilities
import importlib
import json
import logging
import warnings
import sqlalchemy as sa
@ -153,20 +154,34 @@ def get_libver(
config = request.wutta_config
# nb. we prefer a setting to be named like: wuttaweb.libver.vue
# but for back-compat this also can work: wuttaweb.vue_version
# but for back-compat this also can work: tailbone.libver.vue
# and for more back-compat this can work: wuttaweb.vue_version
# however that compat only works for some of the settings...
if not default_only:
# nb. new/preferred setting
version = config.get(f'{prefix}.libver.{key}')
version = config.get(f'wuttaweb.libver.{key}')
if version:
return version
# fallback to caller-specified prefix
if prefix != 'wuttaweb':
version = config.get(f'{prefix}.libver.{key}')
if version:
warnings.warn(f"config for {prefix}.libver.{key} is deprecated; "
f"please set wuttaweb.libver.{key} instead",
DeprecationWarning)
return version
if key == 'buefy':
if not default_only:
# nb. old/legacy setting
version = config.get(f'{prefix}.buefy_version')
if version:
warnings.warn(f"config for {prefix}.buefy_version is deprecated; "
"please set wuttaweb.libver.buefy instead",
DeprecationWarning)
return version
if not configured_only:
return 'latest'
@ -182,6 +197,9 @@ def get_libver(
# nb. old/legacy setting
version = config.get(f'{prefix}.vue_version')
if version:
warnings.warn(f"config for {prefix}.vue_version is deprecated; "
"please set wuttaweb.libver.vue instead",
DeprecationWarning)
return version
if not configured_only:
return '2.6.14'
@ -293,16 +311,35 @@ def get_liburl(
config = request.wutta_config
if not default_only:
# nb. new/preferred setting
url = config.get(f'wuttaweb.liburl.{key}')
if url:
return url
# fallback to caller-specified prefix
url = config.get(f'{prefix}.liburl.{key}')
if url:
warnings.warn(f"config for {prefix}.liburl.{key} is deprecated; "
f"please set wuttaweb.liburl.{key} instead",
DeprecationWarning)
return url
if configured_only:
return
version = get_libver(request, key, prefix=prefix)
version = get_libver(request, key, prefix=prefix,
configured_only=False,
default_only=default_only)
# load fanstatic libcache if configured
static = config.get('wuttaweb.static_libcache.module')
if not static:
static = config.get(f'{prefix}.static_libcache.module')
if static:
warnings.warn(f"config for {prefix}.static_libcache.module is deprecated; "
"please set wuttaweb.static_libcache.module instead",
DeprecationWarning)
if static:
static = importlib.import_module(static)
needed = request.environ['fanstatic.needed']