Changeset - 00311dd15182
[Not reviewed]
0 2 0
Lance Edgar (lance) - 3 months ago 2024-08-05 22:21:17
lance@edbob.org
fix: `AppHandler.get_version()` should use upstream logic

but for now it needs a backward-compatibility wrapper
2 files changed with 41 insertions and 7 deletions:
0 comments (0 inline, 0 general)
rattail/app.py
Show inline comments
 
@@ -138,13 +138,21 @@ class AppHandler(WuttaAppHandler):
 
            return title
 
        return self.get_title(default=default)
 

	
 
    def get_version(self):
 
        """
 
        Returns the current app version.
 
        """
 
        pkg = self.config.app_package()
 
        mod = importlib.import_module(pkg)
 
        return mod.__version__
 
    def get_version(self, **kwargs):
 
        """ """
 
        # if config has defined the (legacy) rattail.app_package
 
        # setting, just use that (this is hacky but it works..)
 
        pkg = self.config.app_package(default='BOGUS')
 
        if pkg != 'BOGUS':
 
            warnings.warn("config has a `rattail.app_package` setting, "
 
                          "but that is deprecated.  please set "
 
                          "`rattail.app_dist` (or nothing) instead.",
 
                          DeprecationWarning)
 
            mod = importlib.import_module(pkg)
 
            return mod.__version__
 

	
 
        # otherwise use upstream logic
 
        return super().get_version(**kwargs)
 

	
 
    def get_class_prefix(self, default=None):
 
        """
tests/test_app.py
Show inline comments
 
@@ -73,6 +73,32 @@ class TestAppHandler(TestCase):
 
        self.assertEqual(self.app.get_title(), "Bar")
 
        self.assertEqual(self.app.get_title(default="Foo"), "Bar")
 

	
 
    def test_get_version(self):
 
        from importlib.metadata import version
 

	
 
        # works with "non-native" objects
 
        from config import Configuration
 
        config = Configuration({})
 
        ver = self.app.get_version(obj=config)
 
        self.assertEqual(ver, version('python-configuration'))
 

	
 
        # can override dist via config
 
        self.config.setdefault('rattail.app_dist', 'importlib_metadata')
 
        ver = self.app.get_version()
 
        self.assertEqual(ver, version('importlib_metadata'))
 

	
 
        # but the provided object takes precedence
 
        ver = self.app.get_version(obj=config)
 
        self.assertEqual(ver, version('python-configuration'))
 

	
 
        # reset
 
        del self.config.defaults['rattail.app_dist']
 

	
 
        # can also override package via config
 
        self.config.setdefault('rattail.app_package', 'mako')
 
        ver = self.app.get_version()
 
        self.assertEqual(ver, version('Mako'))
 

	
 
    def test_get_timezone(self):
 

	
 
        # unconfigured zone causes error
0 comments (0 inline, 0 general)