forked from sparkutils/quality
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
35 lines (27 loc) · 756 Bytes
/
main.py
File metadata and controls
35 lines (27 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import os
from pathlib import Path
import logging
log = logging.getLogger(__name__)
def withPath(fname, thunk):
if Path(fname).exists():
f = open(fname, "r")
return thunk(f)
else:
log.error(f"Path {fname} was required to run macro")
return "FILENOTFOUND "+fname
def readAndStrip(f):
return f.readline().strip()
def readTwiceAndStrip(f):
f.readline()
return readAndStrip(f)
def define_env(env):
"Hook function"
@env.macro
def project_version():
return withPath("version.txt", lambda f: readAndStrip(f))
@env.macro
def statement_coverage():
return withPath("coverage.txt", lambda f: readAndStrip(f))
@env.macro
def branch_coverage():
return withPath("coverage.txt", lambda f: readTwiceAndStrip(f))