Coverage for src/lcdoc/tools.py: 61.39%

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

242 statements  

1""" 

2Common tools for all modules 

3 

4""" 

5import collections lppytest

6import hashlib lppytest

7import json lppytest

8import os lppytest

9import socket lppytest

10import sys lppytest

11import time lppytest

12 

13import toml lppytest

14 

15from lcdoc.log import app, now lppytest

16 

17exists = os.path.exists lppytest

18 

19# fastest algo: 

20def file_hash(fn, algo='blake2b'): lppytest

21 return getattr(hashlib, algo)(open(fn, 'rb').read()).hexdigest() lp|features/lp/plugs/drawio/index.md

22 

23 

24def dirname(fn, create=False): lppytest

25 d = os.path.dirname(fn) lplp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/python/call_flow_logging/index.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|index.mdlp|index.mdlp|index.mdlp|task_runner.mdpytest

26 if create: 26 ↛ 27line 26 didn't jump to line 27, because the condition on line 26 was never truelplp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/python/call_flow_logging/index.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|index.mdlp|index.mdlp|index.mdlp|task_runner.mdpytest

27 os.makedirs(d, exist_ok=True) 

28 return d lplp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/python/call_flow_logging/index.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|index.mdlp|index.mdlp|index.mdlp|task_runner.mdpytest

29 

30 

31def require(cmd, name=None, die=True, _have=set()): lppytest

32 '''cmd e.g. "rg --version"''' 

33 name = name or cmd.split(' ', 1)[0] lplp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/show_src/index.md

34 if cmd in _have: lplp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/show_src/index.md

35 return True lp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/show_src/index.md

36 if os.system(cmd + ' >/dev/null') == 0: 36 ↛ 40line 36 didn't jump to line 40, because the condition on line 36 was never falselplp|features/lp/eval.md

37 _have.add(cmd) lplp|features/lp/eval.md

38 return True lplp|features/lp/eval.md

39 

40 msg = 'Missing required command: %s' % name 

41 if die: 

42 app.die(msg, tried=cmd) 

43 else: 

44 app.warning(msg, tried=cmd) 

45 return False 

46 

47 

48def hostname(c=[0]): lppytest

49 i = c[0] 

50 if i: 

51 return i 

52 c[0] = socket.gethostname() 

53 return c[0] 

54 

55 

56def into(d, k, v): lppytest

57 """the return is important for e.g. rx""" 

58 d[k] = v 

59 return d 

60 

61 

62def to_list(o): lppytest

63 o = [] if o is None else o lp|features/lp/python/call_flow_logging/index.mdpytest|tests.test_cfl.test_one

64 t = type(o) lp|features/lp/python/call_flow_logging/index.mdpytest|tests.test_cfl.test_one

65 return o if t == list else list(o) if t == tuple else [o] lp|features/lp/python/call_flow_logging/index.mdpytest|tests.test_cfl.test_one

66 

67 

68# ----------------------------------------------------------------------------- file ops 

69def walk_dir(directory, crit=None): lppytest

70 crit = (lambda *a: True) if crit is None else crit 

71 files = [] 

72 j = os.path.join 

73 for (dirpath, dirnames, filenames) in os.walk(directory): 

74 files += [j(dirpath, file) for file in filenames if crit(dirpath, file)] 

75 return files 

76 

77 

78def read_file(fn, dflt=None, bytes=-1, strip_comments=False): lppytest

79 """ 

80 API function. 

81 read a file - return a default if it does not exist""" 

82 if not exists(fn): lplp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|index.mdlp|index.mdlp|index.mdlp|task_runner.md

83 if dflt is not None: 83 ↛ 85line 83 didn't jump to line 85, because the condition on line 83 was never falselplp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|index.mdlp|index.mdlp|task_runner.md

84 return dflt lplp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|index.mdlp|index.mdlp|task_runner.md

85 raise Exception(fn, 'does not exist') 

86 with open(fn) as fd: lplp|about/changelog.mdlp|about/navigation.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_src/index.mdlp|index.mdlp|index.md

87 # no idea why but __etc__hostname always contains a linesep at end 

88 # not present in source => rstrip(), hope this does not break templs 

89 res = fd.read(bytes) lplp|about/changelog.mdlp|about/navigation.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_src/index.mdlp|index.mdlp|index.md

90 res = res if not res.endswith('\n') else res[:-1] lplp|about/changelog.mdlp|about/navigation.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_src/index.mdlp|index.mdlp|index.md

91 if strip_comments: 91 ↛ 92line 91 didn't jump to line 92, because the condition on line 91 was never truelplp|about/changelog.mdlp|about/navigation.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_src/index.mdlp|index.mdlp|index.md

92 lines = res.splitlines() 

93 res = '\n'.join([l for l in lines if not l.startswith('#')]) 

94 return res lplp|about/changelog.mdlp|about/navigation.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_src/index.mdlp|index.mdlp|index.md

95 

96 

97def insert_file(fn, content, sep): lppytest

98 s = read_file(fn).split(sep) lp|index.md

99 if not len(s) == 3: 99 ↛ 100line 99 didn't jump to line 100, because the condition on line 99 was never truelp|index.md

100 raise Exception(f'No 2 times occurrance of sep in file. sep: {sep}, fn: {fn}') 

101 write_file(fn, s[0] + sep + content + sep + s[2]) lp|index.md

102 

103 

104def write_file(fn, s, log=0, mkdir=0, chmod=None, mode='w', only_on_change=False): lppytest

105 'API: Write a file. chmod e.g. 0o755 (as octal integer)' 

106 

107 fn = os.path.abspath(fn) lplp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/python/call_flow_logging/index.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|features/lp/xterm.mdlp|index.mdlp|index.mdlp|index.mdlp|task_runner.mdpytest|tests.test_cfl.test_one

108 

109 if isinstance(s, (list, tuple)): 109 ↛ 110line 109 didn't jump to line 110, because the condition on line 109 was never truelplp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/python/call_flow_logging/index.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|features/lp/xterm.mdlp|index.mdlp|index.mdlp|index.mdlp|task_runner.mdpytest|tests.test_cfl.test_one

110 s = '\n'.join(s) 

111 if only_on_change: lplp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/python/call_flow_logging/index.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|features/lp/xterm.mdlp|index.mdlp|index.mdlp|index.mdlp|task_runner.mdpytest|tests.test_cfl.test_one

112 so = read_file(fn, dflt='xxx') lp|features/lp/parameters.mdlp|features/lp/plugs/make_badges/index.mdlp|index.md

113 if s == so: lp|features/lp/parameters.mdlp|features/lp/plugs/make_badges/index.mdlp|index.md

114 return lp|index.md

115 

116 if log > 0: 116 ↛ 117line 116 didn't jump to line 117, because the condition on line 116 was never truelplp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/python/call_flow_logging/index.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|features/lp/xterm.mdlp|index.mdlp|index.mdlp|index.mdlp|task_runner.mdpytest|tests.test_cfl.test_one

117 app.info('Writing file', fn=fn) 

118 if log > 1: 118 ↛ 119line 118 didn't jump to line 119, because the condition on line 118 was never truelplp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/python/call_flow_logging/index.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|features/lp/xterm.mdlp|index.mdlp|index.mdlp|index.mdlp|task_runner.mdpytest|tests.test_cfl.test_one

119 sep = '\n----------------------\n' 

120 ps = ( 

121 s 

122 if not 'key' in fn and not 'assw' in fn and not 'ecret' in fn 

123 else '<hidden>' 

124 ) 

125 app.debug('Content', content=sep + ps + sep[:-1]) 

126 e = None lplp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/python/call_flow_logging/index.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|features/lp/xterm.mdlp|index.mdlp|index.mdlp|index.mdlp|task_runner.mdpytest|tests.test_cfl.test_one

127 while True: lplp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/python/call_flow_logging/index.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|features/lp/xterm.mdlp|index.mdlp|index.mdlp|index.mdlp|task_runner.mdpytest|tests.test_cfl.test_one

128 try: lplp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/python/call_flow_logging/index.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|features/lp/xterm.mdlp|index.mdlp|index.mdlp|index.mdlp|task_runner.mdpytest|tests.test_cfl.test_one

129 with open(fn, mode) as fd: lplp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/python/call_flow_logging/index.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|features/lp/xterm.mdlp|index.mdlp|index.mdlp|index.mdlp|task_runner.mdpytest|tests.test_cfl.test_one

130 fd.write(str(s)) lplp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/python/call_flow_logging/index.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|features/lp/xterm.mdlp|index.mdlp|index.mdlp|index.mdlp|task_runner.mdpytest|tests.test_cfl.test_one

131 if chmod: 131 ↛ 132line 131 didn't jump to line 132, because the condition on line 131 was never truelplp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/python/call_flow_logging/index.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|features/lp/xterm.mdlp|index.mdlp|index.mdlp|index.mdlp|task_runner.mdpytest|tests.test_cfl.test_one

132 if not isinstance(chmod, (list, tuple)): 

133 chmod = [int(chmod)] 

134 for s in chmod: 

135 os.chmod(fn, s) 

136 return fn lplp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/python/call_flow_logging/index.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|features/lp/xterm.mdlp|index.mdlp|index.mdlp|index.mdlp|task_runner.mdpytest|tests.test_cfl.test_one

137 except IOError as ex: 137 ↛ 144line 137 didn't jump to line 144lp|features/lp/python/call_flow_logging/index.md

138 if mkdir: 138 ↛ 143line 138 didn't jump to line 143, because the condition on line 138 was never falselp|features/lp/python/call_flow_logging/index.md

139 mkdir = 0 lp|features/lp/python/call_flow_logging/index.md

140 d = os.path.dirname(fn) lp|features/lp/python/call_flow_logging/index.md

141 os.makedirs(d) lp|features/lp/python/call_flow_logging/index.md

142 continue lp|features/lp/python/call_flow_logging/index.md

143 e = ex 

144 except Exception as ex: 

145 e = ex 

146 app.die('Could not write file', filename=fn, exc=e) 

147 

148 

149have_tty = lambda: sys.stdin.isatty() and sys.stdout.isatty() 149 ↛ exitline 149 didn't run the lambda on line 149lppytest

150 

151 

152def flatten(d, sep='_', tpljoin=None): lppytest

153 """when tpljoin is given we detect them as keys and join 

154 (enables json serialization)""" 

155 

156 obj = collections.OrderedDict() lp

157 

158 def recurse(t, parent_key=''): lp

159 

160 if isinstance(t, list): lp

161 for i in range(len(t)): lp

162 recurse(t[i], parent_key + sep + str(i) if parent_key else str(i)) lp

163 elif isinstance(t, dict): lp

164 for k, v in t.items(): lp

165 if isinstance(k, tuple): 165 ↛ 166line 165 didn't jump to line 166, because the condition on line 165 was never truelp

166 k = tpljoin.join(k) 

167 recurse(v, parent_key + sep + k if parent_key else k) lp

168 else: 

169 obj[parent_key] = t lp

170 

171 recurse(d) lp

172 

173 return obj lp

174 

175 

176from collections import OrderedDict as OD lppytest

177 

178 

179def unflatten(dictionary, sep='_'): lppytest

180 resultDict = OD() lp

181 for key, value in dictionary.items(): lp

182 parts = key.split(sep) lp

183 d = resultDict lp

184 for part in parts[:-1]: lp

185 if part not in d: lp

186 d[part] = OD() lp

187 if isinstance(d[part], str): lp

188 d[part] = OD({None: d[part]}) lp

189 d = d[part] lp

190 

191 d[parts[-1]] = value lp

192 return resultDict lp

193 

194 

195def deep_update(o, n, sep): lppytest

196 of = flatten(o, sep) 

197 nf = flatten(n, sep) 

198 of.update(nf) 

199 return unflatten(of, sep) 

200 

201 

202class project: lppytest

203 """loads the project config 

204 

205 Main app config put into project.cfg['app'] 

206 An optional tool.lc.app section will be merged into that 

207 

208 TODO: other formats than pyproject.toml 

209 

210 """ 

211 

212 config, dir_home, fn_cfg = {}, None, None lppytest

213 

214 def root(config=None, root=None, c=[0]): lppytest

215 """ 

216 config must given first time. Understood currently: mkdocs config 

217 """ 

218 if root is not None: lplp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/python/_tech.mdlp|features/lp/python/call_flow_logging/index.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|index.mdlp|index.mdlp|index.mdlp|task_runner.mdpytestpytest|tests.test_cfl.test_one

219 c[0] = root # for tests, to force it pytest

220 if c[0]: lplp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/python/_tech.mdlp|features/lp/python/call_flow_logging/index.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|index.mdlp|index.mdlp|index.mdlp|task_runner.mdpytestpytest|tests.test_cfl.test_one

221 return c[0] lplp|about/changelog.mdlp|about/coverage.mdlp|about/credits.mdlp|about/navigation.mdlp|features/lp/bash/index.mdlp|features/lp/bash/sessions.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/eval.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/_tech.mdlp|features/lp/plugs/chart/index.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/column/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/flowchart/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_badges/index.mdlp|features/lp/plugs/make_file/index.mdlp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/mermaid/index.mdlp|features/lp/plugs/show_file/index.mdlp|features/lp/plugs/show_src/index.mdlp|features/lp/python/_tech.mdlp|features/lp/python/_tech.mdlp|features/lp/python/call_flow_logging/index.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.mdlp|features/lp/xterm.mdlp|index.mdlp|index.mdlp|index.mdlp|task_runner.mdpytestpytest|tests.test_cfl.test_one

222 ret = 0 lppytest

223 try: lppytest

224 if config and hasattr(config, '__getitem__'): 224 ↛ 229line 224 didn't jump to line 229, because the condition on line 224 was never falselppytest

225 dd = config.get('docs_dir') lppytest

226 if dd: 226 ↛ 229line 226 didn't jump to line 229, because the condition on line 226 was never falselppytest

227 ret = c[0] = dirname(dd) lppytest

228 return ret lppytest

229 try: 

230 # if we run in pytest *and* have devapp, we can create call flow logs 

231 # for devapps: 

232 from devapp.tools import project 

233 

234 ret = c[0] = project.root() 

235 return ret 

236 except: 

237 pass 

238 # todo: look at git here 

239 raise Exception('Cannot derive project root') 

240 finally: 

241 c[0] = ret lppytest

242 

243 fn_config = lambda: project.root() + '/pyproject.toml' lplp|features/lp/plugs/make_badges/index.mdlp|index.mdpytest

244 d_autodocs = lambda: project.root() + '/build/autodocs' 244 ↛ exitline 244 didn't run the lambda on line 244lppytest

245 

246 def abs_path(fn, config=None, mkdirs=False): lppytest

247 r = project.root(config) 

248 if not fn: 

249 return r 

250 if fn[0] != '/': 

251 fn = r + '/' + fn 

252 if mkdirs: 

253 os.makedirs(dirname(fn), exist_ok=True) 

254 return fn 

255 

256 # TODO: understand also poetry and piptools: 

257 def load_config(): lppytest

258 

259 fn = project.fn_config() lp|features/lp/plugs/make_badges/index.mdlp|index.md

260 if not exists(fn): 260 ↛ 261line 260 didn't jump to line 261, because the condition on line 260 was never truelp|features/lp/plugs/make_badges/index.mdlp|index.md

261 app.die('no config found', fn=fn) 

262 

263 cfg = toml.load(fn) lp|features/lp/plugs/make_badges/index.mdlp|index.md

264 app.info('loaded config', filename=fn) lp|features/lp/plugs/make_badges/index.mdlp|index.md

265 c = project.config lp|features/lp/plugs/make_badges/index.mdlp|index.md

266 c.update(cfg) lp|features/lp/plugs/make_badges/index.mdlp|index.md

267 if not 'project' in c: 267 ↛ 268line 267 didn't jump to line 268, because the condition on line 267 was never truelp|features/lp/plugs/make_badges/index.mdlp|index.md

268 c['project'] = {'urls': {}} 

269 if 'tool' in c and 'poetry' in c['tool']: 269 ↛ 274line 269 didn't jump to line 274, because the condition on line 269 was never falselp|features/lp/plugs/make_badges/index.mdlp|index.md

270 c['project'].update(c['tool']['poetry']) lp|features/lp/plugs/make_badges/index.mdlp|index.md

271 c['project']['urls']['homepage'] = c['project']['homepage'] lp|features/lp/plugs/make_badges/index.mdlp|index.md

272 c['project']['urls']['repository'] = c['project']['repository'] lp|features/lp/plugs/make_badges/index.mdlp|index.md

273 

274 t = cfg['tool'] lp|features/lp/plugs/make_badges/index.mdlp|index.md

275 # breakpoint() # FIXME BREAKPOINT 

276 # c['app'] = t['poetry'] 

277 # c['app'].update(t.get('lc', {}).get('app', {})) 

278 project.fn_cfg = fn lp|features/lp/plugs/make_badges/index.mdlp|index.md

279 # app.die('Did not find a pyproject.toml file with badges declared') 

280 return project.config lp|features/lp/plugs/make_badges/index.mdlp|index.md

281 

282 def conf(): lppytest

283 return project.config or project.load_config() lp|about/credits.mdlp|index.md

284 

285 def name(): lppytest

286 p = project.conf() lp|about/credits.mdlp|index.md

287 return p['project']['name'] lp|about/credits.mdlp|index.md

288 

289 def urls(): lppytest

290 p = project.conf()['project'] lp|index.md

291 if 'urls' in p: 291 ↛ 293line 291 didn't jump to line 293, because the condition on line 291 was never falselp|index.md

292 return p['urls'] lp|index.md

293 urls = 'packagehome', 'discusshome', 'homepage', 'repository' 

294 return {k: p.get(k, '') for k in urls} 

295 

296 def homepage(): lppytest

297 return project.urls().get('homepage', 'n.a.') 

298 

299 def repository(): lppytest

300 return project.urls().get('repository', 'n.a.') 

301 

302 def packagehome(): lppytest

303 return ( 

304 project.urls().get('packagehome') 

305 or 'https://pypi.org/project/%s/_VERSION_/' % project.name() 

306 ).replace('_VERSION_', project.version()) 

307 

308 def version(): lppytest

309 p = project.conf()['project'] lp|index.md

310 v = p['version'] lp|index.md

311 if isinstance(v, dict) and v.get('use_scm'): 311 ↛ 312line 311 didn't jump to line 312, because the condition on line 311 was never truelp|index.md

312 raise NotImplemented('currently only poetry') 

313 # from pdm.pep517.scm import get_version_from_scm 

314 # v = get_version_from_scm(project.root()) 

315 return str(v) lp|index.md

316 

317 def dependencies(): lppytest

318 d = project.conf()['project']['dependencies'] lp|about/credits.md

319 if isinstance(d, dict): 319 ↛ 323line 319 didn't jump to line 323, because the condition on line 319 was never falselp|about/credits.md

320 # poetry: 

321 return d lp|about/credits.md

322 # pdm (pep) 

323 return parse_deps(d) 

324 

325 def dev_dependencies(): lppytest

326 p = project.conf()['project'] lp|about/credits.md

327 dd = p.get('dev-dependencies') lp|about/credits.md

328 if dd: 328 ↛ 334line 328 didn't jump to line 334lp|about/credits.md

329 if isinstance(dd, dict): 329 ↛ 332line 329 didn't jump to line 332, because the condition on line 329 was never falselp|about/credits.md

330 # poetry - already dict: 

331 return dd lp|about/credits.md

332 return parse_deps(dd) 

333 

334 r = [ 

335 l 

336 for k in project.conf()['tool']['pdm']['dev-dependencies'].values() 

337 for l in k 

338 ] 

339 return parse_deps(r) 

340 

341 def lock_data(): lppytest

342 fn = [] lp|about/credits.md

343 for k in 'pdm', 'poetry': 343 ↛ 347line 343 didn't jump to line 347, because the loop on line 343 didn't completelp|about/credits.md

344 fn.insert(0, project.root() + '/%s.lock' % k) lp|about/credits.md

345 if exists(fn[0]): lp|about/credits.md

346 return toml.load(fn[0]) lp|about/credits.md

347 app.die('No lock file in root', fn) 

348 

349 

350def parse_deps(deplist, seps='~<>!= '): lppytest

351 m = {} 

352 for dep in deplist: 

353 h = False 

354 for s in seps: 

355 if s in dep: 

356 l = dep.split(s, 1) 

357 m[l[0]] = (s + l[1]).strip() 

358 h = True 

359 break 

360 if not h: 

361 m[dep] = '' 

362 return m