Coverage for lobster/version.py: 61%

25 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-06-26 14:55 +0000

1#!/usr/bin/env python3 

2# 

3# LOBSTER - Lightweight Open BMW Software Traceability Evidence Report 

4# Copyright (C) 2023-2025 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) 

5# 

6# This program is free software: you can redistribute it and/or modify 

7# it under the terms of the GNU Affero General Public License as 

8# published by the Free Software Foundation, either version 3 of the 

9# License, or (at your option) any later version. 

10# 

11# This program is distributed in the hope that it will be useful, but 

12# WITHOUT ANY WARRANTY; without even the implied warranty of 

13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 

14# Affero General Public License for more details. 

15# 

16# You should have received a copy of the GNU Affero General Public 

17# License along with this program. If not, see 

18# <https://www.gnu.org/licenses/>. 

19import sys 

20from argparse import ArgumentParser 

21 

22VERSION_TUPLE = (0, 13, 1) 

23VERSION_SUFFIX = "dev" 

24 

25LOBSTER_VERSION = ("%u.%u.%u" % VERSION_TUPLE) + ( 

26 "-%s" % VERSION_SUFFIX if VERSION_SUFFIX else "" 

27) 

28 

29FULL_NAME = "LOBSTER %s" % LOBSTER_VERSION 

30 

31 

32def get_version(obj): 

33 """ 

34 This decorator function is used on function wherever we are parsing 

35 the command line arguments which then adds a version argument to the function. 

36 If a version flag is passed to the command line arguments then the LOBSTER version 

37 is printed. 

38 Parameters 

39 ---------- 

40 obj - obj can be an ArgumentParser object or a Function object. 

41 

42 Returns - Nothing 

43 ------- 

44 

45 """ 

46 if isinstance(obj, ArgumentParser): 

47 obj.add_argument("-v, --version", action="store_true", 

48 default=None, 

49 help="Get version for the tool") 

50 

51 def version(func): 

52 def execution(): 

53 if (len(sys.argv) > 1 and 53 ↛ 55line 53 didn't jump to line 55 because the condition on line 53 was never true

54 (sys.argv[1] == "--version" or sys.argv[1] == "-v")): 

55 print(FULL_NAME) 

56 return sys.exit(0) 

57 else: 

58 return func() 

59 return execution 

60 return version 

61 else: 

62 def version(func): 

63 if not isinstance(obj, ArgumentParser): 

64 func.ap.add_argument("-v, --version", action="store_true", 

65 default=None, 

66 help="Get version for the tool") 

67 if (len(sys.argv) > 1 and 

68 (sys.argv[1] == "--version" or sys.argv[1] == "-v")): 

69 print(FULL_NAME) 

70 return sys.exit(0) 

71 return obj(func) 

72 return version