-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathworker.js
64 lines (54 loc) · 1.48 KB
/
worker.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'use strict';
var fs = require('fs');
var path = require('path');
function shellCommand(command) {
if (!command || !command.replace(/#[^\n]*/g, '').trim().length) {
return;
}
return {
command: 'sh',
args: ['-x', '-c', command]
};
}
module.exports = {
init: function (config, job, context, done) {
var venvDir = path.join(context.baseDir, '.venv');
var test, runtime;
if (config) {
if (config.test !== 'none') {
test = config.test
}
if (config.runtime !== 'none') {
runtime = config.runtime
} else {
runtime = '2'
}
}
var defaultPrepare = function (context, done) {
if (!fs.existsSync(path.join(context.dataDir, 'requirements.txt'))) {
// skip if default and no requirements.txt exists
// we assume that if you're configuring your own, you'll ensure the file exists
return done(null, true);
}
context.cmd('pip install -r requirements.txt', function (err) {
done(err, true);
});
}
var prepare = defaultPrepare;
if (config && config.prepare) {
prepare = shellCommand(config.prepare);
}
done(null, {
path: [path.join(venvDir, 'bin')],
environment: 'virtualenv -p python' + runtime + ' ' + venvDir,
prepare: prepare,
test: test
});
},
autodetect: {
filename: 'requirements.txt',
exists: true,
language: 'python',
framework: null
}
};