Skip to content

Commit fc25cca

Browse files
committed
tools: move generate_coverage script to tools
a few minor adjustments and tweaks to the script
1 parent b693cc4 commit fc25cca

File tree

1 file changed

+51
-23
lines changed

1 file changed

+51
-23
lines changed

generate_coverage.py renamed to tools/generate_coverage.py

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
1+
#!/usr/bin/env python
12
# coding=utf-8
23
"""
4+
This script will aid in generating a test coverage report for PFASST++ including its examples.
5+
6+
A standard CPython 3.3 compatible Python interpreter with standard library support is required.
7+
No additional modules.
8+
9+
Run it with argument `-h` for usage instructions.
10+
311
.. moduleauthor:: Torbjörn Klatt <[email protected]>
412
"""
5-
613
from sys import version_info
714
# require at least Python 3.3
15+
# (because subprocess.DEVNULL)
816
assert(version_info[0] >= 3 and version_info[1] >= 3)
917

1018

19+
import argparse
20+
import os
21+
import os.path
22+
import shutil
23+
import subprocess as sp
24+
import re
1125
import logging
1226
from logging.config import dictConfig
1327
dictConfig(
@@ -34,27 +48,6 @@
3448
)
3549

3650

37-
import subprocess as sp
38-
try:
39-
sp.check_call('lcov --version', shell=True, stdout=sp.DEVNULL, stderr=sp.DEVNULL)
40-
except sp.CalledProcessError as err:
41-
logging.critical("lcov command not found. It is required.")
42-
raise err
43-
44-
try:
45-
sp.check_call('genhtml --version', shell=True, stdout=sp.DEVNULL, stderr=sp.DEVNULL)
46-
except sp.CalledProcessError as err:
47-
logging.critical("genhtml command not found. It is required.")
48-
raise err
49-
50-
51-
import argparse
52-
import os
53-
import os.path
54-
import shutil
55-
import re
56-
57-
5851
class Options(object):
5952
coverage_dir = ""
6053
build_dir = ""
@@ -65,7 +58,38 @@ class Options(object):
6558

6659

6760
options = Options()
68-
options.base_dir = os.path.abspath(os.path.curdir)
61+
options.base_dir = ""
62+
63+
64+
def is_lcov_available():
65+
try:
66+
sp.check_call('lcov --version', shell=True, stdout=sp.DEVNULL, stderr=sp.DEVNULL)
67+
except sp.CalledProcessError:
68+
logging.critical("lcov command not available. It is required.")
69+
return False
70+
71+
try:
72+
sp.check_call('genhtml --version', shell=True, stdout=sp.DEVNULL, stderr=sp.DEVNULL)
73+
except sp.CalledProcessError:
74+
logging.critical("genhtml command not available. It is required.")
75+
return False
76+
77+
return True
78+
79+
80+
def get_project_root():
81+
logging.info("Determine project root directory")
82+
curr_dir = os.path.abspath(os.path.curdir)
83+
logging.debug("Trying current path: %s" % curr_dir)
84+
if os.access(curr_dir + "/include", os.R_OK) and os.access(curr_dir + "/examples", os.R_OK):
85+
logging.debug("Project root is: %s" % curr_dir)
86+
options.base_dir = curr_dir
87+
else:
88+
logging.warning("Probably called from within the tools dir. "
89+
"This should work but is not recommended. "
90+
"Trying parent directory as project root.")
91+
os.chdir("..")
92+
get_project_root()
6993

7094

7195
def setup_and_init_options():
@@ -80,6 +104,9 @@ def setup_and_init_options():
80104
help="output directory for generated coverage report")
81105

82106
_args = parser.parse_args()
107+
108+
get_project_root()
109+
83110
if not os.access(_args.build_dir, os.W_OK):
84111
logging.critical("Given build path could not be found: %s" % _args.build_dir)
85112
raise ValueError("Given build path could not be found: %s" % _args.build_dir)
@@ -196,6 +223,7 @@ def generate_html():
196223

197224

198225
if __name__ == "__main__":
226+
assert(is_lcov_available())
199227
setup_and_init_options()
200228
get_test_directories()
201229
for test in options.tests:

0 commit comments

Comments
 (0)