Coverage for /opt/conda/envs/apienv/lib/python3.10/site-packages/daiquiri/core/components/version.py: 61%

23 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-11-14 02:13 +0000

1#!/usr/bin/env python 

2# -*- coding: utf-8 -*- 

3import importlib 

4import logging 

5import daiquiri 

6from daiquiri.core import marshal 

7from daiquiri.core.components import Component, ComponentResource 

8from daiquiri.core.schema.components import VersionSchema 

9 

10 

11logger = logging.getLogger(__name__) 

12 

13 

14class VersionResource(ComponentResource): 

15 @marshal(out=[[200, VersionSchema(), "Current version information"]]) 

16 def get(self): 

17 """Returns the current daiquiri version""" 

18 return self._parent.get_versions() 

19 

20 

21class Version(Component): 

22 """Version Component 

23 

24 Simply returns the current app version 

25 """ 

26 

27 def setup(self): 

28 self.register_route(VersionResource, "") 

29 

30 def get_versions(self): 

31 versions = {"version": daiquiri.__version__, "libraries": {}} 

32 

33 for library in self._base_config["versions"]: 

34 try: 

35 mod = importlib.import_module(library) 

36 versions["libraries"][library] = mod.__version__ 

37 except Exception: 

38 logger.warning(f"Could not get version for library: {library}") 

39 

40 return versions