github
9 of 10 branches covered (90.0%)
Branch coverage included in aggregate %.
34 of 36 relevant lines covered (94.44%)
6.25 hits per line
1 |
'use strict';
|
|
2 |
|
1✔ |
3 |
const cp = require('child_process');
|
1✔ |
4 |
|
1✔ |
5 |
let interpreter; |
1✔ |
6 |
|
1✔ |
7 |
function doDetect() { |
|
8 |
const interpreterOptions = [ 'python3', 'python', 'python2' ]; |
9✔ |
9 |
for (const opt of interpreterOptions) {
|
|
10 |
const result = cp.spawnSync(opt, [ '--version' ], {
|
15✔ |
11 |
encoding: 'utf-8', |
15✔ |
12 |
}); |
15✔ |
13 |
|
15✔ |
14 |
if (result.status === 0) { |
|
15 |
return opt;
|
8✔ |
16 |
} |
8✔ |
17 |
} |
15✔ |
18 |
return null; |
|
19 |
} |
9✔ |
20 |
|
1✔ |
21 |
exports.detect = function detect() { |
|
22 |
if (interpreter) {
|
|
23 |
return interpreter;
|
× |
24 |
} |
× |
25 |
|
9✔ |
26 |
interpreter = doDetect(); |
9✔ |
27 |
if (!interpreter) {
|
|
28 |
throw new Error('Python interpreter not found'); |
1✔ |
29 |
} |
1✔ |
30 |
|
|
31 |
return interpreter;
|
8✔ |
32 |
}; |
1✔ |
33 |
|
1✔ |
34 |
exports.clearCache = function clearCache() { |
|
35 |
interpreter = null;
|
16✔ |
36 |
}; |
1✔ |