Coverage for laskea/__init__.py: 100.00%

55 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-12-10 22:19:18 +00:00

1"""Calculate (Finnish: laskea) some parts.""" 

2import logging 

3import os 

4import pathlib 

5from typing import Union, no_type_check 

6 

7# [[[fill git_describe()]]] 

8__version__ = '2023.12.10+parent.g5899adcd' 

9# [[[end]]] (checksum: 433a00c6fc740e8dc1cbae0b2c28b70c) 

10__version_info__ = tuple( 

11 e if '-' not in e else e.split('-')[0] for part in __version__.split('+') for e in part.split('.') if e != 'parent' 

12) 

13 

14APP_ALIAS = str(pathlib.Path(__file__).parent.name) 

15APP_ENV: str = APP_ALIAS.upper() 

16APP_NAME = locals()['__doc__'] 

17DEBUG = bool(os.getenv(f'{APP_ENV}_DEBUG', '')) 

18VERBOSE = bool(os.getenv(f'{APP_ENV}_VERBOSE', '')) 

19QUIET = False 

20STRICT = bool(os.getenv(f'{APP_ENV}_STRICT', '')) 

21CHECKSUMS = bool(os.getenv(f'{APP_ENV}_CHECKSUMS', '')) 

22ENCODING = 'utf-8' 

23ENCODING_ERRORS_POLICY = 'ignore' 

24DEFAULT_CONFIG_NAME = f'.{APP_ALIAS}.json' 

25 

26FILTER_ORDER_TYPE = list[str] 

27PAYLOAD_PAIR_TYPE = list[str] 

28FILTER_PAYLOAD_TYPE = list[PAYLOAD_PAIR_TYPE] 

29FILTER_MAP_TYPE = dict[str, Union[FILTER_ORDER_TYPE, FILTER_PAYLOAD_TYPE]] 

30 

31CACHE_EXPIRY_SECONDS = int(os.getenv(f'{APP_ENV}_CACHE_EXPIRY_SECONDS', '180')) 

32REQUESTS_TIMEOUT_SECS = 30 

33 

34FIELD_SEPARATORS = ( 

35 CARET := '^', 

36 COLON := ':', 

37 COMMA := ',', 

38 DASH := '-', 

39 DOT := '.', 

40 PIPE := '|', 

41 PLUS := '+', 

42 RS := '\x1e', 

43 SEMI := ';', 

44 SPACE := ' ', 

45 TAB := '\t', 

46 USCORE := '_', 

47) 

48FS_SLUG = '$FIELD_SEPARATOR$' 

49 

50DRY_RUN = False 

51OPEN_BRACKET = '[' 

52CLOSE_BRACKET = ']' 

53DEFAULT_MARKERS = f'{OPEN_BRACKET * 3}fill {CLOSE_BRACKET * 3} {OPEN_BRACKET * 3}end{CLOSE_BRACKET * 3}' 

54DEFAULT_LF_ONLY = 'YES' 

55DEFAULT_CAPTION = "$NL$$NL$Table: Search '$QUERY_TEXT$' resulted in $ISSUE_COUNT$ issue$SINGULAR$$PLURAL$s$" 

56DEFAULT_JOIN_STRING = ' <br>' 

57BASE_MARKERS = os.getenv(f'{APP_ENV}_MARKERS', DEFAULT_MARKERS) 

58BASE_LF_ONLY = bool(os.getenv(f'{APP_ENV}_LF_ONLY', DEFAULT_LF_ONLY)) 

59BASE_CAPTION = bool(os.getenv(f'{APP_ENV}_CAPTION', DEFAULT_CAPTION)) 

60BASE_JOIN_STRING = os.getenv(f'{APP_ENV}_JOIN_STRING', DEFAULT_JOIN_STRING) 

61MASK_DISPLAY = '*' * 13 

62EXCEL = {'mbom': 'mbom.xlsm'} 

63TABULATOR = { 

64 'overview': { 

65 'base_url': 'https://example.com/metrics/', 

66 'path': '$year$/kpi-table-$year$.json', 

67 'years': [2022], 

68 'matrix': [ 

69 ['section', 'Section', False, 'L'], 

70 ['name', 'Name', False, 'L'], 

71 ['unit', 'Unit', False, 'C'], 

72 ['all', 'ALL', True, 'R'], 

73 ['pr1', 'PR1', True, 'R'], 

74 ['pr2', 'PR2', True, 'R'], 

75 ['pr3', 'PR3', True, 'R'], 

76 ['description', 'Description', False, 'L'], 

77 ], 

78 'verify_server_certificate': False, 

79 }, 

80 'metrics': { 

81 'base_url': 'https://example.com/metrics/', 

82 'paths': { 

83 'review_effectivity': '$year$/review_effectivity/kpi-review_effectivity-per_product-report-$year$.json', 

84 'sprint_effectivity': '$year$/sprint_effectivity/kpi-sprint_effectivity-per_product-report-$year$.json', 

85 'task_traceability': '$year$/task_traceability/kpi-task_traceability-per_product-report-$year$.json', 

86 }, 

87 'years': [2021, 2022], 

88 'matrix': [ 

89 ['month', 'Month', False, 'L'], 

90 ['all', 'ALL', True, 'R'], 

91 ['pr1', 'PR1', True, 'R'], 

92 ['pr2', 'PR2', True, 'R'], 

93 ['pr3', 'PR3', True, 'R'], 

94 ['trend_all', '±ALL', True, 'R'], 

95 ['trend_pr1', '±PR1', True, 'R'], 

96 ['trend_pr2', '±PR2', True, 'R'], 

97 ['trend_pr3', '±PR3', True, 'R'], 

98 ], 

99 'verify_server_certificate': False, 

100 }, 

101} 

102 

103log = logging.getLogger() # Temporary refactoring: module level logger 

104LOG_FOLDER = pathlib.Path('logs') 

105LOG_FILE = f'{APP_ALIAS}.log' 

106LOG_PATH = pathlib.Path(LOG_FOLDER, LOG_FILE) if LOG_FOLDER.is_dir() else pathlib.Path(LOG_FILE) 

107LOG_LEVEL = logging.INFO 

108 

109from laskea.api.excel import mbom_table # noqa 

110from laskea.api.jira import ( # noqa 

111 login, 

112 markdown_heading, 

113 markdown_list, 

114 markdown_table, 

115 parent_children_sections, 

116 query, 

117 separated_values_list, 

118) 

119from laskea.embed import ( # noqa 

120 dl, 

121 h1, 

122 h2, 

123 h3, 

124 h4, 

125 h5, 

126 h6, 

127 kpi_table, 

128 mbom_table, 

129 metrics_table, 

130 ol, 

131 svl, 

132 table, 

133 test_plans, 

134 ul, 

135) 

136 

137__all__ = [ 

138 'FILTER_MAP_TYPE', 

139 'FILTER_ORDER_TYPE', 

140 'FILTER_PAYLOAD_TYPE', 

141 'REQUESTS_TIMEOUT_SECS', 

142 'h1', 

143 'h2', 

144 'h3', 

145 'h4', 

146 'h5', 

147 'h6', 

148 'dl', 

149 'login', 

150 'markdown_heading', 

151 'markdown_table', 

152 'markdown_list', 

153 'query', 

154 'ol', 

155 'svl', 

156 'table', 

157 'ul', 

158 'kpi_table', 

159 'mbom_table', 

160 'metrics_table', 

161 'parent_children_sections', 

162 'test_plans', 

163] 

164 

165 

166@no_type_check 

167def init_logger(name=None, level=None): 

168 """Initialize module level logger""" 

169 global log # pylint: disable=global-statement 

170 

171 log_format = { 

172 'format': '%(asctime)s.%(msecs)03d %(levelname)s [%(name)s]: %(message)s', 

173 'datefmt': '%Y-%m-%dT%H:%M:%S', 

174 # 'filename': LOG_PATH, 

175 'level': LOG_LEVEL if level is None else level, 

176 } 

177 logging.basicConfig(**log_format) 

178 log = logging.getLogger(APP_ENV if name is None else name) 

179 log.propagate = True 

180 

181 

182init_logger(name=APP_ENV, level=logging.DEBUG if DEBUG else None)