Coverage for liitos / meta.py: 76.83%

648 statements  

« prev     ^ index     » next       coverage.py v7.13.2, created at 2026-02-03 22:54:48 +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 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, PathLike, log 

14 

15VALUE_SLOT = 'VALUE.SLOT' 

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

17STRUCTURE_PATH = DOC_BASE / 'structure.yml' 

18MAGIC_OF_TODAY = 'PUBLICATIONDATE' 

19SLASH = '\\' 

20 

21WEAVE_DEFAULTS = { 

22 'approvals_adjustable_vertical_space': '2.5em', 

23 'approvals_strategy': KNOWN_APPROVALS_STRATEGIES[0], 

24 'bold_font': 'ITCFranklinGothicStd-Demi', 

25 'bold_italic_font': 'ITCFranklinGothicStd-DemiIt', 

26 'bookmatter_path': '', 

27 'change_log_tune_header_sep': '-0em', 

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

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

30 'code_fontsize': r'\scriptsize', 

31 'driver_path': '', 

32 'fixed_font_package': 'sourcecodepro', 

33 'font_path': '/opt/fonts/', 

34 'font_suffix': '.otf', 

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

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

37 'italic_font': 'ITCFranklinGothicStd-BookIt', 

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

39 'main_font': 'ITCFranklinGothicStd-Book', 

40 'metadata_path': '', 

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

42 'proprietary_information_adjustable_vertical_space': '-0em', 

43 'proprietary_information_tune_header_sep': '-0em', 

44 'publisher_path': '', 

45 'setup_path': '', 

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

47 'table_captions_below': False, 

48 'table_uglify': False, 

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

50} 

51ACROSS = { 

52 'eff_font_folder': '', 

53 'eff_font_suffix': '', 

54} 

55 

56 

57@no_type_check 

58def load(aspects: dict[str, str], doc_base: PathLike | None = None) -> gat.Meta | int: 

59 """Best effort loading of meta data. 

60 

61 Examples: 

62 

63 >>> aspects = {gat.KEY_META: 'missing-file'} 

64 >>> load(aspects) 

65 1 

66 

67 >>> doc_base = pathlib.Path('test/fixtures/basic/') 

68 >>> meta_name = 'empty-as-meta.yml' 

69 >>> aspects = {gat.KEY_META: meta_name} 

70 >>> load(aspects, doc_base) 

71 1 

72 

73 >>> doc_base = pathlib.Path('.') 

74 >>> aspects = {gat.KEY_META: __file__} 

75 >>> load(aspects, doc_base) 

76 2 

77 

78 >>> doc_base = pathlib.Path('test/fixtures/basic/') 

79 >>> meta_name = 'space-as-meta.yml' 

80 >>> str(doc_base) 

81 'test/fixtures/basic' 

82 >>> doc_base.is_dir() 

83 True 

84 >>> (doc_base / meta_name).is_file() 

85 True 

86 >>> (doc_base / meta_name).stat().st_size 

87 1 

88 >>> aspects = {gat.KEY_META: meta_name} 

89 >>> load(aspects, doc_base) 

90 3 

91 

92 >>> doc_base = pathlib.Path('test/fixtures/basic/') 

93 >>> str(doc_base) 

94 'test/fixtures/basic' 

95 >>> doc_base.is_dir() 

96 True 

97 >>> meta_name = 'meta-importing-empty-other-meta.yml' 

98 >>> aspects = {gat.KEY_META: meta_name} 

99 >>> load(aspects, doc_base) 

100 4 

101 """ 

102 doc_base = doc_base if doc_base is not None else DOC_BASE 

103 meta_path = doc_base / aspects[gat.KEY_META] 

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

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

106 return 1 

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

108 return 2 

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

110 metadata = yaml.safe_load(handle) 

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

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

113 return 3 

114 if 'import' in metadata['document']: 

115 base_meta_path = doc_base / metadata['document']['import'] 

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

117 log.error( 

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

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

120 ) 

121 return 4 

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

123 base_data = yaml.safe_load(handle) 

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

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

126 metadata = base_data 

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

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

129 return metadata 

130 

131 

132@no_type_check 

133def weave_setup_font_path( 

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

135 text: str, 

136) -> str: 

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

138 

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

140 

141 Examples: 

142 

143 >>> mapper = {'font_path': '/fonts/here/'} # expect warning if folder not present 

144 >>> weave_setup_font_path(mapper, 'Path = VALUE.SLOT,%%_PATCH_%_FONT_%_PATH_%%') 

145 'Path = /fonts/here/,%%_PATCH_%_FONT_%_PATH_%%' 

146 >>> ACROSS['eff_font_folder'] 

147 '/fonts/here/' 

148 

149 >>> mapper = {'no_font_path': 'sorry'} 

150 >>> weave_setup_font_path(mapper, 'Path = VALUE.SLOT,%%_PATCH_%_FONT_%_PATH_%%') 

151 'Path = /opt/fonts/,%%_PATCH_%_FONT_%_PATH_%%' 

152 >>> ACROSS['eff_font_folder'] 

153 '/opt/fonts/' 

154 """ 

155 defaults = {**WEAVE_DEFAULTS} 

156 if mapper.get('font_path'): 

157 font_path = mapper.get('font_path') 

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

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

160 ACROSS['eff_font_folder'] = font_path 

161 return text.replace(VALUE_SLOT, font_path) 

162 else: 

163 log.warning(f'font_path value not set ... setting default ({defaults["font_path"]})') 

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

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

166 

167 

168@no_type_check 

169def weave_setup_font_suffix( 

170 mapper: dict[str, str | int | bool | None], 

171 text: str, 

172) -> str: 

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

174 

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

176 

177 Examples: 

178 

179 >>> mapper = {'font_suffix': '.xtf'} # Expect warning because of unknown suffix for fonts 

180 >>> weave_setup_font_suffix(mapper, 'Extension = VALUE.SLOT,%%_PATCH_%_FONT_%_SUFFIX_%%') 

181 'Extension = .xtf,%%_PATCH_%_FONT_%_SUFFIX_%%' 

182 >>> ACROSS['eff_font_suffix'] 

183 '.xtf' 

184 

185 >>> mapper = {'no_font_suffix': 'sorry'} 

186 >>> weave_setup_font_suffix(mapper, 'Extension = VALUE.SLOT,%%_PATCH_%_FONT_%_SUFFIX_%%') 

187 'Extension = .otf,%%_PATCH_%_FONT_%_SUFFIX_%%' 

188 >>> ACROSS['eff_font_suffix'] 

189 '.otf' 

190 """ 

191 defaults = {**WEAVE_DEFAULTS} 

192 if mapper.get('font_suffix'): 

193 font_suffix = mapper.get('font_suffix') 

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

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

196 ACROSS['eff_font_suffix'] = font_suffix 

197 return text.replace(VALUE_SLOT, font_suffix) 

198 else: 

199 log.warning(f'font_suffix value not set ... setting default ({defaults["font_suffix"]})') 

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

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

202 

203 

204@no_type_check 

205def weave_setup_bold_font( 

206 mapper: dict[str, str | int | bool | None], 

207 text: str, 

208) -> str: 

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

210 

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

212 

213 Examples: 

214 

215 >>> mapper = {'bold_font': 'MadeUp'} # Expect warning when file does not exist at font path and suffix 

216 >>> weave_setup_bold_font(mapper, 'BoldFont={VALUE.SLOT},%%_PATCH_%_BOLD_%_FONT_%%') 

217 'BoldFont={MadeUp},%%_PATCH_%_BOLD_%_FONT_%%' 

218 >>> assert ACROSS['eff_font_folder'] in ('', WEAVE_DEFAULTS['font_path']) 

219 >>> assert ACROSS['eff_font_suffix'] in ('', WEAVE_DEFAULTS['font_suffix']) 

220 

221 >>> mapper = {'no_bold_font': 'sorry'} 

222 >>> weave_setup_bold_font(mapper, 'BoldFont={VALUE.SLOT},%%_PATCH_%_BOLD_%_FONT_%%') 

223 'BoldFont={ITCFranklinGothicStd-Demi},%%_PATCH_%_BOLD_%_FONT_%%' 

224 >>> assert ACROSS['eff_font_folder'] in ('', WEAVE_DEFAULTS['font_path']) 

225 >>> assert ACROSS['eff_font_suffix'] in ('', WEAVE_DEFAULTS['font_suffix']) 

226 """ 

227 defaults = {**WEAVE_DEFAULTS} 

228 eff_font_folder = ACROSS['eff_font_folder'] 

229 eff_font_suffix = ACROSS['eff_font_suffix'] 

230 if mapper.get('bold_font'): 

231 bold_font = mapper.get('bold_font') 

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

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

234 log.warning( 

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

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

237 ) 

238 return text.replace(VALUE_SLOT, bold_font) 

239 else: 

240 log.warning(f'bold_font value not set ... setting default ({defaults["bold_font"]})') 

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

242 

243 

244@no_type_check 

245def weave_setup_italic_font( 

246 mapper: dict[str, str | int | bool | None], 

247 text: str, 

248) -> str: 

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

250 

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

252 

253 Examples: 

254 

255 >>> mapper = {'italic_font': 'MadeUpToo'} # Expect warning when file does not exist at font path and suffix 

256 >>> weave_setup_italic_font(mapper, 'ItalicFont={VALUE.SLOT},%%_PATCH_%_ITALIC_%_FONT_%%') 

257 'ItalicFont={MadeUpToo},%%_PATCH_%_ITALIC_%_FONT_%%' 

258 >>> assert ACROSS['eff_font_folder'] in ('', WEAVE_DEFAULTS['font_path']) 

259 >>> assert ACROSS['eff_font_suffix'] in ('', WEAVE_DEFAULTS['font_suffix']) 

260 

261 >>> mapper = {'no_italic_font': 'sorry'} 

262 >>> weave_setup_italic_font(mapper, 'ItalicFont={VALUE.SLOT},%%_PATCH_%_ITALIC_%_FONT_%%') 

263 'ItalicFont={ITCFranklinGothicStd-BookIt},%%_PATCH_%_ITALIC_%_FONT_%%' 

264 >>> assert ACROSS['eff_font_folder'] in ('', WEAVE_DEFAULTS['font_path']) 

265 >>> assert ACROSS['eff_font_suffix'] in ('', WEAVE_DEFAULTS['font_suffix']) 

266 """ 

267 defaults = {**WEAVE_DEFAULTS} 

268 eff_font_folder = ACROSS['eff_font_folder'] 

269 eff_font_suffix = ACROSS['eff_font_suffix'] 

270 if mapper.get('italic_font'): 

271 italic_font = mapper.get('italic_font') 

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

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

274 log.warning( 

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

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

277 ) 

278 return text.replace(VALUE_SLOT, italic_font) 

279 else: 

280 log.warning(f'italic_font value not set ... setting default ({defaults["italic_font"]})') 

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

282 

283 

284@no_type_check 

285def weave_setup_bold_italic_font( 

286 mapper: dict[str, str | int | bool | None], 

287 text: str, 

288) -> str: 

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

290 

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

292 

293 Examples: 

294 

295 >>> mapper = {'bold_italic_font': 'AlsoMadeUp'} # Expect warning when file does not exist at font path and suffix 

296 >>> weave_setup_bold_italic_font(mapper, 'BoldItalicFont={VALUE.SLOT}%%_PATCH_%_BOLDITALIC_%_FONT_%%') 

297 'BoldItalicFont={AlsoMadeUp}%%_PATCH_%_BOLDITALIC_%_FONT_%%' 

298 >>> assert ACROSS['eff_font_folder'] in ('', WEAVE_DEFAULTS['font_path']) 

299 >>> assert ACROSS['eff_font_suffix'] in ('', WEAVE_DEFAULTS['font_suffix']) 

300 

301 >>> mapper = {'no_bold_italic_font': 'sorry'} 

302 >>> weave_setup_bold_italic_font(mapper, 'BoldItalicFont={VALUE.SLOT}%%_PATCH_%_BOLDITALIC_%_FONT_%%') 

303 'BoldItalicFont={ITCFranklinGothicStd-DemiIt}%%_PATCH_%_BOLDITALIC_%_FONT_%%' 

304 >>> assert ACROSS['eff_font_folder'] in ('', WEAVE_DEFAULTS['font_path']) 

305 >>> assert ACROSS['eff_font_suffix'] in ('', WEAVE_DEFAULTS['font_suffix']) 

306 """ 

307 defaults = {**WEAVE_DEFAULTS} 

308 eff_font_folder = ACROSS['eff_font_folder'] 

309 eff_font_suffix = ACROSS['eff_font_suffix'] 

310 if mapper.get('bold_italic_font'): 

311 bold_italic_font = mapper.get('bold_italic_font') 

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

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

314 log.warning( 

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

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

317 ) 

318 return text.replace(VALUE_SLOT, bold_italic_font) 

319 else: 

320 log.warning(f'bold_italic_font value not set ... setting default ({defaults["bold_italic_font"]})') 

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

322 

323 

324@no_type_check 

325def weave_setup_main_font( 

326 mapper: dict[str, str | int | bool | None], 

327 text: str, 

328) -> str: 

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

330 

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

332 

333 Examples: 

334 

335 >>> mapper = {'main_font': 'IsMadeUp'} # Expect warning when file does not exist at font path and suffix 

336 >>> weave_setup_main_font(mapper, ']{VALUE.SLOT}%%_PATCH_%_MAIN_%_FONT_%%') 

337 ']{IsMadeUp}%%_PATCH_%_MAIN_%_FONT_%%' 

338 >>> assert ACROSS['eff_font_folder'] in ('', WEAVE_DEFAULTS['font_path']) 

339 >>> assert ACROSS['eff_font_suffix'] in ('', WEAVE_DEFAULTS['font_suffix']) 

340 

341 >>> mapper = {'no_main_font': 'sorry'} 

342 >>> weave_setup_main_font(mapper, ']{VALUE.SLOT}%%_PATCH_%_MAIN_%_FONT_%%') 

343 ']{ITCFranklinGothicStd-Book}%%_PATCH_%_MAIN_%_FONT_%%' 

344 >>> assert ACROSS['eff_font_folder'] in ('', WEAVE_DEFAULTS['font_path']) 

345 >>> assert ACROSS['eff_font_suffix'] in ('', WEAVE_DEFAULTS['font_suffix']) 

346 """ 

347 defaults = {**WEAVE_DEFAULTS} 

348 eff_font_folder = ACROSS['eff_font_folder'] 

349 eff_font_suffix = ACROSS['eff_font_suffix'] 

350 if mapper.get('main_font'): 

351 main_font = mapper.get('main_font') 

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

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

354 log.warning( 

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

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

357 ) 

358 return text.replace(VALUE_SLOT, main_font) 

359 else: 

360 log.warning(f'main_font value not set ... setting default ({defaults["main_font"]})') 

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

362 

363 

364@no_type_check 

365def weave_setup_fixed_font_package( 

366 mapper: dict[str, str | int | bool | None], 

367 text: str, 

368) -> str: 

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

370 

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

372 

373 Examples: 

374 

375 >>> mapper = {'fixed_font_package': 'MadeUpAgain'} # Expect warning when font differs from default 

376 >>> weave_setup_fixed_font_package(mapper, r'\usepackage{VALUE.SLOT}%%_PATCH_%_FIXED_%_FONT_%_PACKAGE_%%') 

377 '\\usepackage{MadeUpAgain}%%_PATCH_%_FIXED_%_FONT_%_PACKAGE_%%' 

378 

379 >>> mapper = {'no_fixed_font_package': 'sorry'} 

380 >>> weave_setup_fixed_font_package(mapper, r'\usepackage{VALUE.SLOT}%%_PATCH_%_FIXED_%_FONT_%_PACKAGE_%%') 

381 '\\usepackage{sourcecodepro}%%_PATCH_%_FIXED_%_FONT_%_PACKAGE_%%' 

382 """ 

383 defaults = {**WEAVE_DEFAULTS} 

384 if mapper.get('fixed_font_package'): 

385 fixed_font_package = mapper.get('fixed_font_package') 

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

387 log.warning( 

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

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

390 ) 

391 return text.replace(VALUE_SLOT, fixed_font_package) 

392 else: 

393 log.warning(f'fixed_font_package value not set ... setting default ({defaults["fixed_font_package"]})') 

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

395 

396 

397@no_type_check 

398def weave_setup_code_fontsize( 

399 mapper: dict[str, str | int | bool | None], 

400 text: str, 

401) -> str: 

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

403 

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

405 

406 Examples: 

407 

408 >>> mapper = {'code_fontsize': r'\Huge'} 

409 >>> weave_setup_code_fontsize(mapper, 'fontsize=VALUE.SLOT}%%_PATCH_%_CODE_%_FONTSIZE_%%') 

410 'fontsize=\\Huge}%%_PATCH_%_CODE_%_FONTSIZE_%%' 

411 

412 >>> mapper = {'code_fontsize': r'footnotesize'} 

413 >>> weave_setup_code_fontsize(mapper, 'fontsize=VALUE.SLOT}%%_PATCH_%_CODE_%_FONTSIZE_%%') 

414 'fontsize=\\footnotesize}%%_PATCH_%_CODE_%_FONTSIZE_%%' 

415 

416 >>> mapper = {'code_fontsize': r'scriptsize'} 

417 >>> weave_setup_code_fontsize(mapper, 'fontsize=VALUE.SLOT}%%_PATCH_%_CODE_%_FONTSIZE_%%') 

418 'fontsize=\\scriptsize}%%_PATCH_%_CODE_%_FONTSIZE_%%' 

419 

420 >>> mapper = {'code_fontsize': r'tini'} # Expect warnings on override with available sizes 

421 >>> weave_setup_code_fontsize(mapper, 'fontsize=VALUE.SLOT}%%_PATCH_%_CODE_%_FONTSIZE_%%') 

422 'fontsize=\\scriptsize}%%_PATCH_%_CODE_%_FONTSIZE_%%' 

423 

424 >>> mapper = {'code_fontsize': r'\\LARGE'} 

425 >>> weave_setup_code_fontsize(mapper, 'fontsize=VALUE.SLOT}%%_PATCH_%_CODE_%_FONTSIZE_%%') 

426 'fontsize=\\LARGE}%%_PATCH_%_CODE_%_FONTSIZE_%%' 

427 

428 >>> mapper = {'no_code_fontsize': 'sorry'} 

429 >>> weave_setup_code_fontsize(mapper, 'fontsize=VALUE.SLOT}%%_PATCH_%_CODE_%_FONTSIZE_%%') 

430 'fontsize=\\scriptsize}%%_PATCH_%_CODE_%_FONTSIZE_%%' 

431 """ 

432 defaults = {**WEAVE_DEFAULTS} 

433 if mapper.get('code_fontsize'): 

434 code_fontsize = mapper.get('code_fontsize') 

435 valid_code_font_sizes = ( 

436 r'\Huge', 

437 r'\huge', 

438 r'\LARGE', 

439 r'\Large', 

440 r'\large', 

441 r'\normalsize', 

442 r'\small', 

443 r'\footnotesize', 

444 r'\scriptsize', 

445 r'\tiny', 

446 ) 

447 bs = '\\' 

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

449 if code_fontsize.startswith(SLASH + SLASH): 449 ↛ 450line 449 didn't jump to line 450 because the condition on line 449 was never true

450 code_fontsize = code_fontsize[1:] 

451 if not code_fontsize.startswith(SLASH): 451 ↛ 452line 451 didn't jump to line 452 because the condition on line 451 was never true

452 code_fontsize = SLASH + code_fontsize 

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

454 log.error( 

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

456 ' - rendering would not work as intended' 

457 ) 

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

459 log.warning( 

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

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

462 ) 

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

464 else: 

465 return text.replace(VALUE_SLOT, code_fontsize) 

466 else: 

467 log.info( 

468 f'code_fontsize value not set ... setting default ({defaults["code_fontsize"]})' 

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

470 ) 

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

472 

473 

474@no_type_check 

475def weave_setup_chosen_logo( 

476 mapper: dict[str, str | int | bool | None], 

477 text: str, 

478) -> str: 

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

480 

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

482 

483 Examples: 

484 

485 >>> mapper = {'chosen_logo': 'not-found.png'} # Expect warning when logo path is no file 

486 >>> weave_setup_chosen_logo(mapper, r'\newcommand{\theChosenLogo}{VALUE.SLOT}%%_PATCH_%_CHOSEN_%_LOGO_%%') 

487 '\\newcommand{\\theChosenLogo}{not-found.png}%%_PATCH_%_CHOSEN_%_LOGO_%%' 

488 

489 >>> mapper = {'no_chosen_logo': 'sorry'} 

490 >>> weave_setup_chosen_logo(mapper, r'\newcommand{\theChosenLogo}{VALUE.SLOT}%%_PATCH_%_CHOSEN_%_LOGO_%%') 

491 '\\newcommand{\\theChosenLogo}{/opt/logo/liitos-logo.png}%%_PATCH_%_CHOSEN_%_LOGO_%%' 

492 """ 

493 defaults = {**WEAVE_DEFAULTS} 

494 if mapper.get('chosen_logo'): 

495 chosen_logo = mapper.get('chosen_logo') 

496 logo_path = pathlib.Path(chosen_logo) 

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

498 log.warning( 

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

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

501 ) 

502 return text.replace(VALUE_SLOT, chosen_logo) 

503 else: 

504 log.info(f'chosen_logo value not set ... setting default ({defaults["chosen_logo"]})') 

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

506 

507 

508@no_type_check 

509def weave_setup_chosen_title_page_logo( 

510 mapper: dict[str, str | int | bool | None], 

511 text: str, 

512) -> str: 

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

514 

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

516 

517 Examples: 

518 

519 >>> mapper = {'chosen_title_page_logo': 'not-found.png'} # Expect warning when logo path is no file 

520 >>> t = r'\newcommand{\theChosenTitlePageLogo}{VALUE.SLOT}%%_PATCH_%_CHOSEN_%_TITLE_%_PAGE_%_LOGO_%%' 

521 >>> weave_setup_chosen_title_page_logo(mapper, t) 

522 '\\newcommand{\\theChosenTitlePageLogo}{not-found.png}%%_PATCH_%_CHOSEN_%_TITLE_%_PAGE_%_LOGO_%%' 

523 

524 >>> mapper = {'no_chosen_title_page_logo': 'sorry'} 

525 >>> t = r'\newcommand{\theChosenTitlePageLogo}{VALUE.SLOT}%%_PATCH_%_CHOSEN_%_TITLE_%_PAGE_%_LOGO_%%' 

526 >>> weave_setup_chosen_title_page_logo(mapper, t) 

527 '\\newcommand{\\theChosenTitlePageLogo}{/opt/logo/liitos-logo.png}%%_PATCH_%_CHOSEN_%_TITLE_%_PAGE_%_LOGO_%%' 

528 """ 

529 defaults = {**WEAVE_DEFAULTS} 

530 log.warning(text) 

531 if mapper.get('chosen_title_page_logo'): 

532 chosen_title_page_logo = mapper.get('chosen_title_page_logo') 

533 title_page_logo_path = pathlib.Path(chosen_title_page_logo) 

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

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

536 log.warning( 

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

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

539 ) 

540 return text.replace(VALUE_SLOT, chosen_title_page_logo) 

541 else: 

542 log.warning('default logo') 

543 log.info(f'chosen_title_page_logo value not set ... setting default ({defaults["chosen_title_page_logo"]})') 

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

545 

546 

547@no_type_check 

548def weave_setup_footer_outer_field_normal_pages( 

549 mapper: dict[str, str | int | bool | None], 

550 text: str, 

551) -> str: 

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

553 

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

555 

556 Examples: 

557 

558 >>> mapper = {'footer_outer_field_normal_pages': 'n/a'} 

559 >>> t = ' VALUE.SLOT}}%%_PATCH_%_NORMAL_%_PAGES_%_OUTER_%_FOOT_%_CONTENT_%_VALUE_%%' 

560 >>> weave_setup_footer_outer_field_normal_pages(mapper, t) 

561 ' n/a}}%%_PATCH_%_NORMAL_%_PAGES_%_OUTER_%_FOOT_%_CONTENT_%_VALUE_%%' 

562 

563 >>> mapper = {'footer_outer_field_normal_pages': ''} 

564 >>> t = ' VALUE.SLOT}}%%_PATCH_%_NORMAL_%_PAGES_%_OUTER_%_FOOT_%_CONTENT_%_VALUE_%%' 

565 >>> weave_setup_footer_outer_field_normal_pages(mapper, t) 

566 ' }}%%_PATCH_%_NORMAL_%_PAGES_%_OUTER_%_FOOT_%_CONTENT_%_VALUE_%%' 

567 

568 >>> mapper = {'no_footer_outer_field_normal_pages': 'sorry'} 

569 >>> t = ' VALUE.SLOT}}%%_PATCH_%_NORMAL_%_PAGES_%_OUTER_%_FOOT_%_CONTENT_%_VALUE_%%' 

570 >>> weave_setup_footer_outer_field_normal_pages(mapper, t) 

571 ' \\theMetaPageNumPrefix { } \\thepage { }}}%%_PATCH_%_NORMAL_%_PAGES_%_OUTER_%_FOOT_%_CONTENT_%_VALUE_%%' 

572 """ 

573 defaults = {**WEAVE_DEFAULTS} 

574 if mapper.get('footer_outer_field_normal_pages') is not None: 574 ↛ 578line 574 didn't jump to line 578 because the condition on line 574 was always true

575 footer_outer_field_normal_pages = mapper.get('footer_outer_field_normal_pages') 

576 return text.replace(VALUE_SLOT, footer_outer_field_normal_pages) 

577 else: 

578 log.info( 

579 'footer_outer_field_normal_pages value not set ...' 

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

581 ) 

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

583 

584 

585@no_type_check 

586def weave_setup_toc_all_dots( 

587 mapper: dict[str, str | int | bool | None], 

588 text: str, 

589) -> str: 

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

591 

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

593 

594 Examples: 

595 

596 >>> mapper = {'toc_all_dots': '%'} # Comment out the toc dots 

597 >>> weave_setup_toc_all_dots(mapper, 'VALUE.SLOTtoc=sectionentrywithdots,%%_PATCH_%_TOC_ALL_DOTS_%%') 

598 '%toc=sectionentrywithdots,%%_PATCH_%_TOC_ALL_DOTS_%%' 

599 

600 >>> mapper = {'toc_all_dots': ' '} # Enable the toc dots 

601 >>> weave_setup_toc_all_dots(mapper, 'VALUE.SLOTtoc=sectionentrywithdots,%%_PATCH_%_TOC_ALL_DOTS_%%') 

602 ' toc=sectionentrywithdots,%%_PATCH_%_TOC_ALL_DOTS_%%' 

603 

604 >>> mapper = {'toc_all_dots': '%-does-not-matter'} # Comment out the toc dots 

605 >>> weave_setup_toc_all_dots(mapper, 'VALUE.SLOTtoc=sectionentrywithdots,%%_PATCH_%_TOC_ALL_DOTS_%%') 

606 '%-does-not-mattertoc=sectionentrywithdots,%%_PATCH_%_TOC_ALL_DOTS_%%' 

607 

608 >>> mapper = {'toc_all_dots': 'missing-percent'} # Default toc dots and a warning 

609 >>> weave_setup_toc_all_dots(mapper, 'VALUE.SLOTtoc=sectionentrywithdots,%%_PATCH_%_TOC_ALL_DOTS_%%') 

610 'toc=sectionentrywithdots,%%_PATCH_%_TOC_ALL_DOTS_%%' 

611 

612 >>> mapper = {'no_toc_all_dots': 'sorry'} 

613 >>> weave_setup_toc_all_dots(mapper, 'VALUE.SLOTtoc=sectionentrywithdots,%%_PATCH_%_TOC_ALL_DOTS_%%') 

614 'toc=sectionentrywithdots,%%_PATCH_%_TOC_ALL_DOTS_%%' 

615 """ 

616 defaults = {**WEAVE_DEFAULTS} 

617 if mapper.get('toc_all_dots', None) is not None: 617 ↛ 618line 617 didn't jump to line 618 because the condition on line 617 was never true

618 toc_all_dots = mapper.get('toc_all_dots') 

619 if not toc_all_dots.strip() or toc_all_dots.strip().startswith('%'): 

620 dis_ = 'dis' if not toc_all_dots.strip() else '' 

621 log.info(f'toc_all_dots value received ... {dis_}abling toc dots') 

622 return text.replace(VALUE_SLOT, toc_all_dots) 

623 log.warning( 

624 f"toc_all_dots value is neither '' nor starts with % ... setting default ({defaults['toc_all_dots']})" 

625 ) 

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

627 else: 

628 log.info(f'toc_all_dots value not set ... setting default ({defaults["toc_all_dots"]})') 

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

630 

631 

632@no_type_check 

633def dispatch_setup_weaver( 

634 mapper: dict[str, str | int | bool | None], 

635 text: str, 

636) -> str: 

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

638 dispatch = { 

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

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

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

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

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

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

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

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

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

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

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

650 '%%_PATCH_%_TOC_ALL_DOTS_%%': weave_setup_toc_all_dots, 

651 } 

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

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

654 return weaver(mapper, text) 

655 return text 

656 

657 

658@no_type_check 

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

660 """TODO.""" 

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

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

663 if completed and completed[-1]: 

664 completed.append('\n') 

665 return completed 

666 

667 

668@no_type_check 

669def weave_driver_toc_level( 

670 mapper: dict[str, str | int | bool | None], 

671 text: str, 

672) -> str: 

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

674 

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

676 """ 

677 toc_level = 2 

678 if mapper.get('toc_level'): 

679 try: 

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

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

682 if toc_level != toc_level_read: 

683 log.warning( 

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

685 ) 

686 except ValueError as err: 

687 toc_level = 2 

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

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

690 else: 

691 log.info(f'toc_level value not set ... setting default ({toc_level})') 

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

693 

694 

695@no_type_check 

696def weave_driver_list_of_figures( 

697 mapper: dict[str, str | int | bool | None], 

698 text: str, 

699) -> str: 

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

701 

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

703 """ 

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

705 lof = mapper['list_of_figures'] 

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

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

708 else: 

709 lof = '%' 

710 log.warning( 

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

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

713 ) 

714 else: 

715 log.info('list_of_figures value not set ... setting default (comment out the lof per %)') 

716 

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

718 

719 

720@no_type_check 

721def weave_driver_list_of_tables( 

722 mapper: dict[str, str | int | bool | None], 

723 text: str, 

724) -> str: 

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

726 

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

728 """ 

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

730 lof = mapper['list_of_tables'] 

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

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

733 else: 

734 lof = '%' 

735 log.warning( 

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

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

738 ) 

739 else: 

740 log.info('list_of_tables value not set ... setting default (comment out the lot per %)') 

741 

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

743 

744 

745@no_type_check 

746def dispatch_driver_weaver( 

747 mapper: dict[str, str | int | bool | None], 

748 text: str, 

749) -> str: 

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

751 dispatch = { 

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

753 '%%_PATCH_%_LOF_%%': weave_driver_list_of_figures, 

754 '%%_PATCH_%_LOT_%%': weave_driver_list_of_tables, 

755 } 

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

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

758 return weaver(mapper, text) 

759 return text 

760 

761 

762@no_type_check 

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

764 """TODO.""" 

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

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

767 if completed and completed[-1]: 

768 completed.append('\n') 

769 return completed 

770 

771 

772@no_type_check 

773def weave_meta_part_header_title( 

774 mapper: dict[str, str | int | bool | None], 

775 text: str, 

776) -> str: 

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

778 

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

780 """ 

781 if mapper.get('header_title'): 

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

783 else: 

784 log.info('header_title value not set ... setting default (the title value)') 

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

786 

787 

788@no_type_check 

789def weave_meta_part_title_slug( 

790 mapper: dict[str, str | int | bool | None], 

791 text: str, 

792) -> str: 

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

794 

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

796 

797 Examples: 

798 

799 >>> mapper = {'bookmark_title': 'I aM A BMT'} 

800 >>> t = r'\newcommand{\theTitleSlug}{VALUE.SLOT}%%_PATCH_%_TITLE_%_SLUG_%%' 

801 >>> weave_meta_part_title_slug(mapper, t) 

802 '\\newcommand{\\theTitleSlug}{I aM A BMT}%%_PATCH_%_TITLE_%_SLUG_%%' 

803 """ 

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

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

806 else: 

807 log.info('bookmark_title value not set ... setting default (the slugged title value)') 

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

809 

810 

811@no_type_check 

812def weave_meta_part_title( 

813 mapper: dict[str, str | int | bool | None], 

814 text: str, 

815) -> str: 

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

817 

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

819 """ 

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

821 

822 

823@no_type_check 

824def weave_meta_part_sub_title( 

825 mapper: dict[str, str | int | bool | None], 

826 text: str, 

827) -> str: 

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

829 

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

831 """ 

832 if mapper.get('sub_title'): 

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

834 else: 

835 log.info('sub_title value not set ... setting default (single space)') 

836 return text.replace(VALUE_SLOT, ' ') 

837 

838 

839@no_type_check 

840def weave_meta_part_header_type( 

841 mapper: dict[str, str | int | bool | None], 

842 text: str, 

843) -> str: 

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

845 

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

847 """ 

848 if mapper.get('header_type'): 

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

850 else: 

851 log.info('header_type value not set ... setting default (Engineering Document)') 

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

853 

854 

855@no_type_check 

856def weave_meta_part_header_id_label( 

857 mapper: dict[str, str | int | bool | None], 

858 text: str, 

859) -> str: 

860 r"""Weave in the header_id_label from mapper or default. 

861 

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

863 

864 Examples: 

865 

866 >>> mapper = {'header_id_show': False} 

867 >>> t = r'\newcommand{\theMetaDocIdLabel}{VALUE.SLOT}%%_PATCH_%_ID_%_LABEL_%%' 

868 >>> weave_meta_part_header_id_label(mapper, t) 

869 '\\newcommand{\\theMetaDocIdLabel}{ }%%_PATCH_%_ID_%_LABEL_%%' 

870 

871 >>> mapper = {'header_id_show': ''} 

872 >>> t = r'\newcommand{\theMetaDocIdLabel}{VALUE.SLOT}%%_PATCH_%_ID_%_LABEL_%%' 

873 >>> weave_meta_part_header_id_label(mapper, t) 

874 '\\newcommand{\\theMetaDocIdLabel}{ }%%_PATCH_%_ID_%_LABEL_%%' 

875 

876 >>> mapper = {'header_id_show': None, 'header_id_label': ' '} 

877 >>> t = r'\newcommand{\theMetaDocIdLabel}{VALUE.SLOT}%%_PATCH_%_ID_%_LABEL_%%' 

878 >>> weave_meta_part_header_id_label(mapper, t) 

879 '\\newcommand{\\theMetaDocIdLabel}{ }%%_PATCH_%_ID_%_LABEL_%%' 

880 

881 >>> mapper = {'header_id_show': None, 'header_id_label': ' show-this-stripped '} 

882 >>> t = r'\newcommand{\theMetaDocIdLabel}{VALUE.SLOT}%%_PATCH_%_ID_%_LABEL_%%' 

883 >>> weave_meta_part_header_id_label(mapper, t) 

884 '\\newcommand{\\theMetaDocIdLabel}{show-this-stripped}%%_PATCH_%_ID_%_LABEL_%%' 

885 

886 >>> mapper = {'no_header_id_show': 'sorry'} 

887 >>> t = r'\newcommand{\theMetaDocIdLabel}{VALUE.SLOT}%%_PATCH_%_ID_%_LABEL_%%' 

888 >>> weave_meta_part_header_id_label(mapper, t) 

889 '\\newcommand{\\theMetaDocIdLabel}{Doc. ID:}%%_PATCH_%_ID_%_LABEL_%%' 

890 """ 

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

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

893 return text.replace(VALUE_SLOT, ' ') 

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

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

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

897 if not pub_id_label: 

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

899 return text.replace(VALUE_SLOT, pub_id_label) 

900 else: 

901 log.info('header_id_label value not set ... setting default(Doc. ID:)') 

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

903 

904 

905@no_type_check 

906def weave_meta_part_header_id( 

907 mapper: dict[str, str | int | bool | None], 

908 text: str, 

909) -> str: 

910 r"""Weave in the header_id from mapper or default. 

911 

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

913 

914 Examples: 

915 

916 >>> mapper = {'header_id_show': False} 

917 >>> t = r'\newcommand{\theMetaDocId}{VALUE.SLOT}%%_PATCH_%_ID_%%' 

918 >>> weave_meta_part_header_id(mapper, t) 

919 '\\newcommand{\\theMetaDocId}{ }%%_PATCH_%_ID_%%' 

920 

921 >>> mapper = {'header_id_show': ''} 

922 >>> t = r'\newcommand{\theMetaDocId}{VALUE.SLOT}%%_PATCH_%_ID_%%' 

923 >>> weave_meta_part_header_id(mapper, t) 

924 '\\newcommand{\\theMetaDocId}{ }%%_PATCH_%_ID_%%' 

925 

926 >>> mapper = {'header_id_show': None, 'header_id': ' '} 

927 >>> t = r'\newcommand{\theMetaDocId}{VALUE.SLOT}%%_PATCH_%_ID_%%' 

928 >>> weave_meta_part_header_id(mapper, t) 

929 '\\newcommand{\\theMetaDocId}{ }%%_PATCH_%_ID_%%' 

930 

931 >>> mapper = {'header_id_show': None, 'header_id': ' show-this-unstripped '} 

932 >>> t = r'\newcommand{\theMetaDocId}{VALUE.SLOT}%%_PATCH_%_ID_%%' 

933 >>> weave_meta_part_header_id(mapper, t) 

934 '\\newcommand{\\theMetaDocId}{ show-this-unstripped }%%_PATCH_%_ID_%%' 

935 

936 >>> mapper = {'no_header_id_show': 'sorry'} 

937 >>> t = r'\newcommand{\theMetaDocId}{VALUE.SLOT}%%_PATCH_%_ID_%%' 

938 >>> weave_meta_part_header_id(mapper, t) 

939 '\\newcommand{\\theMetaDocId}{N/A}%%_PATCH_%_ID_%%' 

940 """ 

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

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

943 return text.replace(VALUE_SLOT, ' ') 

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

945 if mapper.get('header_id'): 

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

947 else: 

948 log.info('header_id value not set ... setting default (N/A)') 

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

950 

951 

952@no_type_check 

953def weave_meta_part_issue( 

954 mapper: dict[str, str | int | bool | None], 

955 text: str, 

956) -> str: 

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

958 

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

960 """ 

961 if mapper.get('issue'): 

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

963 else: 

964 log.info('issue value not set ... setting default (01)') 

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

966 

967 

968@no_type_check 

969def weave_meta_part_revision( 

970 mapper: dict[str, str | int | bool | None], 

971 text: str, 

972) -> str: 

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

974 

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

976 """ 

977 if mapper.get('revision'): 

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

979 else: 

980 log.info('revision value not set ... setting default (00)') 

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

982 

983 

984@no_type_check 

985def weave_meta_part_header_date_label( 

986 mapper: dict[str, str | int | bool | None], 

987 text: str, 

988) -> str: 

989 r"""Weave in the header_date_label from mapper or default. 

990 

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

992 

993 Examples: 

994 

995 >>> mapper = {'header_date_show': False} 

996 >>> t = r'\newcommand{\theMetaDateLabel}{VALUE.SLOT}%%_PATCH_%_DATE_%_LABEL_%%' 

997 >>> weave_meta_part_header_date_label(mapper, t) 

998 '\\newcommand{\\theMetaDateLabel}{ }%%_PATCH_%_DATE_%_LABEL_%%' 

999 

1000 >>> mapper = {'header_date_show': ''} 

1001 >>> t = r'\newcommand{\theMetaDateLabel}{VALUE.SLOT}%%_PATCH_%_DATE_%_LABEL_%%' 

1002 >>> weave_meta_part_header_date_label(mapper, t) 

1003 '\\newcommand{\\theMetaDateLabel}{ }%%_PATCH_%_DATE_%_LABEL_%%' 

1004 

1005 >>> mapper = {'header_date_show': None, 'header_date_label': ' '} 

1006 >>> t = r'\newcommand{\theMetaDateLabel}{VALUE.SLOT}%%_PATCH_%_DATE_%_LABEL_%%' 

1007 >>> weave_meta_part_header_date_label(mapper, t) 

1008 '\\newcommand{\\theMetaDateLabel}{ }%%_PATCH_%_DATE_%_LABEL_%%' 

1009 

1010 >>> mapper = {'header_date_show': None, 'header_date_label': ' show-this-stripped '} 

1011 >>> t = r'\newcommand{\theMetaDateLabel}{VALUE.SLOT}%%_PATCH_%_DATE_%_LABEL_%%' 

1012 >>> weave_meta_part_header_date_label(mapper, t) 

1013 '\\newcommand{\\theMetaDateLabel}{show-this-stripped}%%_PATCH_%_DATE_%_LABEL_%%' 

1014 

1015 >>> mapper = {'no_header_date_show': 'sorry'} 

1016 >>> t = r'\newcommand{\theMetaDateLabel}{VALUE.SLOT}%%_PATCH_%_DATE_%_LABEL_%%' 

1017 >>> weave_meta_part_header_date_label(mapper, t) 

1018 '\\newcommand{\\theMetaDateLabel}{ }%%_PATCH_%_DATE_%_LABEL_%%' 

1019 """ 

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

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

1022 return text.replace(VALUE_SLOT, ' ') 

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

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

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

1026 if not pub_date_label: 

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

1028 return text.replace(VALUE_SLOT, pub_date_label) 

1029 else: 

1030 log.info('header_date_label value not set ... setting default(" ")') 

1031 return text.replace(VALUE_SLOT, ' ') 

1032 

1033 

1034@no_type_check 

1035def weave_meta_part_header_date( 

1036 mapper: dict[str, str | int | bool | None], 

1037 text: str, 

1038) -> str: 

1039 r"""Weave in the header_date from mapper or default. 

1040 

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

1042 

1043 Examples: 

1044 

1045 >>> mapper = {'header_date_show': False} 

1046 >>> t = r'\newcommand{\theMetaDate}{VALUE.SLOT}%%_PATCH_%_DATE_%%' 

1047 >>> weave_meta_part_header_date(mapper, t) 

1048 '\\newcommand{\\theMetaDate}{ }%%_PATCH_%_DATE_%%' 

1049 

1050 >>> mapper = {'header_date_show': ''} 

1051 >>> t = r'\newcommand{\theMetaDate}{VALUE.SLOT}%%_PATCH_%_DATE_%%' 

1052 >>> weave_meta_part_header_date(mapper, t) 

1053 '\\newcommand{\\theMetaDate}{ }%%_PATCH_%_DATE_%%' 

1054 

1055 >>> mapper = {'header_date_show': None, 'header_date': ' '} 

1056 >>> t = r'\newcommand{\theMetaDate}{VALUE.SLOT}%%_PATCH_%_DATE_%%' 

1057 >>> weave_meta_part_header_date(mapper, t) 

1058 '\\newcommand{\\theMetaDate}{}%%_PATCH_%_DATE_%%' 

1059 

1060 >>> mapper = {'header_date_show': None, 'header_date': ' show-this-stripped '} 

1061 >>> t = r'\newcommand{\theMetaDate}{VALUE.SLOT}%%_PATCH_%_DATE_%%' 

1062 >>> weave_meta_part_header_date(mapper, t) 

1063 '\\newcommand{\\theMetaDate}{show-this-stripped}%%_PATCH_%_DATE_%%' 

1064 

1065 >>> mapper = {'no_header_date_show': 'sorry'} 

1066 >>> t = r'\newcommand{\theMetaDate}{VALUE.SLOT}%%_PATCH_%_DATE_%%' 

1067 >>> weave_meta_part_header_date(mapper, t) 

1068 '\\newcommand{\\theMetaDate}{ }%%_PATCH_%_DATE_%%' 

1069 

1070 >>> mapper = { 

1071 ... 'no_header_date_show': 'sorry', 

1072 ... 'header_date_enable_auto': True, 

1073 ... 'header_date': ' ', 

1074 ... } 

1075 >>> t = r'\newcommand{\theMetaDate}{VALUE.SLOT}%%_PATCH_%_DATE_%%' 

1076 >>> weave_meta_part_header_date(mapper, t) 

1077 '\\newcommand{\\theMetaDate}{}%%_PATCH_%_DATE_%%' 

1078 

1079 >>> mapper = { 

1080 ... 'no_header_date_show': 'sorry', 

1081 ... 'header_date_enable_auto': True, 

1082 ... 'header_date': '', 

1083 ... } 

1084 >>> t = r'\newcommand{\theMetaDate}{VALUE.SLOT}%%_PATCH_%_DATE_%%' 

1085 >>> weave_meta_part_header_date(mapper, t) 

1086 '\\newcommand{\\theMetaDate}{ }%%_PATCH_%_DATE_%%' 

1087 

1088 >>> mapper = { 

1089 ... 'no_header_date_show': 'sorry', 

1090 ... 'header_date_enable_auto': True, 

1091 ... 'header_date': ' free-form-stripped ', 

1092 ... } 

1093 >>> t = r'\newcommand{\theMetaDate}{VALUE.SLOT}%%_PATCH_%_DATE_%%' 

1094 >>> weave_meta_part_header_date(mapper, t) 

1095 '\\newcommand{\\theMetaDate}{free-form-stripped}%%_PATCH_%_DATE_%%' 

1096 

1097 >>> mapper = { 

1098 ... 'no_header_date_show': 'sorry', 

1099 ... 'header_date_enable_auto': False, 

1100 ... 'header_date': ' free-form-stripped ', 

1101 ... } 

1102 >>> t = r'\newcommand{\theMetaDate}{VALUE.SLOT}%%_PATCH_%_DATE_%%' 

1103 >>> weave_meta_part_header_date(mapper, t) 

1104 '\\newcommand{\\theMetaDate}{free-form-stripped}%%_PATCH_%_DATE_%%' 

1105 

1106 >>> mapper = { 

1107 ... 'no_header_date_show': 'sorry', 

1108 ... 'header_date_enable_auto': False, 

1109 ... 'header_date': '', 

1110 ... } 

1111 >>> t = r'\newcommand{\theMetaDate}{VALUE.SLOT}%%_PATCH_%_DATE_%%' 

1112 >>> weave_meta_part_header_date(mapper, t) 

1113 '\\newcommand{\\theMetaDate}{ }%%_PATCH_%_DATE_%%' 

1114 

1115 >>> mapper = { 

1116 ... 'no_header_date_show': 'sorry', 

1117 ... 'header_date_enable_auto': False, 

1118 ... 'header_date': ' ', 

1119 ... } 

1120 >>> t = r'\newcommand{\theMetaDate}{VALUE.SLOT}%%_PATCH_%_DATE_%%' 

1121 >>> weave_meta_part_header_date(mapper, t) 

1122 '\\newcommand{\\theMetaDate}{ }%%_PATCH_%_DATE_%%' 

1123 """ 

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

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

1126 return text.replace(VALUE_SLOT, ' ') 

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

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

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

1130 if mapper.get('header_date'): 

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

1132 if not pub_date_or_any: 

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

1134 return text.replace(VALUE_SLOT, pub_date_or_any) 

1135 else: 

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

1137 return text.replace(VALUE_SLOT, ' ') 

1138 else: 

1139 today = dti.datetime.today() 

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

1141 if mapper.get('header_date'): 

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

1143 if pub_date == MAGIC_OF_TODAY: 

1144 pub_date = pub_date_today 

1145 return text.replace(VALUE_SLOT, pub_date) 

1146 else: 

1147 log.info('header_date value not set ... setting default as empty(" ")') 

1148 return text.replace(VALUE_SLOT, ' ') 

1149 

1150 

1151@no_type_check 

1152def weave_meta_part_footer_frame_note( 

1153 mapper: dict[str, str | int | bool | None], 

1154 text: str, 

1155) -> str: 

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

1157 

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

1159 """ 

1160 if mapper.get('footer_frame_note'): 

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

1162 else: 

1163 log.info('footer_frame_note value not set ... setting default from module / environment ...') 

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

1165 

1166 

1167@no_type_check 

1168def weave_meta_part_footer_page_number_prefix( 

1169 mapper: dict[str, str | int | bool | None], 

1170 text: str, 

1171) -> str: 

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

1173 

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

1175 """ 

1176 if mapper.get('footer_page_number_prefix'): 

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

1178 else: 

1179 log.info('footer_page_number_prefix value not set ... setting default (Page)') 

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

1181 

1182 

1183@no_type_check 

1184def weave_meta_part_change_log_issue_label( 

1185 mapper: dict[str, str | int | bool | None], 

1186 text: str, 

1187) -> str: 

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

1189 

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

1191 """ 

1192 if mapper.get('change_log_issue_label'): 

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

1194 else: 

1195 log.info('change_log_issue_label value not set ... setting default (Iss.)') 

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

1197 

1198 

1199@no_type_check 

1200def weave_meta_part_change_log_revision_label( 

1201 mapper: dict[str, str | int | bool | None], 

1202 text: str, 

1203) -> str: 

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

1205 

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

1207 """ 

1208 if mapper.get('change_log_revision_label'): 

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

1210 else: 

1211 log.info('change_log_revision_label value not set ... setting default (Rev.)') 

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

1213 

1214 

1215@no_type_check 

1216def weave_meta_part_change_log_date_label( 

1217 mapper: dict[str, str | int | bool | None], 

1218 text: str, 

1219) -> str: 

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

1221 

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

1223 """ 

1224 if mapper.get('change_log_date_label'): 

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

1226 else: 

1227 log.info('change_log_date_label value not set ... setting default (Date)') 

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

1229 

1230 

1231@no_type_check 

1232def weave_meta_part_change_log_author_label( 

1233 mapper: dict[str, str | int | bool | None], 

1234 text: str, 

1235) -> str: 

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

1237 

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

1239 """ 

1240 if mapper.get('change_log_author_label'): 

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

1242 else: 

1243 log.info('change_log_author_label value not set ... setting default (Author)') 

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

1245 

1246 

1247@no_type_check 

1248def weave_meta_part_change_log_description_label( 

1249 mapper: dict[str, str | int | bool | None], 

1250 text: str, 

1251) -> str: 

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

1253 

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

1255 """ 

1256 if mapper.get('change_log_description_label'): 

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

1258 else: 

1259 log.info('change_log_description_label value not set ... setting default (Description)') 

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

1261 

1262 

1263@no_type_check 

1264def weave_meta_part_with_default_slot( 

1265 mapper: dict[str, str | int | bool | None], 

1266 text: str, 

1267 slot: str, 

1268) -> str: 

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

1270 if mapper.get(slot): 

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

1272 else: 

1273 log.info(f'{slot} value not set ... setting default ({WEAVE_DEFAULTS[slot]})') 

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

1275 

1276 

1277@no_type_check 

1278def weave_meta_part_approvals_adjustable_vertical_space( 

1279 mapper: dict[str, str | int | bool | None], 

1280 text: str, 

1281) -> str: 

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

1283 

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

1285 """ 

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

1287 

1288 

1289@no_type_check 

1290def weave_meta_part_proprietary_information_adjustable_vertical_space( 

1291 mapper: dict[str, str | int | bool | None], 

1292 text: str, 

1293) -> str: 

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

1295 

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

1297 """ 

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

1299 

1300 

1301@no_type_check 

1302def weave_meta_part_proprietary_information_tune_header_sep( 

1303 mapper: dict[str, str | int | bool | None], 

1304 text: str, 

1305) -> str: 

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

1307 

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

1309 """ 

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

1311 

1312 

1313@no_type_check 

1314def weave_meta_part_change_log_tune_header_sep( 

1315 mapper: dict[str, str | int | bool | None], 

1316 text: str, 

1317) -> str: 

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

1319 

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

1321 """ 

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

1323 

1324 

1325@no_type_check 

1326def weave_meta_part_approvals_department_label( 

1327 mapper: dict[str, str | int | bool | None], 

1328 text: str, 

1329) -> str: 

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

1331 

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

1333 """ 

1334 if mapper.get('approvals_department_label'): 

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

1336 else: 

1337 log.info('approvals_department_label value not set ... setting default (Department)') 

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

1339 

1340 

1341@no_type_check 

1342def weave_meta_part_approvals_department_value( 

1343 mapper: dict[str, str | int | bool | None], 

1344 text: str, 

1345) -> str: 

1346 r"""Weave in the approvals_department_value from mapper or default. 

1347 

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

1349 

1350 Examples: 

1351 

1352 >>> mapper = {'approvals_department_value': 'AbC'} 

1353 >>> t = r'\newcommand{\theApprovalsDepartmentValue}{VALUE.SLOT}%%_PATCH_%_APPROVALS_%_DEPARTMENT_%_VALUE_%%' 

1354 >>> weave_meta_part_approvals_department_value(mapper, t) 

1355 '\\newcommand{\\theApprovalsDepartmentValue}{AbC}%%_PATCH_%_APPROVALS_%_DEPARTMENT_%_VALUE_%%' 

1356 

1357 >>> mapper = {'approvals_department_value': ' '} 

1358 >>> t = r'\newcommand{\theApprovalsDepartmentValue}{VALUE.SLOT}%%_PATCH_%_APPROVALS_%_DEPARTMENT_%_VALUE_%%' 

1359 >>> weave_meta_part_approvals_department_value(mapper, t) 

1360 '\\newcommand{\\theApprovalsDepartmentValue}{ }%%_PATCH_%_APPROVALS_%_DEPARTMENT_%_VALUE_%%' 

1361 

1362 >>> mapper = {'approvals_department_value': ''} 

1363 >>> t = r'\newcommand{\theApprovalsDepartmentValue}{VALUE.SLOT}%%_PATCH_%_APPROVALS_%_DEPARTMENT_%_VALUE_%%' 

1364 >>> weave_meta_part_approvals_department_value(mapper, t) 

1365 '\\newcommand{\\theApprovalsDepartmentValue}{ }%%_PATCH_%_APPROVALS_%_DEPARTMENT_%_VALUE_%%' 

1366 

1367 >>> mapper = {'no_approvals_department_value': 'sorry'} 

1368 >>> t = r'\newcommand{\theApprovalsDepartmentValue}{VALUE.SLOT}%%_PATCH_%_APPROVALS_%_DEPARTMENT_%_VALUE_%%' 

1369 >>> weave_meta_part_approvals_department_value(mapper, t) 

1370 '\\newcommand{\\theApprovalsDepartmentValue}{ }%%_PATCH_%_APPROVALS_%_DEPARTMENT_%_VALUE_%%' 

1371 """ 

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

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

1374 else: 

1375 log.info('approvals_department_value value not set ... setting default ( )') 

1376 return text.replace(VALUE_SLOT, ' ') 

1377 

1378 

1379@no_type_check 

1380def weave_meta_part_approvals_role_label( 

1381 mapper: dict[str, str | int | bool | None], 

1382 text: str, 

1383) -> str: 

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

1385 

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

1387 """ 

1388 if mapper.get('approvals_role_label'): 

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

1390 else: 

1391 log.info('approvals_role_label value not set ... setting default (Approvals)') 

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

1393 

1394 

1395@no_type_check 

1396def weave_meta_part_approvals_name_label( 

1397 mapper: dict[str, str | int | bool | None], 

1398 text: str, 

1399) -> str: 

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

1401 

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

1403 """ 

1404 if mapper.get('approvals_name_label'): 

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

1406 else: 

1407 log.info('approvals_name_label value not set ... setting default (Name)') 

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

1409 

1410 

1411@no_type_check 

1412def weave_meta_part_approvals_date_and_signature_label( 

1413 mapper: dict[str, str | int | bool | None], 

1414 text: str, 

1415) -> str: 

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

1417 

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

1419 """ 

1420 if mapper.get('approvals_date_and_signature_label'): 

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

1422 else: 

1423 log.info('approvals_date_and_signature_label value not set ... setting default (Date and Signature)') 

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

1425 

1426 

1427@no_type_check 

1428def weave_meta_part_header_issue_revision_combined_label( 

1429 mapper: dict[str, str | int | bool | None], 

1430 text: str, 

1431) -> str: 

1432 r"""Weave in the header_issue_revision_combined_label from mapper or default. 

1433 

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

1435 

1436 Examples: 

1437 

1438 >>> mapper = {'header_issue_revision_combined_show': ''} 

1439 >>> t = r'\newcommand{\theMetaIssRevLabel}{VALUE.SLOT}%%_PATCH_%_ISSUE_%_REVISION_%_COMBINED_%_LABEL_%%' 

1440 >>> weave_meta_part_header_issue_revision_combined_label(mapper, t) 

1441 '\\newcommand{\\theMetaIssRevLabel}{ }%%_PATCH_%_ISSUE_%_REVISION_%_COMBINED_%_LABEL_%%' 

1442 

1443 >>> mapper = { 

1444 ... 'header_issue_revision_combined_show': ' ', 

1445 ... 'header_issue_revision_combined_label': ' ', 

1446 ... } 

1447 >>> t = r'\newcommand{\theMetaIssRevLabel}{VALUE.SLOT}%%_PATCH_%_ISSUE_%_REVISION_%_COMBINED_%_LABEL_%%' 

1448 >>> weave_meta_part_header_issue_revision_combined_label(mapper, t) 

1449 '\\newcommand{\\theMetaIssRevLabel}{ }%%_PATCH_%_ISSUE_%_REVISION_%_COMBINED_%_LABEL_%%' 

1450 

1451 >>> mapper = { 

1452 ... 'header_issue_revision_combined_show': 'well-well-well', 

1453 ... 'header_issue_revision_combined_label': 'visible-fixed-string', 

1454 ... } 

1455 >>> t = r'\newcommand{\theMetaIssRevLabel}{VALUE.SLOT}%%_PATCH_%_ISSUE_%_REVISION_%_COMBINED_%_LABEL_%%' 

1456 >>> weave_meta_part_header_issue_revision_combined_label(mapper, t) 

1457 '\\newcommand{\\theMetaIssRevLabel}{visible-fixed-string}%%_PATCH_%_ISSUE_%_REVISION_%_COMBINED_%_LABEL_%%' 

1458 

1459 >>> mapper = {'no_header_issue_revision_combined_show': 'sorry'} 

1460 >>> t = r'\newcommand{\theMetaIssRevLabel}{VALUE.SLOT}%%_PATCH_%_ISSUE_%_REVISION_%_COMBINED_%_LABEL_%%' 

1461 >>> weave_meta_part_header_issue_revision_combined_label(mapper, t) 

1462 '\\newcommand{\\theMetaIssRevLabel}{Issue, Revision:}%%_PATCH_%_ISSUE_%_REVISION_%_COMBINED_%_LABEL_%%' 

1463 """ 

1464 do_show_key = 'header_issue_revision_combined_show' 

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

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

1467 return text.replace(VALUE_SLOT, ' ') 

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

1469 if mapper.get('header_issue_revision_combined_label'): 

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

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

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

1473 return text.replace(VALUE_SLOT, head_iss_rev_comb_label) 

1474 else: 

1475 log.info('header_issue_revision_combined_label value not set ... setting default(Issue, Revision:)') 

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

1477 

1478 

1479@no_type_check 

1480def weave_meta_part_header_issue_revision_combined( 

1481 mapper: dict[str, str | int | bool | None], 

1482 text: str, 

1483) -> str: 

1484 r"""Weave in the header_issue_revision_combined from mapper or default. 

1485 

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

1487 

1488 Examples: 

1489 

1490 >>> mapper = {'header_issue_revision_combined_show': ''} 

1491 >>> t = r'\newcommand{\theMetaIssRev}{VALUE.SLOT}%%_PATCH_%_ISSUE_%_REVISION_%_COMBINED_%%' 

1492 >>> weave_meta_part_header_issue_revision_combined(mapper, t) 

1493 '\\newcommand{\\theMetaIssRev}{ }%%_PATCH_%_ISSUE_%_REVISION_%_COMBINED_%%' 

1494 

1495 >>> mapper = { 

1496 ... 'header_issue_revision_combined_show': ' ', 

1497 ... 'header_issue_revision_combined': ' ', 

1498 ... } 

1499 >>> t = r'\newcommand{\theMetaIssRev}{VALUE.SLOT}%%_PATCH_%_ISSUE_%_REVISION_%_COMBINED_%%' 

1500 >>> weave_meta_part_header_issue_revision_combined(mapper, t) 

1501 '\\newcommand{\\theMetaIssRev}{ }%%_PATCH_%_ISSUE_%_REVISION_%_COMBINED_%%' 

1502 

1503 >>> mapper = { 

1504 ... 'header_issue_revision_combined_show': 'well-well-well', 

1505 ... 'header_issue_revision_combined': 'visible-fixed-string', 

1506 ... } 

1507 >>> t = r'\newcommand{\theMetaIssRev}{VALUE.SLOT}%%_PATCH_%_ISSUE_%_REVISION_%_COMBINED_%%' 

1508 >>> weave_meta_part_header_issue_revision_combined(mapper, t) 

1509 '\\newcommand{\\theMetaIssRev}{visible-fixed-string}%%_PATCH_%_ISSUE_%_REVISION_%_COMBINED_%%' 

1510 

1511 >>> mapper = {'no_header_issue_revision_combined_show': 'sorry'} 

1512 >>> t = r'\newcommand{\theMetaIssRev}{VALUE.SLOT}%%_PATCH_%_ISSUE_%_REVISION_%_COMBINED_%%' 

1513 >>> weave_meta_part_header_issue_revision_combined(mapper, t) 

1514 '\\newcommand{\\theMetaIssRev}{Iss \\theMetaIssCode, Rev \\theMetaRevCode}%%_PATCH_%_..._%_COMBINED_%%' 

1515 """ 

1516 do_show_key = 'header_issue_revision_combined_show' 

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

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

1519 return text.replace(VALUE_SLOT, ' ') 

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

1521 if mapper.get('header_issue_revision_combined'): 

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

1523 else: 

1524 log.info( 

1525 'header_issue_revision_combined value not set ... setting' 

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

1527 ) 

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

1529 

1530 

1531@no_type_check 

1532def weave_meta_part_proprietary_information( 

1533 mapper: dict[str, str | int | bool | None], 

1534 text: str, 

1535) -> str: 

1536 r"""Weave in the proprietary_information from mapper or default. 

1537 

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

1539 

1540 Examples: 

1541 

1542 >>> mapper = {'proprietary_information': ''} 

1543 >>> t = r'\newcommand{\theProprietaryInformation}{VALUE.SLOT}%%_PATCH_%_PROPRIETARY_%_INFORMATION_%_LABEL_%%' 

1544 >>> weave_meta_part_proprietary_information(mapper, t) 

1545 '\\newcommand{\\theProprietaryInformation}{This is a notice.\n}%%_PATCH_%_PROPRIETARY_%_INFORMATION_%_LABEL_%%' 

1546 

1547 >>> mapper = {'proprietary_information': __file__} 

1548 >>> t = r'\newcommand{\theProprietaryInformation}{VALUE.SLOT}%%_PATCH_%_PROPRIETARY_%_INFORMATION_%_LABEL_%%' 

1549 >>> weave_meta_part_proprietary_information(mapper, t) 

1550 '\\newcommand{\\theProprietaryInformation}{...Weave the content of the meta file(s) of metadata.tex.in...' 

1551 

1552 >>> mapper = {'proprietary_information': '/path/that/does/not/resolve.txt'} 

1553 >>> t = r'\newcommand{\theProprietaryInformation}{VALUE.SLOT}%%_PATCH_%_PROPRIETARY_%_INFORMATION_%_LABEL_%%' 

1554 >>> weave_meta_part_proprietary_information(mapper, t) 

1555 '\\newcommand{\\theProprietaryInformation}{/path/that/does/not/resolve.txt}%%_PATCH_...INFORMATION_%_LABEL_%%' 

1556 

1557 >>> really_a_png_file = 'liitos/placeholders/this-resource-is-missing.jpg' 

1558 >>> pathlib.Path(really_a_png_file).is_file() 

1559 True 

1560 >>> mapper = {'proprietary_information': really_a_png_file} 

1561 >>> t = r'\newcommand{\theProprietaryInformation}{VALUE.SLOT}%%_PATCH_%_PROPRIETARY_%_INFORMATION_%_LABEL_%%' 

1562 >>> weave_meta_part_proprietary_information(mapper, t) 

1563 '\\newcommand{\\theProprietaryInformation}{liitos/placeholders/this-resource-is-missing.jpg}%%_PATCH_..._%%' 

1564 

1565 >>> mapper = {'bo_proprietary_information': 'sorry'} 

1566 >>> t = r'\newcommand{\theProprietaryInformation}{VALUE.SLOT}%%_PATCH_%_PROPRIETARY_%_INFORMATION_%_LABEL_%%' 

1567 >>> weave_meta_part_proprietary_information(mapper, t) 

1568 '\\newcommand{\\theProprietaryInformation}{This is a notice.\n}%%_PATCH_%_PROPRIETARY_%_INFORMATION_%_LABEL_%%' 

1569 

1570 >>> restore_value = WEAVE_DEFAULTS['proprietary_information'] 

1571 >>> WEAVE_DEFAULTS['proprietary_information'] = '/path/that/does/not/resolve.txt' 

1572 >>> mapper = {'no_proprietary_information': 'sorry'} 

1573 >>> t = r'\newcommand{\theProprietaryInformation}{VALUE.SLOT}%%_PATCH_%_PROPRIETARY_%_INFORMATION_%_LABEL_%%' 

1574 >>> weave_meta_part_proprietary_information(mapper, t) 

1575 '\\newcommand{\\theProprietaryInformation}{/path/that/does/not/resolve.txt}%%_PATCH_...INFORMATION_%_LABEL_%%' 

1576 >>> WEAVE_DEFAULTS['proprietary_information'] = restore_value 

1577 

1578 >>> really_a_png_file = 'liitos/placeholders/this-resource-is-missing.png' 

1579 >>> pathlib.Path(really_a_png_file).is_file() 

1580 True 

1581 >>> restore_value = WEAVE_DEFAULTS['proprietary_information'] 

1582 >>> WEAVE_DEFAULTS['proprietary_information'] = really_a_png_file 

1583 >>> mapper = {'no_proprietary_information': 'sorry'} 

1584 >>> t = r'\newcommand{\theProprietaryInformation}{VALUE.SLOT}%%_PATCH_%_PROPRIETARY_%_INFORMATION_%_LABEL_%%' 

1585 >>> weave_meta_part_proprietary_information(mapper, t) 

1586 '\\newcommand{\\theProprietaryInformation}{liitos/placeholders/this-resource-is-missing.png}%%_PATCH_..._%%' 

1587 >>> WEAVE_DEFAULTS['proprietary_information'] = restore_value 

1588 """ 

1589 if mapper.get('proprietary_information'): 

1590 prop_info = mapper['proprietary_information'] 

1591 prop_info_path = pathlib.Path(prop_info) 

1592 if prop_info_path.is_file(): 

1593 with open(prop_info_path) as handle: 

1594 try: 

1595 prop_info_from_file = handle.read() 

1596 prop_info = prop_info_from_file 

1597 except (OSError, UnicodeDecodeError) as err: 

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

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

1600 else: 

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

1602 return text.replace(VALUE_SLOT, prop_info) 

1603 else: 

1604 log.warning('proprietary_information value not set ... setting default from module ...') 

1605 prop_info = WEAVE_DEFAULTS['proprietary_information'] 

1606 prop_info_path = pathlib.Path(prop_info) 

1607 if prop_info_path.is_file(): 1607 ↛ 1616line 1607 didn't jump to line 1616 because the condition on line 1607 was always true

1608 with open(prop_info_path) as handle: 

1609 try: 

1610 prop_info_from_file = handle.read() 

1611 prop_info = prop_info_from_file 

1612 except (OSError, UnicodeDecodeError) as err: 

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

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

1615 else: 

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

1617 return text.replace(VALUE_SLOT, prop_info) 

1618 

1619 

1620@no_type_check 

1621def weave_meta_part_stretch( 

1622 mapper: dict[str, str | int | bool | None], 

1623 text: str, 

1624) -> str: 

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

1626 

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

1628 """ 

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

1630 

1631 

1632@no_type_check 

1633def weave_meta_part_lox_indent( 

1634 mapper: dict[str, str | int | bool | None], 

1635 text: str, 

1636) -> str: 

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

1638 

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

1640 """ 

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

1642 

1643 

1644@no_type_check 

1645def dispatch_meta_weaver( 

1646 mapper: dict[str, str | int | bool | None], 

1647 text: str, 

1648) -> str: 

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

1650 dispatch = { 

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

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

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

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

1655 '%%_PATCH_%_TYPE_%%': weave_meta_part_header_type, 

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

1657 '%%_PATCH_%_ID_%%': weave_meta_part_header_id, 

1658 '%%_PATCH_%_ISSUE_%%': weave_meta_part_issue, 

1659 '%%_PATCH_%_REVISION_%%': weave_meta_part_revision, 

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

1661 '%%_PATCH_%_DATE_%%': weave_meta_part_header_date, 

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1681 '%%_PATCH_%_STRETCH_%%': weave_meta_part_stretch, 

1682 '%%_PATCH_%_LOX_INDENT_%%': weave_meta_part_lox_indent, 

1683 } 

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

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

1686 return weaver(mapper, text) 

1687 return text 

1688 

1689 

1690@no_type_check 

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

1692 """TODO.""" 

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

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

1695 if completed and completed[-1]: 

1696 completed.append('\n') 

1697 return completed 

1698 

1699 

1700@no_type_check 

1701def weave( 

1702 doc_root: str | pathlib.Path, 

1703 structure_name: str, 

1704 target_key: str, 

1705 facet_key: str, 

1706 options: dict[str, bool], 

1707 externals: ExternalsType, 

1708) -> int: 

1709 """Weave the metadata received into various targets. 

1710 

1711 Examples: 

1712 

1713 >>> restore_cwd = os.getcwd() 

1714 >>> dr = '.' 

1715 >>> sn = 'foo' 

1716 >>> tk = '' 

1717 >>> fk = '' 

1718 >>> op = {'bar': True} 

1719 >>> ex = {'baz': {'quux': 'nowhere-to-be-found'}} 

1720 >>> weave(dr, sn, tk, fk, op, ex) 

1721 2 

1722 >>> os.chdir(restore_cwd) 

1723 

1724 >>> restore_cwd = os.getcwd() 

1725 >>> dr = 'example/tuna' 

1726 >>> sn = 'structure.yml' 

1727 >>> tk = 'prod_kind' 

1728 >>> fk = 'non-existing-facet-key' 

1729 >>> op = {'bar': True} 

1730 >>> ex = {'baz': {'quux': 'nowhere-to-be-found'}} 

1731 >>> weave(dr, sn, tk, fk, op, ex) 

1732 1 

1733 >>> os.chdir(restore_cwd) 

1734 

1735 >>> restore_cwd = os.getcwd() 

1736 >>> dr = 'test/fixtures/basic/' 

1737 >>> sn = 'structure.yml' 

1738 >>> tk = 'abc' 

1739 >>> fk = 'missing' 

1740 >>> op = {'bar': True} 

1741 >>> ex = {'baz': {'quux': 'nowhere-to-be-found'}} 

1742 >>> weave(dr, sn, tk, fk, op, ex) 

1743 1 

1744 >>> os.chdir(restore_cwd) 

1745 

1746 >>> restore_cwd = os.getcwd() 

1747 >>> dr = 'example/tuna' 

1748 >>> sn = 'structure.yml' 

1749 >>> tk = 'prod_kind' 

1750 >>> fk = 'tuna' 

1751 >>> op = {'bar': True} 

1752 >>> ex = { 

1753 ... 'bookmatter': {'is_custom': False, 'id': 'templates/bookmatter.tex.in'}, 

1754 ... 'driver': {'is_custom': False, 'id': 'templates/driver.tex.in'}, 

1755 ... 'metadata': {'is_custom': False, 'id': 'templates/metadata.tex.in'}, 

1756 ... 'publisher': {'is_custom': False, 'id': 'templates/publisher.tex.in'}, 

1757 ... 'setup': {'is_custom': False, 'id': 'templates/setup.tex.in'}, 

1758 ... } 

1759 >>> weave(dr, sn, tk, fk, op, ex) 

1760 0 

1761 >>> os.chdir(restore_cwd) 

1762 

1763 >>> restore_cwd = os.getcwd() 

1764 >>> dr = 'example/tuna' 

1765 >>> sn = 'structure.yml' 

1766 >>> tk = 'prod_kind' 

1767 >>> fk = 'tuna' 

1768 >>> op = {'bar': True} 

1769 >>> abs_here = pathlib.Path().resolve() 

1770 >>> ex = { 

1771 ... 'bookmatter': {'is_custom': True, 'id': abs_here / 'example/ejected-templates/bookmatter.tex.in'}, 

1772 ... 'driver': {'is_custom': True, 'id': abs_here / 'example/ejected-templates/driver.tex.in'}, 

1773 ... 'metadata': {'is_custom': True, 'id': abs_here / 'example/ejected-templates/metadata.tex.in'}, 

1774 ... 'publisher': {'is_custom': True, 'id': abs_here / 'example/ejected-templates/publisher.tex.in'}, 

1775 ... 'setup': {'is_custom': True, 'id': abs_here / 'example/ejected-templates/setup.tex.in'}, 

1776 ... } 

1777 >>> try: 

1778 ... code = weave(dr, sn, tk, fk, op, ex) 

1779 ... except FileNotFoundError: 

1780 ... code = -1 

1781 >>> os.chdir(restore_cwd) 

1782 >>> code 

1783 0 

1784 

1785 >>> restore_cwd = os.getcwd() 

1786 >>> dr = 'example/ejected-templates' 

1787 >>> sn = 'structure.yml' 

1788 >>> tk = 'prod_kind' 

1789 >>> fk = 'ejected-templates' 

1790 >>> op = {'bar': True} 

1791 >>> abs_here = pathlib.Path().resolve() 

1792 >>> ex = { 

1793 ... 'bookmatter': {'is_custom': True, 'id': abs_here / 'example/ejected-templates/bookmatter.tex.in'}, 

1794 ... 'driver': {'is_custom': True, 'id': abs_here / 'example/ejected-templates/driver.tex.in'}, 

1795 ... 'metadata': {'is_custom': True, 'id': abs_here / 'example/ejected-templates/metadata.tex.in'}, 

1796 ... 'publisher': {'is_custom': True, 'id': abs_here / 'example/ejected-templates/publisher.tex.in'}, 

1797 ... 'setup': {'is_custom': True, 'id': abs_here / 'example/ejected-templates/setup.tex.in'}, 

1798 ... } 

1799 >>> try: 

1800 ... code = weave(dr, sn, tk, fk, op, ex) 

1801 ... except FileNotFoundError: 

1802 ... code = -1 

1803 >>> os.chdir(restore_cwd) 

1804 >>> code 

1805 0 

1806 

1807 >>> restore_cwd = os.getcwd() 

1808 >>> dr = 'example/ejected-templates' 

1809 >>> sn = 'structure.yml' 

1810 >>> tk = 'prod_kind' 

1811 >>> fk = 'ejected-templates-borked' 

1812 >>> op = {'bar': True} 

1813 >>> abs_here = pathlib.Path().resolve() 

1814 >>> ex = { 

1815 ... 'bookmatter': {'is_custom': True, 'id': abs_here / 'example/ejected-templates/bookmatter.tex.in'}, 

1816 ... 'driver': {'is_custom': True, 'id': abs_here / 'example/ejected-templates/driver.tex.in'}, 

1817 ... 'metadata': {'is_custom': True, 'id': abs_here / 'example/ejected-templates/metadata.tex.in'}, 

1818 ... 'publisher': {'is_custom': True, 'id': abs_here / 'example/ejected-templates/publisher.tex.in'}, 

1819 ... 'setup': {'is_custom': True, 'id': abs_here / 'example/ejected-templates/setup.tex.in'}, 

1820 ... } 

1821 >>> try: 

1822 ... code = weave(dr, sn, tk, fk, op, ex) 

1823 ... except FileNotFoundError: 

1824 ... code = -1 

1825 >>> os.chdir(restore_cwd) 

1826 >>> code 

1827 0 

1828 

1829 >>> restore_cwd = os.getcwd() 

1830 >>> dr = 'example/tuna' 

1831 >>> sn = 'structure.yml' 

1832 >>> tk = 'prod_kind' 

1833 >>> fk = 'tuna' 

1834 >>> op = {'bar': True} 

1835 >>> abs_here = pathlib.Path().resolve() 

1836 >>> ex = { 

1837 ... 'bookmatter': {'is_custom': True, 'id': abs_here / 'example/ejected-templates/bookmatter.tex.in-no'}, 

1838 ... 'driver': {'is_custom': True, 'id': abs_here / 'example/ejected-templates/driver.tex.in-no'}, 

1839 ... 'metadata': {'is_custom': True, 'id': abs_here / 'example/ejected-templates/metadata.tex.in-no'}, 

1840 ... 'publisher': {'is_custom': True, 'id': abs_here / 'example/ejected-templates/publisher.tex.in-no'}, 

1841 ... 'setup': {'is_custom': True, 'id': abs_here / 'example/ejected-templates/setup.tex.in-no'}, 

1842 ... } 

1843 >>> try: 

1844 ... code = weave(dr, sn, tk, fk, op, ex) 

1845 ... except FileNotFoundError: 

1846 ... code = -1 

1847 >>> os.chdir(restore_cwd) 

1848 >>> code 

1849 0 

1850 """ 

1851 log.info(LOG_SEPARATOR) 

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

1853 target_code = target_key 

1854 facet_code = facet_key 

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

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

1857 return 2 

1858 

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

1860 

1861 structure, asset_map = gat.prelude( 

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

1863 ) 

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

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

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

1867 os.chdir(rel_concat_folder_path) 

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

1869 

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

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

1872 return 0 if ok else 1 

1873 

1874 metadata = load(aspect_map) 

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

1876 return 1 

1877 

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

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

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

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

1882 log.info( 

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

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

1885 ) 

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

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

1888 bookmatter_path_str = meta_doc_common['bookmatter_path'] 

1889 if bookmatter_path_str and isinstance(bookmatter_path_str, str): 

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

1891 log.info( 

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

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

1894 ) 

1895 

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

1897 log.info( 

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

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

1900 ) 

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

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

1903 driver_path_str = meta_doc_common['driver_path'] 

1904 if driver_path_str and isinstance(driver_path_str, str): 

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

1906 log.info( 

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

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

1909 ) 

1910 

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

1912 log.info( 

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

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

1915 ) 

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

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

1918 metadata_path_str = meta_doc_common['metadata_path'] 

1919 if metadata_path_str and isinstance(metadata_path_str, str): 

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

1921 log.info( 

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

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

1924 ) 

1925 

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

1927 log.info( 

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

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

1930 ) 

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

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

1933 publisher_path_str = meta_doc_common['publisher_path'] 

1934 if publisher_path_str and isinstance(publisher_path_str, str): 

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

1936 log.info( 

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

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

1939 ) 

1940 

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

1942 log.info( 

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

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

1945 ) 

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

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

1948 setup_path_str = meta_doc_common['setup_path'] 

1949 if setup_path_str and isinstance(setup_path_str, str): 

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

1951 log.info( 

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

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

1954 ) 

1955 

1956 if 'approvals_strategy' in meta_doc_common: 

1957 approvals_strategy_str = meta_doc_common['approvals_strategy'] 

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

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

1960 options['approvals_strategy'] = approvals_strategy_str 

1961 log.info( 

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

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

1964 ) 

1965 

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

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

1968 if table_caption_below: 

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

1970 options['table_caption_below'] = table_caption_below 

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

1972 log.info( 

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

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

1975 ) 

1976 

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

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

1979 if table_uglify: 

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

1981 options['table_uglify'] = table_uglify 

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

1983 log.info( 

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

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

1986 ) 

1987 

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

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

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

1991 

1992 try: 

1993 metadata_template = tpl.load_resource(metadata_template, metadata_template_is_custom) 

1994 except FileNotFoundError: 

1995 log.error( 

1996 f'could not load metadata template in {os.getcwd()} per' 

1997 f' tpl.load_resource({metadata_template}, {metadata_template_is_custom})' 

1998 ) 

1999 if metadata_template_is_custom: 

2000 existence = 'does exist' if pathlib.Path(metadata_template).is_file() else 'does not exist' 

2001 log.error(f'detail: external metadata template {existence}') 

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

2003 lines = weave_meta_meta(metadata, lines) 

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

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

2006 

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

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

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

2010 

2011 try: 

2012 driver_template = tpl.load_resource(driver_template, driver_template_is_custom) 

2013 except FileNotFoundError: 

2014 log.error( 

2015 f'could not load driver template in {os.getcwd()} per' 

2016 f' tpl.load_resource({driver_template}, {driver_template_is_custom})' 

2017 ) 

2018 if driver_template_is_custom: 

2019 existence = 'does exist' if pathlib.Path(driver_template).is_file() else 'does not exist' 

2020 log.error(f'detail: external driver template {existence}') 

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

2022 lines = weave_meta_driver(metadata, lines) 

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

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

2025 

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

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

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

2029 

2030 try: 

2031 setup_template = tpl.load_resource(setup_template, setup_template_is_custom) 

2032 except FileNotFoundError: 

2033 log.error( 

2034 f'could not load driver template in {os.getcwd()} per' 

2035 f' tpl.load_resource({setup_template}, {setup_template_is_custom})' 

2036 ) 

2037 if setup_template_is_custom: 

2038 existence = 'does exist' if pathlib.Path(setup_template).is_file() else 'does not exist' 

2039 log.error(f'detail: external setup template {existence}') 

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

2041 lines = weave_meta_setup(metadata, lines) 

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

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

2044 

2045 return 0