-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
84 lines (60 loc) · 2.55 KB
/
build.py
File metadata and controls
84 lines (60 loc) · 2.55 KB
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
from pybuilder.core import use_plugin, init, Author, task
from pybuilder.pluginhelper.external_command import ExternalCommandBuilder
from pybuilder.utils import read_file
import json
use_plugin('python.core')
use_plugin('python.unittest')
use_plugin('python.install_dependencies')
use_plugin('python.flake8')
use_plugin('python.coverage')
use_plugin('python.distutils')
use_plugin('filter_resources')
name = 'HPaccess'
authors = [
Author('David')]
summary = 'A Python utility to manage the admin account password and LDAP membership of the OA and the VCM'
url = 'https://redacted'
version = '1.0.0'
default_task = [
'clean',
'analyze',
'cyclomatic_complexity',
'package']
@init
def set_properties(project):
project.set_property('unittest_module_glob', 'test_*.py')
project.set_property('teamcity_output', True)
project.set_property('coverage_break_build', False)
project.set_property('flake8_max_line_length', 120)
project.set_property('flake8_verbose_output', True)
project.set_property('flake8_break_build', True)
project.set_property('flake8_include_scripts', True)
project.set_property('flake8_include_test_sources', True)
project.set_property('flake8_ignore', 'E501, W503, F401')
project.get_property('filter_resources_glob').extend([
'**/HPaccess/*'])
project.build_depends_on_requirements('requirements-build.txt')
project.depends_on_requirements('requirements.txt')
@task('cyclomatic_complexity', description='calculates and publishes cyclomatic complexity')
def cyclomatic_complexity(project, logger):
command = ExternalCommandBuilder('radon', project)
command.use_argument('cc')
command.use_argument('-a')
result = command.run_on_production_source_files(logger)
if len(result.error_report_lines) > 0:
logger.error('Errors while running radon, see {0}'.format(result.error_report_file))
for line in result.report_lines[:-1]:
logger.debug(line.strip())
average_complexity_line = result.report_lines[-1].strip()
logger.info(average_complexity_line)
def _coverage_file(project):
return project.expand_path('$dir_reports/{0}'.format('coverage.json'))
def get_value(line):
if ':' in line:
return line.split(':')[1].strip()
@task('publish_coverage', description='publishes overall coverage')
def publish_coverage(project, logger):
coverage_file = _coverage_file(project)
coverage_json = read_file(coverage_file)
coverage = json.loads(''.join(coverage_json))['overall_coverage']
logger.info('Overall coverage: {0}'.format(coverage))