2
0
Fork 0

Compare commits

..

2 commits

Author SHA1 Message Date
Lance Edgar 7feaa844af bump: version 0.8.0 → 0.8.1 2024-08-15 23:14:42 -05:00
Lance Edgar 429f3c69b5 fix: improve backward compat for util.get_liburl()
ready to drop the old logic from tailbone
2024-08-15 23:03:39 -05:00
4 changed files with 67 additions and 7 deletions

View file

@ -5,6 +5,12 @@ All notable changes to wuttaweb will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## v0.8.1 (2024-08-15)
### Fix
- improve backward compat for `util.get_liburl()`
## v0.8.0 (2024-08-15) ## v0.8.0 (2024-08-15)
### Feat ### Feat

View file

@ -6,7 +6,7 @@ build-backend = "hatchling.build"
[project] [project]
name = "WuttaWeb" name = "WuttaWeb"
version = "0.8.0" version = "0.8.1"
description = "Web App for Wutta Framework" description = "Web App for Wutta Framework"
readme = "README.md" readme = "README.md"
authors = [{name = "Lance Edgar", email = "lance@edbob.org"}] authors = [{name = "Lance Edgar", email = "lance@edbob.org"}]

View file

@ -27,6 +27,7 @@ Web Utilities
import importlib import importlib
import json import json
import logging import logging
import warnings
import sqlalchemy as sa import sqlalchemy as sa
@ -153,13 +154,24 @@ def get_libver(
config = request.wutta_config config = request.wutta_config
# nb. we prefer a setting to be named like: wuttaweb.libver.vue # 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... # however that compat only works for some of the settings...
if not default_only: if not default_only:
# nb. new/preferred setting # nb. new/preferred setting
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}') version = config.get(f'{prefix}.libver.{key}')
if version: if version:
warnings.warn(f"config for {prefix}.libver.{key} is deprecated; "
f"please set wuttaweb.libver.{key} instead",
DeprecationWarning)
return version return version
if key == 'buefy': if key == 'buefy':
@ -167,6 +179,9 @@ def get_libver(
# nb. old/legacy setting # nb. old/legacy setting
version = config.get(f'{prefix}.buefy_version') version = config.get(f'{prefix}.buefy_version')
if version: if version:
warnings.warn(f"config for {prefix}.buefy_version is deprecated; "
"please set wuttaweb.libver.buefy instead",
DeprecationWarning)
return version return version
if not configured_only: if not configured_only:
return 'latest' return 'latest'
@ -182,6 +197,9 @@ def get_libver(
# nb. old/legacy setting # nb. old/legacy setting
version = config.get(f'{prefix}.vue_version') version = config.get(f'{prefix}.vue_version')
if version: if version:
warnings.warn(f"config for {prefix}.vue_version is deprecated; "
"please set wuttaweb.libver.vue instead",
DeprecationWarning)
return version return version
if not configured_only: if not configured_only:
return '2.6.14' return '2.6.14'
@ -293,16 +311,35 @@ def get_liburl(
config = request.wutta_config config = request.wutta_config
if not default_only: 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}') url = config.get(f'{prefix}.liburl.{key}')
if url: if url:
warnings.warn(f"config for {prefix}.liburl.{key} is deprecated; "
f"please set wuttaweb.liburl.{key} instead",
DeprecationWarning)
return url return url
if configured_only: if configured_only:
return 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') 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: if static:
static = importlib.import_module(static) static = importlib.import_module(static)
needed = request.environ['fanstatic.needed'] needed = request.environ['fanstatic.needed']

View file

@ -59,6 +59,11 @@ class TestGetLibVer(TestCase):
version = util.get_libver(self.request, 'buefy') version = util.get_libver(self.request, 'buefy')
self.assertEqual(version, '0.9.29') self.assertEqual(version, '0.9.29')
def test_buefy_custom_old_tailbone(self):
self.config.setdefault('tailbone.libver.buefy', '0.9.28')
version = util.get_libver(self.request, 'buefy', prefix='tailbone')
self.assertEqual(version, '0.9.28')
def test_buefy_custom_new(self): def test_buefy_custom_new(self):
self.config.setdefault('wuttaweb.libver.buefy', '0.9.29') self.config.setdefault('wuttaweb.libver.buefy', '0.9.29')
version = util.get_libver(self.request, 'buefy') version = util.get_libver(self.request, 'buefy')
@ -221,8 +226,9 @@ class TestGetLibUrl(TestCase):
def tearDown(self): def tearDown(self):
testing.tearDown() testing.tearDown()
def setup_fanstatic(self): def setup_fanstatic(self, register=True):
self.pyramid_config.include('pyramid_fanstatic') self.pyramid_config.include('pyramid_fanstatic')
if register:
self.config.setdefault('wuttaweb.static_libcache.module', self.config.setdefault('wuttaweb.static_libcache.module',
'tests.test_util') 'tests.test_util')
@ -240,6 +246,11 @@ class TestGetLibUrl(TestCase):
url = util.get_liburl(self.request, 'buefy') url = util.get_liburl(self.request, 'buefy')
self.assertEqual(url, '/lib/buefy.js') self.assertEqual(url, '/lib/buefy.js')
def test_buefy_custom_tailbone(self):
self.config.setdefault('tailbone.liburl.buefy', '/tailbone/buefy.js')
url = util.get_liburl(self.request, 'buefy', prefix='tailbone')
self.assertEqual(url, '/tailbone/buefy.js')
def test_buefy_default_only(self): def test_buefy_default_only(self):
self.config.setdefault('wuttaweb.liburl.buefy', '/lib/buefy.js') self.config.setdefault('wuttaweb.liburl.buefy', '/lib/buefy.js')
url = util.get_liburl(self.request, 'buefy', default_only=True) url = util.get_liburl(self.request, 'buefy', default_only=True)
@ -254,6 +265,12 @@ class TestGetLibUrl(TestCase):
url = util.get_liburl(self.request, 'buefy') url = util.get_liburl(self.request, 'buefy')
self.assertEqual(url, '/wutta/fanstatic/buefy.js') self.assertEqual(url, '/wutta/fanstatic/buefy.js')
def test_buefy_fanstatic_tailbone(self):
self.setup_fanstatic(register=False)
self.config.setdefault('tailbone.static_libcache.module', 'tests.test_util')
url = util.get_liburl(self.request, 'buefy', prefix='tailbone')
self.assertEqual(url, '/wutta/fanstatic/buefy.js')
def test_buefy_css_default(self): def test_buefy_css_default(self):
url = util.get_liburl(self.request, 'buefy.css') url = util.get_liburl(self.request, 'buefy.css')
self.assertEqual(url, 'https://unpkg.com/buefy@latest/dist/buefy.min.css') self.assertEqual(url, 'https://unpkg.com/buefy@latest/dist/buefy.min.css')