feat: standardize how app, package versions are determined

This commit is contained in:
Lance Edgar 2024-06-10 09:07:10 -05:00
parent b8ace1eb98
commit 2c2727bf66
4 changed files with 15 additions and 18 deletions

View file

@ -26,13 +26,12 @@ Tailbone Web API - "Common" Views
from collections import OrderedDict
import rattail
from rattail.util import get_pkg_version
from cornice import Service
from cornice.service import get_services
from cornice_swagger import CorniceSwagger
import tailbone
from tailbone import forms
from tailbone.forms.common import Feedback
from tailbone.api import APIView, api
@ -68,8 +67,8 @@ class CommonView(APIView):
return app.get_title()
def get_project_version(self):
import tailbone
return tailbone.__version__
app = self.get_rattail_app()
return app.get_version()
def get_packages(self):
"""
@ -77,8 +76,8 @@ class CommonView(APIView):
'about' page.
"""
return OrderedDict([
('rattail', rattail.__version__),
('Tailbone', tailbone.__version__),
('rattail', get_pkg_version('rattail')),
('Tailbone', get_pkg_version('Tailbone')),
])
@api

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2022 Lance Edgar
# Copyright © 2010-2024 Lance Edgar
#
# This file is part of Rattail.
#
@ -27,11 +27,11 @@ Note that most of the code for this module was copied from the beaker and
pyramid_beaker projects.
"""
from __future__ import unicode_literals, absolute_import
import time
from pkg_resources import parse_version
from rattail.util import get_pkg_version
import beaker
from beaker.session import Session
from beaker.util import coerce_session_params
@ -49,7 +49,7 @@ class TailboneSession(Session):
"Loads the data from this session from persistent storage"
# are we using older version of beaker?
old_beaker = parse_version(beaker.__version__) < parse_version('1.12')
old_beaker = parse_version(get_pkg_version('beaker')) < parse_version('1.12')
self.namespace = self.namespace_class(self.id,
data_dir=self.data_dir,

View file

@ -170,6 +170,7 @@ def before_render(event):
renderer_globals = event
renderer_globals['rattail_app'] = app
renderer_globals['app_title'] = app.get_title()
renderer_globals['app_version'] = app.get_version()
renderer_globals['h'] = helpers
renderer_globals['url'] = request.route_url
renderer_globals['rattail'] = rattail

View file

@ -24,12 +24,11 @@
Various common views
"""
import importlib
import os
from collections import OrderedDict
from rattail.batch import consume_batch_id
from rattail.util import simple_error
from rattail.util import get_pkg_version, simple_error
from rattail.files import resource_path
from tailbone import forms
@ -109,9 +108,8 @@ class CommonView(View):
if hasattr(self, 'project_version'):
return self.project_version
pkg = self.rattail_config.app_package()
mod = importlib.import_module(pkg)
return mod.__version__
app = self.get_rattail_app()
return app.get_version()
def exception(self):
"""
@ -136,10 +134,9 @@ class CommonView(View):
Should return the full set of packages which should be displayed on the
'about' page.
"""
import rattail, tailbone
return OrderedDict([
('rattail', rattail.__version__),
('Tailbone', tailbone.__version__),
('rattail', get_pkg_version('rattail')),
('Tailbone', get_pkg_version('Tailbone')),
])
def change_theme(self):