Coverage for src/lcdoc/mkdocs/lp/plugs/python/pyplugs/call_flow_logging/__init__.py: 50.00%

Shortcuts on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

50 statements  

1import os lp|index.md

2import time lp|index.md

3from functools import partial lp|index.md

4from hashlib import md5 lp|index.md

5 

6from lcdoc.mkdocs.lp.plugs import python lp|index.md

7from lcdoc.mkdocs.tools import add_post_page_func, make_img lp|index.md

8from lcdoc.tools import dirname, exists, read_file, walk_dir, write_file lp|index.md

9 

10config, page, Session, stats = (python.config, python.page, python.Session, python.stats) lp|index.md

11project = python.project lp|index.md

12app = python.app lp|index.md

13nocache = True # we always need to embed the svg into the html, need to be called. lp|index.md

14now = time.time lp|index.md

15 

16 

17def register(fmts): lp|index.md

18 """registering us as renderer for show(<pyplot module>) within lp python""" 

19 fmts['call_flow'] = call_flow_log lp|index.md

20 

21 

22def call_flow_log(s, call, trace, **inner_kw): lp|index.md

23 import lcdoc.call_flows.call_flow_logging as cfl lp|features/lp/python/call_flow_logging/index.md

24 from lcdoc.mkdocs.lp.plugs.kroki import run as kroki_run lp|features/lp/python/call_flow_logging/index.md

25 

26 kw = python.lpkw() lp|features/lp/python/call_flow_logging/index.md

27 trace = [trace] if not isinstance(trace, list) else trace lp|features/lp/python/call_flow_logging/index.md

28 

29 use_case = '_'.join([t.__name__ for t in trace]) lp|features/lp/python/call_flow_logging/index.md

30 call_name = call.__name__ lp|features/lp/python/call_flow_logging/index.md

31 os.environ['PYTEST_CURRENT_TEST'] = 'fakepytest.py::%s' % use_case lp|features/lp/python/call_flow_logging/index.md

32 dest = project.root() + '/build/autodocs/%s/%s.md' % (kw['id'], use_case) lp|features/lp/python/call_flow_logging/index.md

33 python.write_file(dest, '', mkdir=True) lp|features/lp/python/call_flow_logging/index.md

34 f = cfl.document(call, dest=dest) lp|features/lp/python/call_flow_logging/index.md

35 

36 # this creates all infos, incl. plantuml within autodocs dir in /build: 

37 f(call, trace=trace)() lp|features/lp/python/call_flow_logging/index.md

38 

39 # we need to embed the svg, only then mouseovers work. 

40 # But we embedd the svg only later, after html is there, avoids many problems with 

41 # html conversion: 

42 from .svg import embed_svgs 

43 

44 page_ = page() 

45 add_post_page_func(python.Session.kw, embed_svgs, once=True) 

46 

47 # Now every svg may have its own params, e.g. server, plantuml style. 

48 # so we parametrize a kroki plantuml partial for each of them and add to the page: 

49 # Main mess is to find out the actual filename, relative to us but also absolut: 

50 # (relative needed since the svg will also be created within site dir) 

51 

52 d = config()['docs_dir'] + '/autodocs' 

53 if not exists(d): 

54 frm = project.root() + '/build/autodocs/' 

55 app.info('Symlink', frm=frm, to=d) 

56 os.symlink(frm, d) 

57 

58 d = dict(Session.kw) 

59 d['mode'] = 'kroki:plantuml' 

60 sp = page_.file.src_path 

61 pth_up = '../' * (len(sp.split('/')) - 1) 

62 if not sp.endswith('/index.md'): 

63 pth_up = '../' + pth_up 

64 fn = 'autodocs/%s/%s/run_lp_flow.%s/call_flow' 

65 t = kw['id'], use_case, call_name 

66 d['fn'] = fn = fn % t 

67 pth_d = pth_up + fn.rsplit('/', 1)[0] 

68 

69 uml = read_file(config()['docs_dir'] + '/' + fn + '.plantuml') 

70 d['fn'] = pth_up + fn + '.svg' 

71 d['add_svg'] = True 

72 d['page'] = page_ 

73 setattr(page_, 'to_svg_' + kw['id'], partial(kroki_run, uml, d)) 

74 

75 return {'nocache': True, 'res': '\n<lp_svg "%s::%s" />\n' % (kw['id'], pth_d)}