Skip to content

Commit 5ea2780

Browse files
committed
Add 'py2lcov --cmd exe ..' option, so user can specify the name of their Coverage.py execuable.
Default is retrieved from 'COVERAGE_COMMAND' environment variable, or is set to 'coverage' otherwise. See #347 Signed-off-by: Henry Cox <[email protected]>
1 parent 77d1a9b commit 5ea2780

File tree

3 files changed

+42
-23
lines changed

3 files changed

+42
-23
lines changed

.github/workflows/run_test_suite.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ jobs:
6565
6666
sudo perl -MCPAN -e 'install(Memory::Process)' # no package in Ubuntu
6767
68-
sudo ln -s python3-coverage /usr/bin/coverage # until issue #347 is fixed
69-
7068
- name: make install
7169
run: |-
7270
set -x -o pipefail

bin/py2lcov

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,19 @@ first line of the function has a non-zero count.
6767
Best practice is to either always specify '--no-functions' or never specify
6868
'--no-functions'.
6969
70-
Note that xml2lcov does not implement the full suite of LCOV features
71-
(e.g., filtering, substitutions, etc.).
70+
py2lcov uses Coverage.py to extract coverage data.
71+
Note that the name of the Coverage.py executable my differ on your platform.
72+
By default, py2lcov uses 'coverage' (which it expects to be in your path).
73+
You can use a different executable, either:
74+
- through your COVERAGE_COMMAND environment variable, or
75+
- via the 'py2lcov --cmd exename ..' command line option.
76+
77+
py2lcov does not implement the full suite of LCOV features (e.g., filtering,
78+
substitutions, etc.).
7279
Please generate the translated LCOV format file and then read the data
7380
back in to lcov to use any of those features.
7481
%(usage)s
82+
7583
Example:
7684
$ export PYCOV_DATA=path/to/pydata
7785
@@ -98,7 +106,6 @@ Example:
98106
# use differential coverage to see exactly what filtering did
99107
$ genhtml -o html_differential --baseline-file mydata.info filtered.info ...
100108
101-
102109
Deprecated feature:
103110
For backward compatibility, py2lcov also supports translation to LCOV
104111
format from intermediate XML:
@@ -115,6 +122,12 @@ Example:
115122
'usage' : ProcessFile.usageNote,
116123
}
117124

125+
from_env = ''
126+
cover_cmd = 'coverage'
127+
if 'COVERAGE_COMMAND' in os.environ:
128+
cover_cmd = os.environ['COVERAGE_COMMAND']
129+
from_env = ' (from your COVERAGE_COMMAND environment variable)'
130+
118131
parser = argparse.ArgumentParser(
119132
formatter_class=argparse.RawDescriptionHelpFormatter,
120133
epilog=usageString)
@@ -141,6 +154,8 @@ Example:
141154
help='tabsize when computing indent')
142155
parser.add_argument('-k', "--keep-going", dest='keepGoing', default=False, action='store_true',
143156
help="ignore errors")
157+
parser.add_argument('--cmd', dest='cover_cmd', default=cover_cmd,
158+
help='executable used to extract python data - e.g., "python3-coverage". Default is "%s"%s.' % (cover_cmd, from_env))
144159
parser.add_argument('inputs', nargs='*',
145160
help="list of python coverage data input files - expected to be XML or Python .dat format")
146161

@@ -176,7 +191,7 @@ Example:
176191
while os.path.exists(xml):
177192
xml = base + '.xml%d' % suffix
178193
suffix += 1
179-
cmd = 'COVERAGE_FILE=%s coverage xml -o %s' % (f, xml)
194+
cmd = 'COVERAGE_FILE=%s %s xml -o %s' % (f, args.cover_cmd, xml)
180195
try:
181196
#x = subprocess.run(cmd, capture_output=True, shell=True, check=True)
182197
x = subprocess.run(cmd, shell=True, check=True, stdout=True, stderr=True)

tests/py2lcov/py2lcov.sh

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -141,21 +141,27 @@ if [[ 1 == $CLEAN_ONLY ]] ; then
141141
exit 0
142142
fi
143143

144-
which coverage
144+
CMD='coverage'
145+
which $CMD
145146
if [ 0 != $? ] ; then
147+
CMD='python3-coverage' # ubuntu?
148+
fi
149+
which $CMD
150+
if [ 0 != $? ] ; then
151+
echo "cannot find 'coverage' or 'python3-coverage'"
146152
echo "unable to run py2lcov - please install python Coverage.py package"
147153
exit 1
148154
fi
149155

150156
# some corner cases:
151-
COVERAGE_FILE=./functions.dat coverage run --branch ./test.py
157+
COVERAGE_FILE=./functions.dat $CMD run --branch ./test.py
152158
if [ 0 != $? ] ; then
153159
echo "coverage functions failed"
154160
if [ 0 == $KEEP_GOING ] ; then
155161
exit 1
156162
fi
157163
fi
158-
eval ${PYCOV} ${PY2LCOV_TOOL} -o functions.info functions.dat $VERSION
164+
eval ${PYCOV} ${PY2LCOV_TOOL} -o functions.info --cmd $CMD functions.dat $VERSION
159165
if [ 0 != $? ] ; then
160166
echo "py2lcov failed function example"
161167
if [ 0 == $KEEP_GOING ] ; then
@@ -208,7 +214,7 @@ fi
208214

209215

210216
# legacy mode: run with intermediate XML file
211-
COVERAGE_FILE=./functions.dat coverage xml -o functions.xml
217+
COVERAGE_FILE=./functions.dat $CMD xml -o functions.xml
212218
if [ 0 != $? ] ; then
213219
echo "coverage xml failed"
214220
exit 1
@@ -232,7 +238,7 @@ if [ 0 != $? ] ; then
232238
fi
233239

234240
# run again, generating checksum data...
235-
eval ${PYCOV} ${PY2LCOV_TOOL} -o checksum.info functions.dat $VERSION --checksum
241+
eval ${PYCOV} ${PY2LCOV_TOOL} --cmd $CMD -o checksum.info functions.dat $VERSION --checksum
236242
if [ 0 != $? ] ; then
237243
echo "py2lcov failed function example"
238244
if [ 0 == $KEEP_GOING ] ; then
@@ -262,7 +268,7 @@ fi
262268

263269

264270
# run without generating function data:
265-
eval ${PYCOV} ${PY2LCOV_TOOL} functions.dat -o no_functions.info $VERSION --no-function
271+
eval ${PYCOV} ${PY2LCOV_TOOL} functions.dat --cmd $CMD -o no_functions.info $VERSION --no-function
266272
if [ 0 != $? ] ; then
267273
echo "coverage no_functions failed"
268274
if [ 0 == $KEEP_GOING ] ; then
@@ -279,7 +285,7 @@ if [ 0 != $COUNT ] ; then
279285
fi
280286

281287
# run without extracting version
282-
eval ${PYCOV} ${PY2LCOV_TOOL} functions.dat -o no_version.info
288+
eval ${PYCOV} ${PY2LCOV_TOOL} functions.dat --cmd $CMD -o no_version.info
283289
if [ 0 != $? ] ; then
284290
echo "coverage no_functions failed"
285291
if [ 0 == $KEEP_GOING ] ; then
@@ -296,7 +302,7 @@ if [ 0 != $COUNT ] ; then
296302
fi
297303

298304
# test exclusion
299-
eval ${PYCOV} ${PY2LCOV_TOOL} -o excl.info --exclude test.py functions.dat
305+
eval ${PYCOV} ${PY2LCOV_TOOL} -o excl.info --cmd $CMD --exclude test.py functions.dat
300306
if [ 0 != $? ] ; then
301307
echo "coverage no_functions failed"
302308
if [ 0 == $KEEP_GOING ] ; then
@@ -330,7 +336,7 @@ if [ 0 != $? ] ; then
330336
fi
331337

332338
# some usage errors
333-
eval ${PYCOV} ${PY2LCOV_TOOL} functions.dat -o paramErr.info ${VERSION},-x
339+
eval ${PYCOV} ${PY2LCOV_TOOL} functions.dat -o paramErr.info --cmd $CMD ${VERSION},-x
334340
if [ 0 == $? ] ; then
335341
echo "coverage version did not see error"
336342
if [ 0 == $KEEP_GOING ] ; then
@@ -339,7 +345,7 @@ if [ 0 == $? ] ; then
339345
fi
340346

341347
# run again with --keep-going flag - should generate same result as we see without version script
342-
eval ${PYCOV} ${PY2LCOV_TOOL} functions.dat -o keepGoing.info ${VERSION},-x --keep-going --verbose
348+
eval ${PYCOV} ${PY2LCOV_TOOL} functions.dat -o keepGoing.info --cmd $CMD ${VERSION},-x --keep-going --verbose
343349
if [ 0 != $? ] ; then
344350
echo "keepGoing version saw error"
345351
if [ 0 == $KEEP_GOING ] ; then
@@ -359,9 +365,9 @@ fi
359365
# can't run this unless we have a new enough 'coverage' version
360366
# to support the --data-file input
361367
if [[ "${PYCOV}" =~ "COVERAGE_FILE=" || "${PY2LCOV_TOOL}" =~ "COVERAGE_FILE=" ]] ; then
362-
${LCOV_HOME}/bin/py2lcov -o missing.info
368+
${LCOV_HOME}/bin/py2lcov -o missing.info --cmd $CMD
363369
else
364-
eval ${PYCOV} ${PY2LCOV_TOOL} -o missing.info
370+
eval ${PYCOV} ${PY2LCOV_TOOL} -o missing.info --cmd $CMD
365371
fi
366372
if [ 0 == $? ] ; then
367373
echo "did not see error with missing input data"
@@ -371,7 +377,7 @@ if [ 0 == $? ] ; then
371377
fi
372378

373379
# usage error:
374-
eval ${PYCOV} ${PY2LCOV_TOOL} -o noFile.info run.dat y.xml
380+
eval ${PYCOV} ${PY2LCOV_TOOL} -o noFile.info run.dat y.xml --cmd $CMD
375381
if [ 0 == $? ] ; then
376382
echo "did not see error with missing input file"
377383
if [ 0 == $KEEP_GOING ] ; then
@@ -380,7 +386,7 @@ if [ 0 == $? ] ; then
380386
fi
381387

382388
# usage error:
383-
eval ${PYCOV} ${PY2LCOV_TOOL} -o badArg.info --noSuchParam run_help.dat
389+
eval ${PYCOV} ${PY2LCOV_TOOL} -o badArg.info --noSuchParam run_help.dat --cmd $CMD
384390
if [ 0 == $? ] ; then
385391
echo "did not see error with unsupported param"
386392
if [ 0 == $KEEP_GOING ] ; then
@@ -392,10 +398,10 @@ fi
392398
# to support the --data-file input
393399
if [[ "${PYCOV}" =~ "COVERAGE_FILE=" || "${PY2LCOV_TOOL}" =~ "COVERAGE_FILE=" ]] ; then
394400
# can't generate coverage report for this feature...
395-
COVERAGE_FILE=functions.dat ${LCOV_HOME}/bin/py2lcov -o fromEnv.info
401+
COVERAGE_FILE=functions.dat ${LCOV_HOME}/bin/py2lcov -o fromEnv.info --cmd $CMD
396402
else
397403
# get input from environment var:
398-
eval COVERAGE_FILE=functions.dat ${PYCOV} ${PY2LCOV_TOOL} -o fromEnv.info
404+
eval COVERAGE_FILE=functions.dat ${PYCOV} ${PY2LCOV_TOOL} -o fromEnv.info --cmd $CMD
399405
fi
400406

401407
if [ 0 != $? ] ; then
@@ -480,6 +486,6 @@ echo "Tests passed"
480486
if [[ "x$COVER" != "x" && $LOCAL_COVERAGE == 1 ]] ; then
481487
cover
482488
${LCOV_HOME}/bin/perl2lcov -o perlcov.info --testname py2lcov $VERSION ./cover_db
483-
${PY2LCOV_TOOL} -o pycov.info --testname py2lcov $VERSION ${PYCOV_DB}
489+
${PY2LCOV_TOOL} -o pycov.info --testname py2lcov --cmd $CMD $VERSION ${PYCOV_DB}
484490
${GENHTML_TOOL} -o pycov pycov.info perlcov.info --flat --show-navigation --show-proportion --branch $VERSION $ANNOTATE --ignore inconsistent,version
485491
fi

0 commit comments

Comments
 (0)