Coverage for liitos/meta.py: 79.16%

617 statements  

« prev     ^ index     » next       coverage.py v7.6.8, created at 2024-11-25 15:36:16 +00:00

1"""Weave the content of the meta file(s) of metadata.tex.in into the output metadata.tex.""" 

2 

3import datetime as dti 

4import os 

5import pathlib 

6from typing import Union, no_type_check 

7 

8import yaml 

9 

10import liitos.gather as gat 

11import liitos.template as tpl 

12import liitos.tools as too 

13from liitos import ENCODING, ExternalsType, KNOWN_APPROVALS_STRATEGIES, LOG_SEPARATOR, log 

14 

15VALUE_SLOT = 'VALUE.SLOT' 

16DOC_BASE = pathlib.Path('..', '..') 

17STRUCTURE_PATH = DOC_BASE / 'structure.yml' 

18MAGIC_OF_TODAY = 'PUBLICATIONDATE' 

19 

20WEAVE_DEFAULTS = { 

21 'approvals_adjustable_vertical_space': '2.5em', 

22 'approvals_strategy': KNOWN_APPROVALS_STRATEGIES[0], 

23 'bold_font': 'ITCFranklinGothicStd-Demi', 

24 'bold_italic_font': 'ITCFranklinGothicStd-DemiIt', 

25 'bookmatter_path': '', 

26 'change_log_tune_header_sep': '-0em', 

27 'chosen_logo': '/opt/logo/liitos-logo.png', 

28 'chosen_title_page_logo': '/opt/logo/liitos-logo.png', 

29 'code_fontsize': r'\scriptsize', 

30 'driver_path': '', 

31 'fixed_font_package': 'sourcecodepro', 

32 'font_path': '/opt/fonts/', 

33 'font_suffix': '.otf', 

34 'footer_frame_note': os.getenv('LIITOS_FOOTER_FRAME_NOTE', ' '), # TODO 

35 'footer_outer_field_normal_pages': r'\theMetaPageNumPrefix { } \thepage { }', 

36 'italic_font': 'ITCFranklinGothicStd-BookIt', 

37 'lox_indent': r'\hspace*{0.40\textwidth}', # old default was '' for left align 

38 'main_font': 'ITCFranklinGothicStd-Book', 

39 'metadata_path': '', 

40 'proprietary_information': '/opt/legal/proprietary-information.txt', 

41 'proprietary_information_adjustable_vertical_space': '-0em', 

42 'proprietary_information_tune_header_sep': '-0em', 

43 'publisher_path': '', 

44 'setup_path': '', 

45 'stretch': '1.04', # old default was 1.2 

46 'table_captions_below': False, 

47 'table_uglify': False, 

48 'toc_all_dots': '', # old default was not toc all dots, so '%' would restore 

49} 

50ACROSS = { 

51 'eff_font_folder': '', 

52 'eff_font_suffix': '', 

53} 

54 

55 

56@no_type_check 

57def process_meta(aspects: dict[str, str]) -> Union[gat.Meta, int]: 

58 """TODO.""" 

59 meta_path = DOC_BASE / aspects[gat.KEY_META] 

60 if not meta_path.is_file() or not meta_path.stat().st_size: 60 ↛ 61line 60 didn't jump to line 61 because the condition on line 60 was never true

61 log.error(f'destructure failed to find non-empty meta file at {meta_path}') 

62 return 1 

63 if meta_path.suffix.lower() not in ('.yaml', '.yml'): 63 ↛ 64line 63 didn't jump to line 64 because the condition on line 63 was never true

64 return 1 

65 with open(meta_path, 'rt', encoding=ENCODING) as handle: 

66 metadata = yaml.safe_load(handle) 

67 if not metadata: 67 ↛ 68line 67 didn't jump to line 68 because the condition on line 67 was never true

68 log.error(f'empty metadata file? Please add metadata to ({meta_path})') 

69 return 1 

70 if 'import' in metadata['document']: 70 ↛ 83line 70 didn't jump to line 83 because the condition on line 70 was always true

71 base_meta_path = DOC_BASE / metadata['document']['import'] 

72 if not base_meta_path.is_file() or not base_meta_path.stat().st_size: 72 ↛ 73line 72 didn't jump to line 73 because the condition on line 72 was never true

73 log.error( 

74 f'metadata declares import of base data from ({base_meta_path.name})' 

75 f' but failed to find non-empty base file at {base_meta_path}' 

76 ) 

77 return 1 

78 with open(base_meta_path, 'rt', encoding=ENCODING) as handle: 

79 base_data = yaml.safe_load(handle) 

80 for key, value in metadata['document']['patch'].items(): 

81 base_data['document']['common'][key] = value 

82 metadata = base_data 

83 with open('metadata.yml', 'wt', encoding=ENCODING) as handle: 

84 yaml.dump(metadata, handle, default_flow_style=False) 

85 return metadata 

86 

87 

88@no_type_check 

89def weave_setup_font_path( 

90 mapper: dict[str, Union[str, int, bool, None]], 

91 text: str, 

92) -> str: 

93 """Weave in the xxxx from mapper or default for driver. 

94 

95 Trigger is text.rstrip().endswith('%%_PATCH_%_FONT_%_PATH_%%') 

96 """ 

97 defaults = {**WEAVE_DEFAULTS} 

98 if mapper.get('font_path'): 

99 font_path = mapper.get('font_path') 

100 if not pathlib.Path(font_path).is_dir(): 100 ↛ 101line 100 didn't jump to line 101 because the condition on line 100 was never true

101 log.warning(f'font_path ({font_path}) is no directory on this system - rendering may not work as intended') 

102 ACROSS['eff_font_folder'] = font_path 

103 return text.replace(VALUE_SLOT, font_path) 

104 else: 

105 log.warning(f'font_path value missing ... setting default ({defaults["font_path"]})') 

106 ACROSS['eff_font_folder'] = defaults['font_path'] 

107 return text.replace(VALUE_SLOT, defaults['font_path']) 

108 

109 

110@no_type_check 

111def weave_setup_font_suffix( 

112 mapper: dict[str, Union[str, int, bool, None]], 

113 text: str, 

114) -> str: 

115 """Weave in the font_suffix from mapper or default for driver. 

116 

117 Trigger is text.rstrip().endswith('%%_PATCH_%_FONT_%_SUFFIX_%%') 

118 """ 

119 defaults = {**WEAVE_DEFAULTS} 

120 if mapper.get('font_suffix'): 

121 font_suffix = mapper.get('font_suffix') 

122 if font_suffix not in ('.otf', '.ttf'): 122 ↛ 123line 122 didn't jump to line 123 because the condition on line 122 was never true

123 log.warning(f'font_suffix ({font_suffix}) is unexpected - rendering may not work as intended') 

124 ACROSS['eff_font_suffix'] = font_suffix 

125 return text.replace(VALUE_SLOT, font_suffix) 

126 else: 

127 log.warning(f'font_suffix value missing ... setting default ({defaults["font_suffix"]})') 

128 ACROSS['eff_font_suffix'] = defaults['font_suffix'] 

129 return text.replace(VALUE_SLOT, defaults['font_suffix']) 

130 

131 

132@no_type_check 

133def weave_setup_bold_font( 

134 mapper: dict[str, Union[str, int, bool, None]], 

135 text: str, 

136) -> str: 

137 """Weave in the bold_font from mapper or default for driver. 

138 

139 Trigger is text.rstrip().endswith('%%_PATCH_%_BOLD_%_FONT_%%') 

140 """ 

141 defaults = {**WEAVE_DEFAULTS} 

142 eff_font_folder = ACROSS['eff_font_folder'] 

143 eff_font_suffix = ACROSS['eff_font_suffix'] 

144 if mapper.get('bold_font'): 

145 bold_font = mapper.get('bold_font') 

146 font_path = pathlib.Path(eff_font_folder) / f'{bold_font}{eff_font_suffix}' 

147 if not font_path.is_file(): 147 ↛ 148line 147 didn't jump to line 148 because the condition on line 147 was never true

148 log.warning( 

149 f'bold_font ({bold_font}) is not found' 

150 f' as ({font_path}) on this system - rendering may not work as intended' 

151 ) 

152 return text.replace(VALUE_SLOT, bold_font) 

153 else: 

154 log.warning(f'bold_font value missing ... setting default ({defaults["bold_font"]})') 

155 return text.replace(VALUE_SLOT, defaults['bold_font']) 

156 

157 

158@no_type_check 

159def weave_setup_italic_font( 

160 mapper: dict[str, Union[str, int, bool, None]], 

161 text: str, 

162) -> str: 

163 """Weave in the italic_font from mapper or default for driver. 

164 

165 Trigger is text.rstrip().endswith('%%_PATCH_%_ITALIC_%_FONT_%%') 

166 """ 

167 defaults = {**WEAVE_DEFAULTS} 

168 eff_font_folder = ACROSS['eff_font_folder'] 

169 eff_font_suffix = ACROSS['eff_font_suffix'] 

170 if mapper.get('italic_font'): 

171 italic_font = mapper.get('italic_font') 

172 font_path = pathlib.Path(eff_font_folder) / f'{italic_font}{eff_font_suffix}' 

173 if not font_path.is_file(): 173 ↛ 174line 173 didn't jump to line 174 because the condition on line 173 was never true

174 log.warning( 

175 f'italic_font ({italic_font}) is not found' 

176 f' as ({font_path}) on this system - rendering may not work as intended' 

177 ) 

178 return text.replace(VALUE_SLOT, italic_font) 

179 else: 

180 log.warning(f'italic_font value missing ... setting default ({defaults["italic_font"]})') 

181 return text.replace(VALUE_SLOT, defaults['italic_font']) 

182 

183 

184@no_type_check 

185def weave_setup_bold_italic_font( 

186 mapper: dict[str, Union[str, int, bool, None]], 

187 text: str, 

188) -> str: 

189 """Weave in the bold_italic_font from mapper or default for driver. 

190 

191 Trigger is text.rstrip().endswith('%%_PATCH_%_BOLDITALIC_%_FONT_%%') 

192 """ 

193 defaults = {**WEAVE_DEFAULTS} 

194 eff_font_folder = ACROSS['eff_font_folder'] 

195 eff_font_suffix = ACROSS['eff_font_suffix'] 

196 if mapper.get('bold_italic_font'): 

197 bold_italic_font = mapper.get('bold_italic_font') 

198 font_path = pathlib.Path(eff_font_folder) / f'{bold_italic_font}{eff_font_suffix}' 

199 if not font_path.is_file(): 199 ↛ 200line 199 didn't jump to line 200 because the condition on line 199 was never true

200 log.warning( 

201 f'bold_italic_font ({bold_italic_font}) is not found' 

202 f' as ({font_path}) on this system - rendering may not work as intended' 

203 ) 

204 return text.replace(VALUE_SLOT, bold_italic_font) 

205 else: 

206 log.warning(f'bold_italic_font value missing ... setting default ({defaults["bold_italic_font"]})') 

207 return text.replace(VALUE_SLOT, defaults['bold_italic_font']) 

208 

209 

210@no_type_check 

211def weave_setup_main_font( 

212 mapper: dict[str, Union[str, int, bool, None]], 

213 text: str, 

214) -> str: 

215 """Weave in the main_font from mapper or default for driver. 

216 

217 Trigger is text.rstrip().endswith('%%_PATCH_%_MAIN_%_FONT_%%') 

218 """ 

219 defaults = {**WEAVE_DEFAULTS} 

220 eff_font_folder = ACROSS['eff_font_folder'] 

221 eff_font_suffix = ACROSS['eff_font_suffix'] 

222 if mapper.get('main_font'): 

223 main_font = mapper.get('main_font') 

224 font_path = pathlib.Path(eff_font_folder) / f'{main_font}{eff_font_suffix}' 

225 if not font_path.is_file(): 225 ↛ 226line 225 didn't jump to line 226 because the condition on line 225 was never true

226 log.warning( 

227 f'main_font ({main_font}) is not found' 

228 f' as ({font_path}) on this system - rendering may not work as intended' 

229 ) 

230 return text.replace(VALUE_SLOT, main_font) 

231 else: 

232 log.warning(f'main_font value missing ... setting default ({defaults["main_font"]})') 

233 return text.replace(VALUE_SLOT, defaults['main_font']) 

234 

235 

236@no_type_check 

237def weave_setup_fixed_font_package( 

238 mapper: dict[str, Union[str, int, bool, None]], 

239 text: str, 

240) -> str: 

241 """Weave in the fixed_font_package from mapper or default for driver. 

242 

243 Trigger is text.rstrip().endswith('%%_PATCH_%_FIXED_%_FONT_%_PACKAGE_%%') 

244 """ 

245 defaults = {**WEAVE_DEFAULTS} 

246 if mapper.get('fixed_font_package'): 

247 fixed_font_package = mapper.get('fixed_font_package') 

248 if fixed_font_package != defaults['fixed_font_package']: 248 ↛ 249line 248 didn't jump to line 249 because the condition on line 248 was never true

249 log.warning( 

250 f'fixed_font_package ({fixed_font_package}) has not' 

251 ' been tested on this system - rendering may not work as intended' 

252 ) 

253 return text.replace(VALUE_SLOT, fixed_font_package) 

254 else: 

255 log.warning(f'fixed_font_package value missing ... setting default ({defaults["fixed_font_package"]})') 

256 return text.replace(VALUE_SLOT, defaults['fixed_font_package']) 

257 

258 

259@no_type_check 

260def weave_setup_code_fontsize( 

261 mapper: dict[str, Union[str, int, bool, None]], 

262 text: str, 

263) -> str: 

264 """Weave in the code_fontsize from mapper or default for driver. 

265 

266 Trigger is text.rstrip().endswith('%%_PATCH_%_CODE_%_FONTSIZE_%%') 

267 """ 

268 defaults = {**WEAVE_DEFAULTS} 

269 if mapper.get('code_fontsize'): 

270 code_fontsize = mapper.get('code_fontsize') 

271 valid_code_font_sizes = ( 

272 r'\Huge', 

273 r'\huge', 

274 r'\LARGE', 

275 r'\Large', 

276 r'\large', 

277 r'\normalsize', 

278 r'\small', 

279 r'\footnotesize', 

280 r'\scriptsize', 

281 r'\tiny', 

282 ) 

283 bs = '\\' 

284 sizes = tuple(size[1:] for size in valid_code_font_sizes) 

285 if code_fontsize.startswith(r'\\'): 285 ↛ 286line 285 didn't jump to line 286 because the condition on line 285 was never true

286 code_fontsize = code_fontsize[1:] 

287 if code_fontsize not in valid_code_font_sizes: 287 ↛ 288line 287 didn't jump to line 288 because the condition on line 287 was never true

288 log.error( 

289 f'code_fontsize ({code_fontsize}) is not a valid font size value' 

290 ' - rendering would not work as intended' 

291 ) 

292 log.info(f'valid values for code_fontsize must be in {bs}{(", " + bs).join(sizes)}') 

293 log.warning( 

294 f'overriding code font size value with the (working) default of ({defaults["code_fontsize"]})' 

295 f' - in config that would be {defaults["code_fontsize"]}' 

296 ) 

297 return text.replace(VALUE_SLOT, defaults['code_fontsize']) 

298 else: 

299 return text.replace(VALUE_SLOT, code_fontsize) 

300 else: 

301 log.info( 

302 f'code_fontsize value missing ... setting default ({defaults["code_fontsize"]})' 

303 f' - in config that would be {defaults["code_fontsize"]}' 

304 ) 

305 return text.replace(VALUE_SLOT, defaults['code_fontsize']) 

306 

307 

308@no_type_check 

309def weave_setup_chosen_logo( 

310 mapper: dict[str, Union[str, int, bool, None]], 

311 text: str, 

312) -> str: 

313 """Weave in the chosen_logo from mapper or default for driver. 

314 

315 Trigger is text.rstrip().endswith('%%_PATCH_%_CHOSEN_%_LOGO_%%') 

316 """ 

317 defaults = {**WEAVE_DEFAULTS} 

318 if mapper.get('chosen_logo'): 

319 chosen_logo = mapper.get('chosen_logo') 

320 logo_path = pathlib.Path(chosen_logo) 

321 if not logo_path.is_file(): 321 ↛ 322line 321 didn't jump to line 322 because the condition on line 321 was never true

322 log.warning( 

323 f'chosen_logo ({chosen_logo}) is not found' 

324 f' as ({logo_path}) on this system - rendering may not work as intended' 

325 ) 

326 return text.replace(VALUE_SLOT, chosen_logo) 

327 else: 

328 log.info(f'chosen_logo value missing ... setting default ({defaults["chosen_logo"]})') 

329 return text.replace(VALUE_SLOT, defaults['chosen_logo']) 

330 

331 

332@no_type_check 

333def weave_setup_chosen_title_page_logo( 

334 mapper: dict[str, Union[str, int, bool, None]], 

335 text: str, 

336) -> str: 

337 """Weave in the chosen_logo from mapper or default for driver. 

338 

339 Trigger is text.rstrip().endswith('%%_PATCH_%_CHOSEN_%_TITLE_%_PAGE_%_LOGO_%%') 

340 """ 

341 defaults = {**WEAVE_DEFAULTS} 

342 log.warning(text) 

343 if mapper.get('chosen_title_page_logo'): 

344 chosen_title_page_logo = mapper.get('chosen_title_page_logo') 

345 title_page_logo_path = pathlib.Path(chosen_title_page_logo) 

346 log.warning(f'found {chosen_title_page_logo}') 

347 if not title_page_logo_path.is_file(): 347 ↛ 348line 347 didn't jump to line 348 because the condition on line 347 was never true

348 log.warning( 

349 f'chosen_title_page_logo ({chosen_title_page_logo}) is not found' 

350 f' as ({title_page_logo_path}) on this system - rendering may not work as intended' 

351 ) 

352 return text.replace(VALUE_SLOT, chosen_title_page_logo) 

353 else: 

354 log.warning('default logo') 

355 log.info(f'chosen_title_page_logo value missing ... setting default ({defaults["chosen_title_page_logo"]})') 

356 return text.replace(VALUE_SLOT, defaults['chosen_title_page_logo']) 

357 

358 

359@no_type_check 

360def weave_setup_footer_outer_field_normal_pages( 

361 mapper: dict[str, Union[str, int, bool, None]], 

362 text: str, 

363) -> str: 

364 """Weave in the footer_outer_field_normal_pages from mapper or default for driver. 

365 

366 Trigger is text.rstrip().endswith('%%_PATCH_%_NORMAL_%_PAGES_%_OUTER_%_FOOT_%_CONTENT_%_VALUE_%%') 

367 """ 

368 defaults = {**WEAVE_DEFAULTS} 

369 if mapper.get('footer_outer_field_normal_pages'): 369 ↛ 373line 369 didn't jump to line 373 because the condition on line 369 was always true

370 footer_outer_field_normal_pages = mapper.get('footer_outer_field_normal_pages') 

371 return text.replace(VALUE_SLOT, footer_outer_field_normal_pages) 

372 else: 

373 log.info( 

374 'footer_outer_field_normal_pages value missing ...' 

375 f' setting default ({defaults["footer_outer_field_normal_pages"]})' 

376 ) 

377 return text.replace(VALUE_SLOT, defaults['footer_outer_field_normal_pages']) 

378 

379 

380@no_type_check 

381def weave_setup_toc_all_dots( 

382 mapper: dict[str, Union[str, int, bool, None]], 

383 text: str, 

384) -> str: 

385 """Weave in the toc_all_dots from mapper or default for driver. 

386 

387 Trigger is text.rstrip().endswith('%%_PATCH_%_TOC_ALL_DOTS_%%') 

388 """ 

389 defaults = {**WEAVE_DEFAULTS} 

390 if mapper.get('toc_all_dots'): 390 ↛ 391line 390 didn't jump to line 391 because the condition on line 390 was never true

391 toc_all_dots = mapper.get('toc_all_dots') 

392 return text.replace(VALUE_SLOT, toc_all_dots) 

393 else: 

394 log.info('toc_all_dots value missing ...' f' setting default ({defaults["toc_all_dots"]})') 

395 return text.replace(VALUE_SLOT, defaults['toc_all_dots']) 

396 

397 

398@no_type_check 

399def dispatch_setup_weaver( 

400 mapper: dict[str, Union[str, int, bool, None]], 

401 text: str, 

402) -> str: 

403 """Dispatch the driver weaver by mapping to handled groups per source marker.""" 

404 dispatch = { 

405 '%%_PATCH_%_FONT_%_PATH_%%': weave_setup_font_path, 

406 '%%_PATCH_%_FONT_%_SUFFIX_%%': weave_setup_font_suffix, 

407 '%%_PATCH_%_BOLD_%_FONT_%%': weave_setup_bold_font, 

408 '%%_PATCH_%_ITALIC_%_FONT_%%': weave_setup_italic_font, 

409 '%%_PATCH_%_BOLDITALIC_%_FONT_%%': weave_setup_bold_italic_font, 

410 '%%_PATCH_%_MAIN_%_FONT_%%': weave_setup_main_font, 

411 '%%_PATCH_%_FIXED_%_FONT_%_PACKAGE_%%': weave_setup_fixed_font_package, 

412 '%%_PATCH_%_CODE_%_FONTSIZE_%%': weave_setup_code_fontsize, 

413 '%%_PATCH_%_CHOSEN_%_LOGO_%%': weave_setup_chosen_logo, 

414 '%%_PATCH_%_CHOSEN_%_TITLE_%_PAGE_%_LOGO_%%': weave_setup_chosen_title_page_logo, 

415 '%%_PATCH_%_NORMAL_%_PAGES_%_OUTER_%_FOOT_%_CONTENT_%_VALUE_%%': weave_setup_footer_outer_field_normal_pages, 

416 '%%_PATCH_%_TOC_ALL_DOTS_%%': weave_setup_toc_all_dots, 

417 } 

418 for trigger, weaver in dispatch.items(): 

419 if text.rstrip().endswith(trigger): 

420 return weaver(mapper, text) 

421 return text 

422 

423 

424@no_type_check 

425def weave_meta_setup(meta_map: gat.Meta, latex: list[str]) -> list[str]: 

426 """TODO.""" 

427 log.info('weaving in the meta data per setup.tex.in into setup.tex ...') 

428 completed = [dispatch_setup_weaver(meta_map['document']['common'], line) for line in latex] 

429 if completed and completed[-1]: 

430 completed.append('\n') 

431 return completed 

432 

433 

434@no_type_check 

435def weave_driver_toc_level( 

436 mapper: dict[str, Union[str, int, bool, None]], 

437 text: str, 

438) -> str: 

439 """Weave in the toc_level from mapper or default for driver. 

440 

441 Trigger is text.rstrip().endswith('%%_PATCH_%_TOC_%_LEVEL_%%') 

442 """ 

443 toc_level = 2 

444 if mapper.get('toc_level'): 

445 try: 

446 toc_level_read = int(mapper['toc_level']) 

447 toc_level = toc_level_read if 0 < toc_level_read < 5 else 2 

448 if toc_level != toc_level_read: 

449 log.warning( 

450 f'ignored toc level ({toc_level_read}) set to default (2) - expected value 0 < toc_level < 5' 

451 ) 

452 except ValueError as err: 

453 toc_level = 2 

454 log.warning(f'toc_level ({mapper["toc_level"]}) not in (1, 2, 3, 4) - resorting to default ({toc_level})') 

455 log.error(f'error detail: {err}') 

456 else: 

457 log.info(f'toc_level value missing ... setting default ({toc_level})') 

458 return text.replace(VALUE_SLOT, str(toc_level)) 

459 

460 

461@no_type_check 

462def weave_driver_list_of_figures( 

463 mapper: dict[str, Union[str, int, bool, None]], 

464 text: str, 

465) -> str: 

466 """Weave in the list_of_figures from mapper or default for driver. 

467 

468 Trigger is text.rstrip().endswith('%%_PATCH_%_LOF_%%') 

469 """ 

470 if mapper.get('list_of_figures', None) is not None: 

471 lof = mapper['list_of_figures'] 

472 if lof in ('', '%'): 

473 return text.replace(VALUE_SLOT, str(lof)) 

474 else: 

475 lof = '%' 

476 log.warning( 

477 f"list_of_figures ({mapper['list_of_figures']}) not in ('', '%')" 

478 f' - resorting to default ({lof}) i.e. commenting out the list of figures' 

479 ) 

480 else: 

481 log.info('list_of_figures value missing ... setting default (comment out the lof per %)') 

482 

483 return text.replace(VALUE_SLOT, '%') 

484 

485 

486@no_type_check 

487def weave_driver_list_of_tables( 

488 mapper: dict[str, Union[str, int, bool, None]], 

489 text: str, 

490) -> str: 

491 """Weave in the list_of_tables from mapper or default for driver. 

492 

493 Trigger is text.rstrip().endswith('%%_PATCH_%_LOT_%%') 

494 """ 

495 if mapper.get('list_of_tables', None) is not None: 

496 lof = mapper['list_of_tables'] 

497 if lof in ('', '%'): 

498 return text.replace(VALUE_SLOT, str(lof)) 

499 else: 

500 lof = '%' 

501 log.warning( 

502 f"list_of_tables ({mapper['list_of_tables']}) not in ('', '%')" 

503 f' - resorting to default ({lof}) i.e. commenting out the list of tables' 

504 ) 

505 else: 

506 log.info('list_of_tables value missing ... setting default (comment out the lot per %)') 

507 

508 return text.replace(VALUE_SLOT, '%') 

509 

510 

511@no_type_check 

512def dispatch_driver_weaver( 

513 mapper: dict[str, Union[str, int, bool, None]], 

514 text: str, 

515) -> str: 

516 """Dispatch the driver weaver by mapping to handled groups per source marker.""" 

517 dispatch = { 

518 '%%_PATCH_%_TOC_%_LEVEL_%%': weave_driver_toc_level, 

519 '%%_PATCH_%_LOF_%%': weave_driver_list_of_figures, 

520 '%%_PATCH_%_LOT_%%': weave_driver_list_of_tables, 

521 } 

522 for trigger, weaver in dispatch.items(): 

523 if text.rstrip().endswith(trigger): 

524 return weaver(mapper, text) 

525 return text 

526 

527 

528@no_type_check 

529def weave_meta_driver(meta_map: gat.Meta, latex: list[str]) -> list[str]: 

530 """TODO.""" 

531 log.info('weaving in the meta data per driver.tex.in into driver.tex ...') 

532 completed = [dispatch_driver_weaver(meta_map['document']['common'], line) for line in latex] 

533 if completed and completed[-1]: 

534 completed.append('\n') 

535 return completed 

536 

537 

538@no_type_check 

539def weave_meta_part_header_title( 

540 mapper: dict[str, Union[str, int, bool, None]], 

541 text: str, 

542) -> str: 

543 """Weave in the header_title from mapper or default. 

544 

545 Trigger is text.rstrip().endswith('%%_PATCH_%_HEADER_%_TITLE_%%') 

546 """ 

547 if mapper.get('header_title'): 

548 return text.replace(VALUE_SLOT, mapper['header_title']) 

549 else: 

550 log.info('header_title value missing ... setting default (the title value)') 

551 return text.replace(VALUE_SLOT, mapper['title']) 

552 

553 

554@no_type_check 

555def weave_meta_part_title_slug( 

556 mapper: dict[str, Union[str, int, bool, None]], 

557 text: str, 

558) -> str: 

559 """Weave in the title slug deriving from mapper or default. 

560 

561 Trigger is text.rstrip().endswith('%%_PATCH_%_MAIN_%_TITLE_%_SLUG_%%') 

562 """ 

563 if mapper.get('bookmark_title'): 563 ↛ 564line 563 didn't jump to line 564 because the condition on line 563 was never true

564 return text.replace(VALUE_SLOT, mapper['bookmark_title']) 

565 else: 

566 log.info('bookmark_title value missing ... setting default (the slugged title value)') 

567 return text.replace(VALUE_SLOT, mapper['title'].replace('\\\\', '').replace(' ', ' ').title()) 

568 

569 

570@no_type_check 

571def weave_meta_part_title( 

572 mapper: dict[str, Union[str, int, bool, None]], 

573 text: str, 

574) -> str: 

575 """Weave in the title from mapper or default. 

576 

577 Trigger is text.rstrip().endswith('%%_PATCH_%_MAIN_%_TITLE_%%') 

578 """ 

579 return text.replace(VALUE_SLOT, mapper['title']) 

580 

581 

582@no_type_check 

583def weave_meta_part_sub_title( 

584 mapper: dict[str, Union[str, int, bool, None]], 

585 text: str, 

586) -> str: 

587 """Weave in the sub_title from mapper or default. 

588 

589 Trigger is text.rstrip().endswith('%%_PATCH_%_SUB_%_TITLE_%%') 

590 """ 

591 if mapper.get('sub_title'): 

592 return text.replace(VALUE_SLOT, mapper['sub_title']) 

593 else: 

594 log.info('sub_title value missing ... setting default (single space)') 

595 return text.replace(VALUE_SLOT, ' ') 

596 

597 

598@no_type_check 

599def weave_meta_part_header_type( 

600 mapper: dict[str, Union[str, int, bool, None]], 

601 text: str, 

602) -> str: 

603 """Weave in the header_type from mapper or default. 

604 

605 Trigger is text.rstrip().endswith('%%_PATCH_%_TYPE_%%') 

606 """ 

607 if mapper.get('header_type'): 

608 return text.replace(VALUE_SLOT, mapper['header_type']) 

609 else: 

610 log.info('header_type value missing ... setting default (Engineering Document)') 

611 return text.replace(VALUE_SLOT, 'Engineering Document') 

612 

613 

614@no_type_check 

615def weave_meta_part_header_id_label( 

616 mapper: dict[str, Union[str, int, bool, None]], 

617 text: str, 

618) -> str: 

619 """Weave in the header_id_label from mapper or default. 

620 

621 Trigger is text.rstrip().endswith('%%_PATCH_%_ID_%_LABEL_%%') 

622 """ 

623 if mapper.get('header_id_show', None) is not None and not mapper['header_id_show']: 623 ↛ 624line 623 didn't jump to line 624 because the condition on line 623 was never true

624 log.info('header_id_show set to false - hiding id slot in header by setting label to a single space(" ")') 

625 return text.replace(VALUE_SLOT, ' ') 

626 log.info('header_id_show not set - considering header_id_label ...') 

627 if mapper.get('header_id_label'): 627 ↛ 628line 627 didn't jump to line 628 because the condition on line 627 was never true

628 pub_id_label = mapper['header_id_label'].strip() 

629 if not pub_id_label: 

630 pub_id_label = ' ' # single space to please the backend parser 

631 return text.replace(VALUE_SLOT, pub_id_label) 

632 else: 

633 log.info('header_id_label value missing ... setting default(Doc. ID:)') 

634 return text.replace(VALUE_SLOT, 'Doc. ID:') 

635 

636 

637@no_type_check 

638def weave_meta_part_header_id( 

639 mapper: dict[str, Union[str, int, bool, None]], 

640 text: str, 

641) -> str: 

642 """Weave in the header_id from mapper or default. 

643 

644 Trigger is text.rstrip().endswith('%%_PATCH_%_ID_%%') 

645 """ 

646 if mapper.get('header_id_show', None) is not None and not mapper['header_id_show']: 646 ↛ 647line 646 didn't jump to line 647 because the condition on line 646 was never true

647 log.info('header_id_show set to false - hiding id slot in header by setting value to a single space(" ")') 

648 return text.replace(VALUE_SLOT, ' ') 

649 log.info('header_id_show not set - considering header_id ...') 

650 if mapper.get('header_id'): 

651 return text.replace(VALUE_SLOT, mapper['header_id']) 

652 else: 

653 log.info('header_id value missing ... setting default (N/A)') 

654 return text.replace(VALUE_SLOT, 'N/A') 

655 

656 

657@no_type_check 

658def weave_meta_part_issue( 

659 mapper: dict[str, Union[str, int, bool, None]], 

660 text: str, 

661) -> str: 

662 """Weave in the issue from mapper or default. 

663 

664 Trigger is text.rstrip().endswith('%%_PATCH_%_ISSUE_%%') 

665 """ 

666 if mapper.get('issue'): 

667 return text.replace(VALUE_SLOT, mapper['issue']) 

668 else: 

669 log.info('issue value missing ... setting default (01)') 

670 return text.replace(VALUE_SLOT, '01') 

671 

672 

673@no_type_check 

674def weave_meta_part_revision( 

675 mapper: dict[str, Union[str, int, bool, None]], 

676 text: str, 

677) -> str: 

678 """Weave in the revision from mapper or default. 

679 

680 Trigger is text.rstrip().endswith('%%_PATCH_%_REVISION_%%') 

681 """ 

682 if mapper.get('revision'): 

683 return text.replace(VALUE_SLOT, mapper['revision']) 

684 else: 

685 log.info('revision value missing ... setting default (00)') 

686 return text.replace(VALUE_SLOT, '00') 

687 

688 

689@no_type_check 

690def weave_meta_part_header_date_label( 

691 mapper: dict[str, Union[str, int, bool, None]], 

692 text: str, 

693) -> str: 

694 """Weave in the header_date_label from mapper or default. 

695 

696 Trigger is text.rstrip().endswith('%%_PATCH_%_DATE_%_LABEL_%%') 

697 """ 

698 if mapper.get('header_date_show', None) is not None and not mapper['header_date_show']: 698 ↛ 699line 698 didn't jump to line 699 because the condition on line 698 was never true

699 log.info('header_date_show set to false - hiding date slot in header by setting label to a single space(" ")') 

700 return text.replace(VALUE_SLOT, ' ') 

701 log.info('header_date_show not set - considering header_date_label ...') 

702 if mapper.get('header_date_label'): 702 ↛ 703line 702 didn't jump to line 703 because the condition on line 702 was never true

703 pub_date_label = mapper['header_date_label'].strip() 

704 if not pub_date_label: 

705 pub_date_label = ' ' # single space to please the backend parser 

706 return text.replace(VALUE_SLOT, pub_date_label) 

707 else: 

708 log.info('header_date_label value missing ... setting default(" ")') 

709 return text.replace(VALUE_SLOT, ' ') 

710 

711 

712@no_type_check 

713def weave_meta_part_header_date( 

714 mapper: dict[str, Union[str, int, bool, None]], 

715 text: str, 

716) -> str: 

717 """Weave in the header_date from mapper or default. 

718 

719 Trigger is text.rstrip().endswith('%%_PATCH_%_DATE_%%') 

720 """ 

721 if mapper.get('header_date_show', None) is not None and not mapper['header_date_show']: 721 ↛ 722line 721 didn't jump to line 722 because the condition on line 721 was never true

722 log.info('header_date_show set to false - hiding date slot in header by setting value to a single space(" ")') 

723 return text.replace(VALUE_SLOT, ' ') 

724 log.info('header_date_show not set - considering header_date ...') 

725 if mapper.get('header_date_enable_auto', None) is not None and not mapper['header_date_enable_auto']: 725 ↛ 726line 725 didn't jump to line 726 because the condition on line 725 was never true

726 log.info('header_date_enable_auto set to false - setting that slot value as is (no date semantics enforced)') 

727 if mapper.get('header_date'): 

728 pub_date_or_any = mapper['header_date'].strip() 

729 if not pub_date_or_any: 

730 pub_date_or_any = ' ' # single space to please the backend parser 

731 return text.replace(VALUE_SLOT, pub_date_or_any) 

732 else: 

733 log.info('header_date value missing and as-is mode ... setting to single space ( ) a.k.a. hiding') 

734 return text.replace(VALUE_SLOT, ' ') 

735 else: 

736 today = dti.datetime.today() 

737 pub_date_today = today.strftime('%d %b %Y').upper() 

738 if mapper.get('header_date'): 

739 pub_date = mapper['header_date'].strip() 

740 if pub_date == MAGIC_OF_TODAY: 

741 pub_date = pub_date_today 

742 return text.replace(VALUE_SLOT, pub_date) 

743 else: 

744 log.info('header_date value missing ... setting default as empty(" ")') 

745 return text.replace(VALUE_SLOT, ' ') 

746 

747 

748@no_type_check 

749def weave_meta_part_footer_frame_note( 

750 mapper: dict[str, Union[str, int, bool, None]], 

751 text: str, 

752) -> str: 

753 """Weave in the footer_frame_note from mapper or default. 

754 

755 Trigger is text.rstrip().endswith('%%_PATCH_%_FRAME_%_NOTE_%%') 

756 """ 

757 if mapper.get('footer_frame_note'): 

758 return text.replace(VALUE_SLOT, mapper['footer_frame_note']) 

759 else: 

760 log.info('footer_frame_note value missing ... setting default from module / environment ...') 

761 return text.replace(VALUE_SLOT, WEAVE_DEFAULTS['footer_frame_note']) 

762 

763 

764@no_type_check 

765def weave_meta_part_footer_page_number_prefix( 

766 mapper: dict[str, Union[str, int, bool, None]], 

767 text: str, 

768) -> str: 

769 """Weave in the footer_page_number_prefix from mapper or default. 

770 

771 Trigger is text.rstrip().endswith('%%_PATCH_%_FOOT_%_PAGE_%_COUNTER_%_LABEL_%%') 

772 """ 

773 if mapper.get('footer_page_number_prefix'): 

774 return text.replace(VALUE_SLOT, mapper['footer_page_number_prefix']) 

775 else: 

776 log.info('footer_page_number_prefix value missing ... setting default (Page)') 

777 return text.replace(VALUE_SLOT, 'Page') 

778 

779 

780@no_type_check 

781def weave_meta_part_change_log_issue_label( 

782 mapper: dict[str, Union[str, int, bool, None]], 

783 text: str, 

784) -> str: 

785 """Weave in the change_log_issue_label from mapper or default. 

786 

787 Trigger is text.rstrip().endswith('%%_PATCH_%_CHANGELOG_%_ISSUE_%_LABEL_%%') 

788 """ 

789 if mapper.get('change_log_issue_label'): 

790 return text.replace(VALUE_SLOT, mapper['change_log_issue_label']) 

791 else: 

792 log.info('change_log_issue_label value missing ... setting default (Iss.)') 

793 return text.replace(VALUE_SLOT, 'Iss.') 

794 

795 

796@no_type_check 

797def weave_meta_part_change_log_revision_label( 

798 mapper: dict[str, Union[str, int, bool, None]], 

799 text: str, 

800) -> str: 

801 """Weave in the change_log_revision_label from mapper or default. 

802 

803 Trigger is text.rstrip().endswith('%%_PATCH_%_CHANGELOG_%_REVISION_%_LABEL_%%') 

804 """ 

805 if mapper.get('change_log_revision_label'): 

806 return text.replace(VALUE_SLOT, mapper['change_log_revision_label']) 

807 else: 

808 log.info('change_log_revision_label value missing ... setting default (Rev.)') 

809 return text.replace(VALUE_SLOT, 'Rev.') 

810 

811 

812@no_type_check 

813def weave_meta_part_change_log_date_label( 

814 mapper: dict[str, Union[str, int, bool, None]], 

815 text: str, 

816) -> str: 

817 """Weave in the change_log_date_label from mapper or default. 

818 

819 Trigger is text.rstrip().endswith('%%_PATCH_%_CHANGELOG_%_DATE_%_LABEL_%%') 

820 """ 

821 if mapper.get('change_log_date_label'): 

822 return text.replace(VALUE_SLOT, mapper['change_log_date_label']) 

823 else: 

824 log.info('change_log_date_label value missing ... setting default (Date)') 

825 return text.replace(VALUE_SLOT, 'Date') 

826 

827 

828@no_type_check 

829def weave_meta_part_change_log_author_label( 

830 mapper: dict[str, Union[str, int, bool, None]], 

831 text: str, 

832) -> str: 

833 """Weave in the change_log_author_label from mapper or default. 

834 

835 Trigger is text.rstrip().endswith('%%_PATCH_%_CHANGELOG_%_AUTHOR_%_LABEL_%%') 

836 """ 

837 if mapper.get('change_log_author_label'): 

838 return text.replace(VALUE_SLOT, mapper['change_log_author_label']) 

839 else: 

840 log.info('change_log_author_label value missing ... setting default (Author)') 

841 return text.replace(VALUE_SLOT, 'Author') 

842 

843 

844@no_type_check 

845def weave_meta_part_change_log_description_label( 

846 mapper: dict[str, Union[str, int, bool, None]], 

847 text: str, 

848) -> str: 

849 """Weave in the change_log_description_label from mapper or default. 

850 

851 Trigger is text.rstrip().endswith('%%_PATCH_%_CHANGELOG_%_DESCRIPTION_%_LABEL_%%') 

852 """ 

853 if mapper.get('change_log_description_label'): 

854 return text.replace(VALUE_SLOT, mapper['change_log_description_label']) 

855 else: 

856 log.info('change_log_description_label value missing ... setting default (Description)') 

857 return text.replace(VALUE_SLOT, 'Description') 

858 

859 

860@no_type_check 

861def weave_meta_part_with_default_slot( 

862 mapper: dict[str, Union[str, int, bool, None]], 

863 text: str, 

864 slot: str, 

865) -> str: 

866 """Do the conditional weaving of slot if text matches else used default (and log a warning).""" 

867 if mapper.get(slot): 

868 return text.replace(VALUE_SLOT, mapper[slot]) 

869 else: 

870 log.info(f'{slot} value missing ... setting default ({WEAVE_DEFAULTS[slot]})') 

871 return text.replace(VALUE_SLOT, WEAVE_DEFAULTS[slot]) 

872 

873 

874@no_type_check 

875def weave_meta_part_approvals_adjustable_vertical_space( 

876 mapper: dict[str, Union[str, int, bool, None]], 

877 text: str, 

878) -> str: 

879 """Weave in the approvals_adjustable_vertical_space from mapper or default. 

880 

881 Trigger is text.rstrip().endswith('%%_PATCH_%_APPROVALS_%_ADJUSTABLE_%_VERTICAL_%_SPACE_%%') 

882 """ 

883 return weave_meta_part_with_default_slot(mapper, text, 'approvals_adjustable_vertical_space') 

884 

885 

886@no_type_check 

887def weave_meta_part_proprietary_information_adjustable_vertical_space( 

888 mapper: dict[str, Union[str, int, bool, None]], 

889 text: str, 

890) -> str: 

891 """Weave in the proprietary_information_adjustable_vertical_space from mapper or default. 

892 

893 Trigger is text.rstrip().endswith('%%_PATCH_%_BLURB_%_ADJUSTABLE_%_VERTICAL_%_SPACE_%%') 

894 """ 

895 return weave_meta_part_with_default_slot(mapper, text, 'proprietary_information_adjustable_vertical_space') 

896 

897 

898@no_type_check 

899def weave_meta_part_proprietary_information_tune_header_sep( 

900 mapper: dict[str, Union[str, int, bool, None]], 

901 text: str, 

902) -> str: 

903 """Weave in the proprietary_information_tune_header_sep from mapper or default. 

904 

905 Trigger is text.rstrip().endswith('%%_PATCH_%_BLURB_%_TUNE_%_HEADER_%_SEP_%%') 

906 """ 

907 return weave_meta_part_with_default_slot(mapper, text, 'proprietary_information_tune_header_sep') 

908 

909 

910@no_type_check 

911def weave_meta_part_change_log_tune_header_sep( 

912 mapper: dict[str, Union[str, int, bool, None]], 

913 text: str, 

914) -> str: 

915 """Weave in the change_log_tune_header_sep from mapper or default. 

916 

917 Trigger is text.rstrip().endswith('%%_PATCH_%_CHANGE_%_LOG_%_TUNE_%_HEADER_%_SEP_%%') 

918 """ 

919 return weave_meta_part_with_default_slot(mapper, text, 'change_log_tune_header_sep') 

920 

921 

922@no_type_check 

923def weave_meta_part_approvals_department_label( 

924 mapper: dict[str, Union[str, int, bool, None]], 

925 text: str, 

926) -> str: 

927 """Weave in the approvals_department_label from mapper or default. 

928 

929 Trigger is text.rstrip().endswith('%%_PATCH_%_APPROVALS_%_DEPARTMENT_%_LABEL_%%') 

930 """ 

931 if mapper.get('approvals_department_label'): 

932 return text.replace(VALUE_SLOT, mapper['approvals_department_label']) 

933 else: 

934 log.info('approvals_department_label value missing ... setting default (Department)') 

935 return text.replace(VALUE_SLOT, 'Department') 

936 

937 

938@no_type_check 

939def weave_meta_part_approvals_department_value( 

940 mapper: dict[str, Union[str, int, bool, None]], 

941 text: str, 

942) -> str: 

943 """Weave in the approvals_department_value from mapper or default. 

944 

945 Trigger is text.rstrip().endswith('%%_PATCH_%_APPROVALS_%_DEPARTMENT_%_VALUE_%%') 

946 """ 

947 if mapper.get('approvals_department_value'): 947 ↛ 950line 947 didn't jump to line 950 because the condition on line 947 was always true

948 return text.replace(VALUE_SLOT, mapper['approvals_department_value']) 

949 else: 

950 log.info('approvals_department_value value missing ... setting default ( )') 

951 return text.replace(VALUE_SLOT, ' ') 

952 

953 

954@no_type_check 

955def weave_meta_part_approvals_role_label( 

956 mapper: dict[str, Union[str, int, bool, None]], 

957 text: str, 

958) -> str: 

959 """Weave in the approvals_role_label from mapper or default. 

960 

961 Trigger is text.rstrip().endswith('%%_PATCH_%_APPROVALS_%_ROLE_%_LABEL_%%') 

962 """ 

963 if mapper.get('approvals_role_label'): 

964 return text.replace(VALUE_SLOT, mapper['approvals_role_label']) 

965 else: 

966 log.info('approvals_role_label value missing ... setting default (Approvals)') 

967 return text.replace(VALUE_SLOT, 'Approvals') 

968 

969 

970@no_type_check 

971def weave_meta_part_approvals_name_label( 

972 mapper: dict[str, Union[str, int, bool, None]], 

973 text: str, 

974) -> str: 

975 """Weave in the approvals_name_label from mapper or default. 

976 

977 Trigger is text.rstrip().endswith('%%_PATCH_%_APPROVALS_%_NAME_%_LABEL_%%') 

978 """ 

979 if mapper.get('approvals_name_label'): 

980 return text.replace(VALUE_SLOT, mapper['approvals_name_label']) 

981 else: 

982 log.info('approvals_name_label value missing ... setting default (Name)') 

983 return text.replace(VALUE_SLOT, 'Name') 

984 

985 

986@no_type_check 

987def weave_meta_part_approvals_date_and_signature_label( 

988 mapper: dict[str, Union[str, int, bool, None]], 

989 text: str, 

990) -> str: 

991 """Weave in the approvals_date_and_signature_label from mapper or default. 

992 

993 Trigger is text.rstrip().endswith('%%_PATCH_%_APPROVALS_%_DATE_%_AND_%_SIGNATURE_%_LABEL_%%') 

994 """ 

995 if mapper.get('approvals_date_and_signature_label'): 

996 return text.replace(VALUE_SLOT, mapper['approvals_date_and_signature_label']) 

997 else: 

998 log.info('approvals_date_and_signature_label value missing ... setting default (Date and Signature)') 

999 return text.replace(VALUE_SLOT, 'Date and Signature') 

1000 

1001 

1002@no_type_check 

1003def weave_meta_part_header_issue_revision_combined_label( 

1004 mapper: dict[str, Union[str, int, bool, None]], 

1005 text: str, 

1006) -> str: 

1007 """Weave in the header_issue_revision_combined_label from mapper or default. 

1008 

1009 Trigger is text.rstrip().endswith('%%_PATCH_%_ISSUE_%_REVISION_%_COMBINED_%_LABEL_%%') 

1010 """ 

1011 do_show_key = 'header_issue_revision_combined_show' 

1012 if mapper.get(do_show_key, None) is not None and not mapper[do_show_key]: 1012 ↛ 1013line 1012 didn't jump to line 1013 because the condition on line 1012 was never true

1013 log.info(f'{do_show_key} set to false' ' - hiding date slot in header by setting label to a single space(" ")') 

1014 return text.replace(VALUE_SLOT, ' ') 

1015 log.info(f'{do_show_key} not set - considering header_issue_revision_combined_label ...') 

1016 if mapper.get('header_issue_revision_combined_label'): 

1017 head_iss_rev_comb_label = mapper['header_issue_revision_combined_label'].strip() 

1018 if not head_iss_rev_comb_label: 1018 ↛ 1019line 1018 didn't jump to line 1019 because the condition on line 1018 was never true

1019 head_iss_rev_comb_label = ' ' # single space to please the backend parser 

1020 return text.replace(VALUE_SLOT, head_iss_rev_comb_label) 

1021 else: 

1022 log.info('header_issue_revision_combined_label value missing ... setting default(Issue, Revision:)') 

1023 return text.replace(VALUE_SLOT, 'Issue, Revision:') 

1024 

1025 

1026@no_type_check 

1027def weave_meta_part_header_issue_revision_combined( 

1028 mapper: dict[str, Union[str, int, bool, None]], 

1029 text: str, 

1030) -> str: 

1031 """Weave in the header_issue_revision_combined from mapper or default. 

1032 

1033 Trigger is text.rstrip().endswith('%%_PATCH_%_ISSUE_%_REVISION_%_COMBINED_%%') 

1034 """ 

1035 do_show_key = 'header_issue_revision_combined_show' 

1036 if mapper.get(do_show_key, None) is not None and not mapper[do_show_key]: 1036 ↛ 1037line 1036 didn't jump to line 1037 because the condition on line 1036 was never true

1037 log.info(f'{do_show_key} set to false' ' - hiding date slot in header by setting value to a single space(" ")') 

1038 return text.replace(VALUE_SLOT, ' ') 

1039 log.info(f'{do_show_key} not set - considering header_issue_revision_combined ...') 

1040 if mapper.get('header_issue_revision_combined'): 

1041 return text.replace(VALUE_SLOT, mapper['header_issue_revision_combined']) 

1042 else: 

1043 log.info( 

1044 'header_issue_revision_combined value missing ... setting' 

1045 ' default (Iss \\theMetaIssCode, Rev \\theMetaRevCode)' 

1046 ) 

1047 return text.replace(VALUE_SLOT, r'Iss \theMetaIssCode, Rev \theMetaRevCode') 

1048 

1049 

1050@no_type_check 

1051def weave_meta_part_proprietary_information( 

1052 mapper: dict[str, Union[str, int, bool, None]], 

1053 text: str, 

1054) -> str: 

1055 """Weave in the proprietary_information from mapper or default. 

1056 

1057 Trigger is text.rstrip().endswith('%%_PATCH_%_PROPRIETARY_%_INFORMATION_%_LABEL_%%') 

1058 """ 

1059 if mapper.get('proprietary_information'): 

1060 prop_info = mapper['proprietary_information'] 

1061 if pathlib.Path(prop_info).is_file(): 

1062 try: 

1063 prop_info_from_file = pathlib.Path(prop_info).open().read() 

1064 prop_info = prop_info_from_file 

1065 except (OSError, UnicodeDecodeError) as err: 

1066 log.error(f'interpretation of proprietary_information value ({prop_info}) failed with error: {err}') 

1067 log.warning(f'using value ({prop_info}) directly for proprietary_information') 

1068 else: 

1069 log.info(f'using value ({prop_info}) directly for proprietary_information (no file)') 

1070 return text.replace(VALUE_SLOT, prop_info) 

1071 else: 

1072 log.warning('proprietary_information value missing ... setting default from module ...') 

1073 prop_info = WEAVE_DEFAULTS['proprietary_information'] 

1074 if pathlib.Path(prop_info).is_file(): 1074 ↛ 1082line 1074 didn't jump to line 1082 because the condition on line 1074 was always true

1075 try: 

1076 prop_info_from_file = pathlib.Path(prop_info).open().read() 

1077 prop_info = prop_info_from_file 

1078 except (OSError, UnicodeDecodeError) as err: 

1079 log.error(f'interpretation of proprietary_information value ({prop_info}) failed with error: {err}') 

1080 log.warning(f'using value ({prop_info}) directly for proprietary_information') 

1081 else: 

1082 log.info(f'using value ({prop_info}) directly for proprietary_information (no file)') 

1083 return text.replace(VALUE_SLOT, prop_info) 

1084 

1085 

1086@no_type_check 

1087def weave_meta_part_stretch( 

1088 mapper: dict[str, Union[str, int, bool, None]], 

1089 text: str, 

1090) -> str: 

1091 """Weave in the stretch from mapper or default. 

1092 

1093 Trigger is text.rstrip().endswith('%%_PATCH_%_STRETCH_%%') 

1094 """ 

1095 return weave_meta_part_with_default_slot(mapper, text, 'stretch') 

1096 

1097 

1098@no_type_check 

1099def weave_meta_part_lox_indent( 

1100 mapper: dict[str, Union[str, int, bool, None]], 

1101 text: str, 

1102) -> str: 

1103 """Weave in the lox_indent from mapper or default. 

1104 

1105 Trigger is text.rstrip().endswith('%%_PATCH_%_LOX_INDENT_%%') 

1106 """ 

1107 return weave_meta_part_with_default_slot(mapper, text, 'lox_indent') 

1108 

1109 

1110@no_type_check 

1111def dispatch_meta_weaver( 

1112 mapper: dict[str, Union[str, int, bool, None]], 

1113 text: str, 

1114) -> str: 

1115 """Dispatch the meta weaver by mapping to handled groups per source marker.""" 

1116 dispatch = { 

1117 '%%_PATCH_%_HEADER_%_TITLE_%%': weave_meta_part_header_title, 

1118 '%%_PATCH_%_TITLE_%_SLUG_%%': weave_meta_part_title_slug, 

1119 '%%_PATCH_%_MAIN_%_TITLE_%%': weave_meta_part_title, 

1120 '%%_PATCH_%_SUB_%_TITLE_%%': weave_meta_part_sub_title, 

1121 '%%_PATCH_%_TYPE_%%': weave_meta_part_header_type, 

1122 '%%_PATCH_%_ID_%_LABEL_%%': weave_meta_part_header_id_label, 

1123 '%%_PATCH_%_ID_%%': weave_meta_part_header_id, 

1124 '%%_PATCH_%_ISSUE_%%': weave_meta_part_issue, 

1125 '%%_PATCH_%_REVISION_%%': weave_meta_part_revision, 

1126 '%%_PATCH_%_DATE_%_LABEL_%%': weave_meta_part_header_date_label, 

1127 '%%_PATCH_%_DATE_%%': weave_meta_part_header_date, 

1128 '%%_PATCH_%_FRAME_%_NOTE_%%': weave_meta_part_footer_frame_note, 

1129 '%%_PATCH_%_FOOT_%_PAGE_%_COUNTER_%_LABEL_%%': weave_meta_part_footer_page_number_prefix, 

1130 '%%_PATCH_%_CHANGELOG_%_ISSUE_%_LABEL_%%': weave_meta_part_change_log_issue_label, 

1131 '%%_PATCH_%_CHANGELOG_%_REVISION_%_LABEL_%%': weave_meta_part_change_log_revision_label, 

1132 '%%_PATCH_%_CHANGELOG_%_DATE_%_LABEL_%%': weave_meta_part_change_log_date_label, 

1133 '%%_PATCH_%_CHANGELOG_%_AUTHOR_%_LABEL_%%': weave_meta_part_change_log_author_label, 

1134 '%%_PATCH_%_CHANGELOG_%_DESCRIPTION_%_LABEL_%%': weave_meta_part_change_log_description_label, 

1135 '%%_PATCH_%_APPROVALS_%_ADJUSTABLE_%_VERTICAL_%_SPACE_%%': weave_meta_part_approvals_adjustable_vertical_space, 

1136 '%%_PATCH_%_BLURB_%_ADJUSTABLE_%_VERTICAL_%_SPACE_%%': weave_meta_part_proprietary_information_adjustable_vertical_space, # noqa 

1137 '%%_PATCH_%_BLURB_%_TUNE_%_HEADER_%_SEP_%%': weave_meta_part_proprietary_information_tune_header_sep, 

1138 '%%_PATCH_%_CHANGE_%_LOG_%_TUNE_%_HEADER_%_SEP_%%': weave_meta_part_change_log_tune_header_sep, 

1139 '%%_PATCH_%_APPROVALS_%_DEPARTMENT_%_LABEL_%%': weave_meta_part_approvals_department_label, 

1140 '%%_PATCH_%_APPROVALS_%_DEPARTMENT_%_VALUE_%%': weave_meta_part_approvals_department_value, 

1141 '%%_PATCH_%_APPROVALS_%_ROLE_%_LABEL_%%': weave_meta_part_approvals_role_label, 

1142 '%%_PATCH_%_APPROVALS_%_NAME_%_LABEL_%%': weave_meta_part_approvals_name_label, 

1143 '%%_PATCH_%_APPROVALS_%_DATE_%_AND_%_SIGNATURE_%_LABEL_%%': weave_meta_part_approvals_date_and_signature_label, 

1144 '%%_PATCH_%_ISSUE_%_REVISION_%_COMBINED_%_LABEL_%%': weave_meta_part_header_issue_revision_combined_label, 

1145 '%%_PATCH_%_ISSUE_%_REVISION_%_COMBINED_%%': weave_meta_part_header_issue_revision_combined, 

1146 '%%_PATCH_%_PROPRIETARY_%_INFORMATION_%_LABEL_%%': weave_meta_part_proprietary_information, 

1147 '%%_PATCH_%_STRETCH_%%': weave_meta_part_stretch, 

1148 '%%_PATCH_%_LOX_INDENT_%%': weave_meta_part_lox_indent, 

1149 } 

1150 for trigger, weaver in dispatch.items(): 

1151 if text.rstrip().endswith(trigger): 

1152 return weaver(mapper, text) 

1153 return text 

1154 

1155 

1156@no_type_check 

1157def weave_meta_meta(meta_map: gat.Meta, latex: list[str]) -> list[str]: 

1158 """TODO.""" 

1159 log.info('weaving in the meta data per metadata.tex.in into metadata.tex ...') 

1160 completed = [dispatch_meta_weaver(meta_map['document']['common'], line) for line in latex] 

1161 if completed and completed[-1]: 

1162 completed.append('\n') 

1163 return completed 

1164 

1165 

1166@no_type_check 

1167def weave( 

1168 doc_root: Union[str, pathlib.Path], 

1169 structure_name: str, 

1170 target_key: str, 

1171 facet_key: str, 

1172 options: dict[str, bool], 

1173 externals: ExternalsType, 

1174) -> int: 

1175 """Later alligator.""" 

1176 log.info(LOG_SEPARATOR) 

1177 log.info('entered meta weave function ...') 

1178 target_code = target_key 

1179 facet_code = facet_key 

1180 if not facet_code.strip() or not target_code.strip(): 1180 ↛ 1181line 1180 didn't jump to line 1181 because the condition on line 1180 was never true

1181 log.error(f'meta requires non-empty target ({target_code}) and facet ({facet_code}) codes') 

1182 return 2 

1183 

1184 log.info(f'parsed target ({target_code}) and facet ({facet_code}) from request') 

1185 

1186 structure, asset_map = gat.prelude( 

1187 doc_root=doc_root, structure_name=structure_name, target_key=target_key, facet_key=facet_key, command='meta' 

1188 ) 

1189 log.info(f'prelude teleported processor into the document root at ({os.getcwd()}/)') 

1190 rel_concat_folder_path = pathlib.Path('render/pdf/') 

1191 rel_concat_folder_path.mkdir(parents=True, exist_ok=True) 

1192 os.chdir(rel_concat_folder_path) 

1193 log.info(f'meta (this processor) teleported into the render/pdf location ({os.getcwd()}/)') 

1194 

1195 ok, aspect_map = too.load_target(target_code, facet_code) 

1196 if not ok or not aspect_map: 1196 ↛ 1197line 1196 didn't jump to line 1197 because the condition on line 1196 was never true

1197 return 0 if ok else 1 

1198 

1199 metadata = process_meta(aspect_map) 

1200 if isinstance(metadata, int): 1200 ↛ 1201line 1200 didn't jump to line 1201 because the condition on line 1200 was never true

1201 return 1 

1202 

1203 meta_doc_common = metadata['document']['common'] # noqa 

1204 log.debug(f'in meta.weave {meta_doc_common=}') 

1205 log.debug(f'in meta.weave {externals=}') 

1206 if externals['bookmatter']['is_custom']: 1206 ↛ 1207line 1206 didn't jump to line 1207 because the condition on line 1206 was never true

1207 log.info( 

1208 'per environment variable value request to load external bookmatter layout template' 

1209 f' from {externals["bookmatter"]["id"]} for title page incl. approvals' 

1210 ) 

1211 log.debug(f'in meta.weave bookmatter_path is "{meta_doc_common.get("bookmatter_path", "NOT-PRESENT")}"') 

1212 if 'bookmatter_path' in meta_doc_common: 1212 ↛ 1213line 1212 didn't jump to line 1213 because the condition on line 1212 was never true

1213 bookmatter_path_str = meta_doc_common['bookmatter_path'] 

1214 if bookmatter_path_str and isinstance(bookmatter_path_str, str): 

1215 externals['bookmatter'] = {'id': bookmatter_path_str.strip(), 'is_custom': True} 

1216 log.info( 

1217 f'per configuration variable value request to load external bookmatter layout template' 

1218 f' from {externals["bookmatter"]["id"]} title page incl. approvals' 

1219 ) 

1220 

1221 if externals['driver']['is_custom']: 1221 ↛ 1222line 1221 didn't jump to line 1222 because the condition on line 1221 was never true

1222 log.info( 

1223 'per environment variable value request to load external driver layout template' 

1224 f' from {externals["driver"]["id"]} for general document structure' 

1225 ) 

1226 log.debug(f'in meta.weave driver_path is "{meta_doc_common.get("driver_path", "NOT-PRESENT")}"') 

1227 if 'driver_path' in meta_doc_common: 1227 ↛ 1228line 1227 didn't jump to line 1228 because the condition on line 1227 was never true

1228 driver_path_str = meta_doc_common['driver_path'] 

1229 if driver_path_str and isinstance(driver_path_str, str): 

1230 externals['driver'] = {'id': driver_path_str.strip(), 'is_custom': True} 

1231 log.info( 

1232 f'per configuration variable value request to load external driver layout template' 

1233 f' from {externals["driver"]["id"]} for general document structure' 

1234 ) 

1235 

1236 if externals['metadata']['is_custom']: 1236 ↛ 1237line 1236 didn't jump to line 1237 because the condition on line 1236 was never true

1237 log.info( 

1238 'per environment variable value request to load external metadata template' 

1239 f' from {externals["metadata"]["id"]} for mapping values to required keys' 

1240 ) 

1241 log.debug(f'in meta.weave metadata_path is "{meta_doc_common.get("metadata_path", "NOT-PRESENT")}"') 

1242 if 'metadata_path' in meta_doc_common: 1242 ↛ 1243line 1242 didn't jump to line 1243 because the condition on line 1242 was never true

1243 metadata_path_str = meta_doc_common['metadata_path'] 

1244 if metadata_path_str and isinstance(metadata_path_str, str): 

1245 externals['metadata'] = {'id': metadata_path_str.strip(), 'is_custom': True} 

1246 log.info( 

1247 f'per configuration variable value request to load external metadata template' 

1248 f' from {externals["metadata"]["id"]} for mapping values to required keys' 

1249 ) 

1250 

1251 if externals['publisher']['is_custom']: 1251 ↛ 1252line 1251 didn't jump to line 1252 because the condition on line 1251 was never true

1252 log.info( 

1253 'per environment variable value request to load external publisher layout template' 

1254 f' from {externals["publisher"]["id"]} for changes and notices' 

1255 ) 

1256 log.debug(f'in meta.weave publisher_path is "{meta_doc_common.get("publisher_path", "NOT-PRESENT")}"') 

1257 if 'publisher_path' in meta_doc_common: 1257 ↛ 1258line 1257 didn't jump to line 1258 because the condition on line 1257 was never true

1258 publisher_path_str = meta_doc_common['publisher_path'] 

1259 if publisher_path_str and isinstance(publisher_path_str, str): 

1260 externals['publisher'] = {'id': publisher_path_str.strip(), 'is_custom': True} 

1261 log.info( 

1262 f'per configuration variable value request to load external publisher layout template' 

1263 f' from {externals["publisher"]["id"]} for changes and notices' 

1264 ) 

1265 

1266 if externals['setup']['is_custom']: 1266 ↛ 1267line 1266 didn't jump to line 1267 because the condition on line 1266 was never true

1267 log.info( 

1268 'per environment variable value request to load external setup layout template' 

1269 f' from {externals["setup"]["id"]} for general document setup' 

1270 ) 

1271 log.debug(f'in meta.weave setup_path is "{meta_doc_common.get("setup_path", "NOT-PRESENT")}"') 

1272 if 'setup_path' in meta_doc_common: 1272 ↛ 1273line 1272 didn't jump to line 1273 because the condition on line 1272 was never true

1273 setup_path_str = meta_doc_common['setup_path'] 

1274 if setup_path_str and isinstance(setup_path_str, str): 

1275 externals['setup'] = {'id': setup_path_str.strip(), 'is_custom': True} 

1276 log.info( 

1277 f'per configuration variable value request to load external setup layout template' 

1278 f' from {externals["setup"]["id"]} for general document setup' 

1279 ) 

1280 

1281 if 'approvals_strategy' in meta_doc_common: 

1282 approvals_strategy_str = meta_doc_common['approvals_strategy'] 

1283 if approvals_strategy_str and approvals_strategy_str in KNOWN_APPROVALS_STRATEGIES: 1283 ↛ 1291line 1283 didn't jump to line 1291 because the condition on line 1283 was always true

1284 memo = options.get('approvals_strategy', 'unset') 

1285 options['approvals_strategy'] = approvals_strategy_str 

1286 log.info( 

1287 f'per configuration variable value request for approvals strategy ({approvals_strategy_str})' 

1288 f' was set before to ({memo}) from default or command line' 

1289 ) 

1290 

1291 if 'table_caption_below' in meta_doc_common: 1291 ↛ 1292line 1291 didn't jump to line 1292 because the condition on line 1291 was never true

1292 table_caption_below = bool(meta_doc_common['table_caption_below']) 

1293 if table_caption_below: 

1294 memo = options.get('table_caption_below', False) 

1295 options['table_caption_below'] = table_caption_below 

1296 tc_strategy = 'below' if table_caption_below else 'above' 

1297 log.info( 

1298 f'per configuration variable value request for table captions ({tc_strategy})' 

1299 f' was set before to ({memo}) from default or command line' 

1300 ) 

1301 

1302 if 'table_uglify' in meta_doc_common: 1302 ↛ 1303line 1302 didn't jump to line 1303 because the condition on line 1302 was never true

1303 table_uglify = bool(meta_doc_common['table_uglify']) 

1304 if table_uglify: 

1305 memo = options.get('table_uglify', False) 

1306 options['table_uglify'] = table_uglify 

1307 tc_style = 'ugly' if table_uglify else 'readable' 

1308 log.info( 

1309 f'per configuration variable value request for table style ({tc_style})' 

1310 f' was set before to ({memo}) from default or command line' 

1311 ) 

1312 

1313 metadata_template_is_custom = externals['metadata']['is_custom'] 

1314 metadata_template = str(externals['metadata']['id']) 

1315 metadata_path = pathlib.Path('metadata.tex') 

1316 

1317 metadata_template = tpl.load_resource(metadata_template, metadata_template_is_custom) 

1318 lines = [line.rstrip() for line in metadata_template.split('\n')] 

1319 lines = weave_meta_meta(metadata, lines) 

1320 with open(metadata_path, 'wt', encoding=ENCODING) as handle: 

1321 handle.write('\n'.join(lines)) 

1322 

1323 driver_template_is_custom = externals['driver']['is_custom'] 

1324 driver_template = str(externals['driver']['id']) 

1325 driver_path = pathlib.Path('driver.tex') 

1326 

1327 driver_template = tpl.load_resource(driver_template, driver_template_is_custom) 

1328 lines = [line.rstrip() for line in driver_template.split('\n')] 

1329 lines = weave_meta_driver(metadata, lines) 

1330 with open(driver_path, 'wt', encoding=ENCODING) as handle: 

1331 handle.write('\n'.join(lines)) 

1332 

1333 setup_template_is_custom = externals['setup']['is_custom'] 

1334 setup_template = str(externals['setup']['id']) 

1335 setup_path = pathlib.Path('setup.tex') 

1336 

1337 setup_template = tpl.load_resource(setup_template, setup_template_is_custom) 

1338 lines = [line.rstrip() for line in setup_template.split('\n')] 

1339 lines = weave_meta_setup(metadata, lines) 

1340 with open(setup_path, 'wt', encoding=ENCODING) as handle: 

1341 handle.write('\n'.join(lines)) 

1342 

1343 return 0