summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-10-18 05:39:17 +0000
committerGerrit Code Review <review@openstack.org>2018-10-18 05:39:17 +0000
commit422fc1f4adcf47df39401b37dabe030abccd9693 (patch)
tree7273d670e0206faabbdfdaa0c6033fa7d5812b95
parentc662ef5bd9af59da1b907cc6d62808d2eb399c93 (diff)
parent421f533b6171ea6140e0967a75765cb73404241f (diff)
Merge "Extract pep8 messages for inline comments"
-rw-r--r--roles/tox/library/tox_parse_output.py75
-rw-r--r--roles/tox/tasks/main.yaml23
-rw-r--r--test-requirements.txt1
-rw-r--r--tox.ini4
4 files changed, 102 insertions, 1 deletions
diff --git a/roles/tox/library/tox_parse_output.py b/roles/tox/library/tox_parse_output.py
new file mode 100644
index 0000000..7a77f11
--- /dev/null
+++ b/roles/tox/library/tox_parse_output.py
@@ -0,0 +1,75 @@
1#!/usr/bin/python
2
3# Copyright (c) 2018 Red Hat
4#
5# This module is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# This software is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this software. If not, see <http://www.gnu.org/licenses/>.
17from __future__ import absolute_import, division, print_function
18__metaclass__ = type
19
20DOCUMENTATION = '''
21---
22module: tox_parse_output
23short_description: Parses the output of tox looking for per-line comments
24author: Monty Taylor (@mordred)
25description:
26 - Looks for output from the tox command to find content that could be
27 returned as inline comments.
28requirements:
29 - "python >= 3.5"
30options:
31 tox_output:
32 description:
33 - Output from the tox command run
34 required: true
35 type: str
36'''
37from ansible.module_utils.basic import AnsibleModule
38
39
40def extract_file_comments(tox_output):
41 ret = {}
42 for line in tox_output.split('\n'):
43 try:
44 if not line:
45 continue
46 if line[0].isspace():
47 continue
48 if ': ' not in line:
49 continue
50 (file_info, message) = line.split(': ', 1)
51 (file_path, start_line, start_char) = file_info.split(':')
52 if file_path.startswith('./'):
53 file_path = file_path[2:]
54 ret.setdefault(file_path, [])
55 ret[file_path].append(dict(line=int(start_line),
56 message=message))
57 except Exception:
58 pass
59 return ret
60
61
62def main():
63 module = AnsibleModule(
64 argument_spec=dict(
65 tox_output=dict(required=True, type='str'),
66 )
67 )
68 tox_output = module.params['tox_output']
69
70 file_comments = extract_file_comments(tox_output)
71 module.exit_json(changed=False, file_comments=file_comments)
72
73
74if __name__ == '__main__':
75 main()
diff --git a/roles/tox/tasks/main.yaml b/roles/tox/tasks/main.yaml
index b1f464f..3c4a7b0 100644
--- a/roles/tox/tasks/main.yaml
+++ b/roles/tox/tasks/main.yaml
@@ -36,3 +36,26 @@
36 chdir: "{{ zuul_work_dir }}" 36 chdir: "{{ zuul_work_dir }}"
37 environment: "{{ tox_environment|combine(tox_constraints_env|default({})) }}" 37 environment: "{{ tox_environment|combine(tox_constraints_env|default({})) }}"
38 command: "{{ tox_executable }} -e{{ tox_envlist }} {{ tox_extra_args }}" 38 command: "{{ tox_executable }} -e{{ tox_envlist }} {{ tox_extra_args }}"
39 failed_when: false
40 register: tox_output
41
42- name: Look for output
43 tox_parse_output:
44 tox_output: '{{ tox_output.stdout }}'
45 register: file_comments
46
47- name: Return file comments to Zuul
48 when: file_comments.file_comments
49 delegate_to: localhost
50 zuul_return:
51 data:
52 zuul:
53 file_comments: '{{ file_comments.file_comments }}'
54 tags:
55 # Avoid "no action detected in task" linter error
56 - skip_ansible_lint
57
58- name: Return tox status
59 fail:
60 msg: 'tox exited with return code {{ tox_output.rc }}'
61 when: tox_output.rc != 0
diff --git a/test-requirements.txt b/test-requirements.txt
index 25adbc2..d7feb56 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -2,7 +2,6 @@
2# of appearance. Changing the order has an impact on the overall integration 2# of appearance. Changing the order has an impact on the overall integration
3# process, which may cause wedges in the gate later. 3# process, which may cause wedges in the gate later.
4flake8 4flake8
5zuul
6 5
7# We need to pin the ansible version directly here; per the 6# We need to pin the ansible version directly here; per the
8# deprecation policy it should trail the version used by Zuul by 4 7# deprecation policy it should trail the version used by Zuul by 4
diff --git a/tox.ini b/tox.ini
index 3e3dbde..bcc1fd8 100644
--- a/tox.ini
+++ b/tox.ini
@@ -26,6 +26,10 @@ commands =
26 sphinx-build -E -W -d doc/build/doctrees -b html doc/source/ doc/build/html 26 sphinx-build -E -W -d doc/build/doctrees -b html doc/source/ doc/build/html
27 27
28[testenv:linters] 28[testenv:linters]
29deps =
30 # Zuul is required to supply the zuul ansible modules for ansible-lint
31 -r{toxinidir}/test-requirements.txt
32 -egit+https://git.openstack.org/openstack-infra/zuul#egg=zuul
29passenv = 33passenv =
30 # NOTE(pabelanger): if you'd like to run tox -elinters locally, you'll need 34 # NOTE(pabelanger): if you'd like to run tox -elinters locally, you'll need
31 # to export ANSIBLE_ROLES_PATH pointing to the currect repos. 35 # to export ANSIBLE_ROLES_PATH pointing to the currect repos.