Merge lp:~savoirfairelinux-openerp/lp-community-utils/branch_pep8 into lp:lp-community-utils

Status: Needs review
Proposed branch: lp:~savoirfairelinux-openerp/lp-community-utils/branch_pep8
Merge into: lp:lp-community-utils
Prerequisite: lp:~savoirfairelinux-openerp/lp-community-utils/nag_refactor
Diff against target: 118 lines (+89/-0)
2 files modified
branch_mp_pep8.py (+83/-0)
openerp-nag (+6/-0)
To merge this branch: bzr merge lp:~savoirfairelinux-openerp/lp-community-utils/branch_pep8
Reviewer Review Type Date Requested Status
Guewen Baconnier @ Camptocamp Disapprove
Holger Brunn (Therp) code review Approve
Review via email: mp+205260@code.launchpad.net

Description of the change

Added library for branching and running Flake8/PEP8 checks on changed files in MP

Added run option -t --test-pep8 argument to activate this functionality.

test-pep8 will ignore ocb-addons and ocb-server as it takes too long to branch. This is hard coded, I am willing to move it to argument list if there is demand for it.

To post a comment you must log in.
Revision history for this message
Holger Brunn (Therp) (hbrunn) wrote :

I think it's okay to ignore ocb-addons

review: Approve (code review)
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Hi,

It checks pep8 on the entire modified file, which is very likely to print way too many errors/warnings: the projects currently are far to be pep8-errors-prone and we don't expect for a merge proposal to fix all the pep8 errors in the modified files. Considering that, I don't see the value to add that in the nag, as it will output a lot of false-negative.

I would agree with something in this vein, that checks only for modified lines (but only git actually): https://github.com/edx/diff-cover

Thanks

review: Disapprove
Revision history for this message
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) wrote :

@Guewen, thank you for the link, I was wondering if such a tool existed.

Unmerged revisions

25. By Sandy Carter (http://www.savoirfairelinux.com)

Added option to branch MPs and run PEP8 on them

24. By Sandy Carter (http://www.savoirfairelinux.com)

Moved nag functionality to library and restructured some code

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'branch_mp_pep8.py'
2--- branch_mp_pep8.py 1970-01-01 00:00:00 +0000
3+++ branch_mp_pep8.py 2014-02-06 21:08:54 +0000
4@@ -0,0 +1,83 @@
5+# -*- encoding: utf-8 -*-
6+##############################################################################
7+#
8+# OpenERP, Open Source Management Solution
9+# This module copyright (C) 2013 Savoir-faire Linux
10+# (<http://www.savoirfairelinux.com>).
11+#
12+# This program is free software: you can redistribute it and/or modify
13+# it under the terms of the GNU Affero General Public License as
14+# published by the Free Software Foundation, either version 3 of the
15+# License, or (at your option) any later version.
16+#
17+# This program is distributed in the hope that it will be useful,
18+# but WITHOUT ANY WARRANTY; without even the implied warranty of
19+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+# GNU Affero General Public License for more details.
21+#
22+# You should have received a copy of the GNU Affero General Public License
23+# along with this program. If not, see <http://www.gnu.org/licenses/>.
24+#
25+##############################################################################
26+
27+import os
28+import tempfile
29+import shutil
30+
31+from bzrlib.branch import Branch
32+from bzrlib.plugin import load_plugins
33+from flake8 import main as flake8
34+from flake8 import engine
35+
36+load_plugins()
37+
38+
39+def branch_pep8(nag):
40+ exit_code = 0
41+ if nag.project_name in ['ocb-addons', 'ocb-server', 'ocb-web']:
42+ print("%s takes too long to branch, skipped..." % nag.project_name)
43+ return exit_code
44+
45+ # Find files changed to test on which to test PEP8
46+ changed_files = nag.proposal.preview_diff.diffstat.keys()
47+ changed_py_files = sorted([i for i in changed_files if i.endswith(".py")])
48+ changed_init_files = [i for i in changed_py_files if i.endswith("__init__.py")]
49+ changed_oe_files = [i for i in changed_py_files if i.endswith("__openerp__.py")]
50+
51+ # Branch MP locally
52+ mp_branch_name = nag.proposal.source_branch.bzr_identity
53+ mp_branch = Branch.open(mp_branch_name)
54+ previousDir = os.getcwd()
55+ branch_dir = tempfile.mkdtemp()
56+ os.chdir(branch_dir)
57+ mp_branch.bzrdir.sprout(branch_dir).open_branch()
58+ try:
59+ # Create Flake8 style guides
60+ flake8_style = engine.get_style_guide(
61+ parse_argv=False, config_file=flake8.DEFAULT_CONFIG)
62+ flake8_style.options.exclude += ['__init__.py', '__openerp__.py']
63+ flake8_style.options.ignore += ('E501', )
64+ flake8_style_init = engine.get_style_guide(
65+ parse_argv=False, config_file=flake8.DEFAULT_CONFIG)
66+ flake8_style_init.options.ignore += ('E501', 'F401', )
67+ flake8_style_openerp = engine.get_style_guide(
68+ parse_argv=False, config_file=flake8.DEFAULT_CONFIG)
69+ flake8_style_openerp.options.ignore += ('E501', )
70+
71+ # Run Flake8
72+ report = flake8_style_init.check_files(paths=changed_init_files)
73+ exit_code = exit_code or flake8.print_report(report, flake8_style)
74+ report = flake8_style_openerp.check_files(paths=changed_oe_files)
75+ exit_code = exit_code or flake8.print_report(report, flake8_style)
76+ report = flake8_style.check_files(paths=changed_py_files)
77+ exit_code = exit_code or flake8.print_report(report, flake8_style)
78+
79+ except:
80+ pass
81+
82+ finally:
83+ # Cleanup
84+ os.chdir(previousDir)
85+ shutil.rmtree(branch_dir)
86+
87+ return exit_code
88
89=== modified file 'openerp-nag'
90--- openerp-nag 2014-02-06 21:08:54 +0000
91+++ openerp-nag 2014-02-06 21:08:54 +0000
92@@ -50,6 +50,7 @@
93 gen_project_nags,
94 DefaultPolicy,
95 )
96+from branch_mp_pep8 import branch_pep8
97
98 consumer_name = 'OpenERP Community Reviewers Nagging Scripts'
99
100@@ -91,6 +92,9 @@
101 group.add_argument(
102 '--production', action='store_const', const='production',
103 dest='service_root', help="Use production launchpad instance")
104+ group.add_argument(
105+ '-t', '--test-pep8', action='store_true',
106+ help="Test branch using Flake8")
107 parser.set_defaults(anonymous=True, service_root='production')
108 args = parser.parse_args()
109 if not args.project and not args.projects_file:
110@@ -134,6 +138,8 @@
111 index1=index1, age=nag.age, person=nag.person,
112 action=nag.action, subject=nag.subject,
113 project=nag.project_name))
114+ if args.test_pep8:
115+ branch_pep8(nag)
116
117
118 if __name__ == "__main__":

Subscribers

People subscribed via source and target branches