-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
180 lines (159 loc) · 5.19 KB
/
gulpfile.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
var gulp = require('gulp'),
shell = require('gulp-shell'),
runSequence = require('run-sequence');
var config = {
sourceDir: 'project/',
reportDir: 'reports/',
docDir: 'docs/',
testDir: 'test/'
};
/**
* Creates missing directories
*/
gulp.task('prepare', shell.task(['mkdir -p ' + config.reportDir]));
/**
* Runs pylint on all python files within the project directory
*/
gulp.task('pylint', function() {
var files = [];
gulp.src(config.sourceDir + '**/*.py')
.on('data', function(file) {
files.push(file.path);
})
.on('data', function() {
shell.task(
['pylint ' + files.join(' ') + ' -f html > ' + config.reportDir + 'pylint_report.html'],
{quiet: true, ignoreErrors: true}
)();
});
});
/**
* Runs autopep8 to automatically fix PEP8 issues
*/
gulp.task('autopep8', function() {
var files = [];
gulp.src(config.sourceDir + '**/*.py')
.on('data', function(file) {
files.push(file.path);
})
.on('data', function() {
shell.task(['autopep8 --in-place --recursive --aggressive --aggressive ' + files.join(' ')])();
});
});
/**
* Runs the clonedigger command to find duplicate code
*/
gulp.task('clonedigger', shell.task(
['clonedigger ' + config.sourceDir + ' --ignore-dir=' + config.testDir +
' --output ' + config.reportDir + 'clonedigger.html'
]
));
/**
* Runs pycallgraph on all python files to generate diagrams showing the call graphs
*/
gulp.task('pycallgraph', function() {
var files = [];
gulp.src([config.sourceDir + '**/*.py', '!/**/__init__.py', '!' + config.sourceDir + config.testDir + '*'])
.on('data', function(file) {
files.push(file.path);
})
.on('data', function() {
shell.task([
'cd ' + config.sourceDir +
' && pycallgraph graphviz --output-file ' + __dirname + '/' + config.reportDir + 'pycallgraph.png' +
' -- ' + files.join(' ')
],
{quiet: true}
)();
});
});
/**
* Runs coverage on all python files to generate a code coverage report
*/
gulp.task('coverage', function() {
var files = [];
gulp.src([config.sourceDir + '**/*.py', '!/**/__init__.py', '!' + config.sourceDir + config.testDir + '*'])
.on('data', function(file) {
files.push(file.path);
})
.on('data', function() {
shell.task([
'cd ' + config.sourceDir +
' && coverage run ' + files.join(' ') +
' && coverage html',
'mv ' + config.sourceDir + 'htmlcov ' + __dirname + '/' + config.reportDir + 'htmlcov',
'rm ' + config.sourceDir + '.coverage'
],
{quiet: true, ignoreErrors: true}
)();
});
});
/**
* Runs pyreverse on all python files to generate UML diagrams of the packages and classes
*/
gulp.task('pyreverse', function() {
var directories = [];
gulp.src([config.sourceDir + '**/*.py', '!/**/__init__.py', '!' + config.sourceDir + config.testDir + '*'])
.on('data', function(file) {
reduced_file = file.path.replace(__dirname + '/' + config.sourceDir, '');
if (reduced_file.indexOf('/') === -1) {
directories.push(reduced_file);
} else {
folder = reduced_file.replace(/[^\/]*$\//, '')
if (directories.indexOf(folder) === -1) {
directories.push(folder);
}
}
})
.on('data', function() {
shell.task([
'cd ' + config.sourceDir + ' && pyreverse -o png -p Uml ' + directories.join(' '),
'mv ' + config.sourceDir + '*.png ' + config.docDir
],
{quiet: true, ignoreErrors: true}
)();
});
});
/**
* Runs the sphinx command to create an automated API documentation
*/
gulp.task('sphinx', shell.task(
[
'sphinx-apidoc ' + config.sourceDir + ' -o ' + config.docDir + 'sphinx/source --force',
'cd ' + config.docDir + 'sphinx && make clean && make html'
]
));
/**
* Runs the vulture command to find unused code without executing the module
*/
gulp.task('vulture', shell.task(
[
'vulture ' + config.sourceDir + ' --exclude=' + config.sourceDir + config.testDir +
' | tee ' + config.reportDir + 'vulture.txt'
],
{ignoreErrors: true}
));
/**
* Runs nosetests to run unit tests
*/
gulp.task('test', shell.task(
['nosetests ' + config.sourceDir + ' -v 2>&1 | tee ' + config.reportDir + 'unittests.txt']
));
/**
* Report task to bundle single reporting tasks
*/
gulp.task('report', function(callback){
runSequence('prepare', 'pylint', 'clonedigger', 'pycallgraph', 'coverage', 'vulture', 'test', callback)
});
/**
* Documentation task to bundle single documentation tasks
*/
gulp.task('documentate', function(callback){
runSequence('sphinx', 'pyreverse', callback)
});
/**
* Default gulp task to run reports and documentation
*/
gulp.task('default', function(callback){
runSequence('documentate', 'report', callback)
});