Use pkg_resources to determine package versions

and always add `app_version` to global template context.  this was for
sake of "About This App v1.0.0" style links in custom page footers
This commit is contained in:
Lance Edgar 2024-06-06 20:33:36 -05:00
parent ce290f5f8b
commit f6f2a53a0c
2 changed files with 7 additions and 3 deletions

View file

@ -28,6 +28,7 @@ import six
import json
import datetime
import logging
import pkg_resources
import warnings
from collections import OrderedDict
@ -168,7 +169,11 @@ def before_render(event):
renderer_globals = event
renderer_globals['rattail_app'] = request.rattail_config.get_app()
renderer_globals['app_title'] = request.rattail_config.app_title()
pkg = rattail_config.app_package()
renderer_globals['app_version'] = pkg_resources.get_distribution(pkg).version
renderer_globals['h'] = helpers
renderer_globals['url'] = request.route_url
renderer_globals['rattail'] = rattail

View file

@ -24,8 +24,8 @@
Various common views
"""
import importlib
import os
import pkg_resources
from collections import OrderedDict
from rattail.batch import consume_batch_id
@ -108,8 +108,7 @@ class CommonView(View):
return self.project_version
pkg = self.rattail_config.app_package()
mod = importlib.import_module(pkg)
return mod.__version__
return pkg_resources.get_distribution(pkg).version
def exception(self):
"""