Merge lp:~elopio/unity8/flake8-precommit into lp:unity8

Proposed by Leo Arias
Status: Work in progress
Proposed branch: lp:~elopio/unity8/flake8-precommit
Merge into: lp:unity8
Prerequisite: lp:~elopio/unity8/flake8
Diff against target: 70 lines (+53/-0)
3 files modified
.bazaar/Makefile (+1/-0)
.bazaar/plugins/run_static_tests.py (+47/-0)
run_python_static_tests.sh (+5/-0)
To merge this branch: bzr merge lp:~elopio/unity8/flake8-precommit
Reviewer Review Type Date Requested Status
Michael Zanetti (community) Needs Information
Michał Sawicz Needs Fixing
PS Jenkins bot (community) continuous-integration Needs Fixing
Review via email: mp+224852@code.launchpad.net

Commit message

Added a precommit hook for static tests.

Description of the change

 * Are there any related MPs required for this MP to build/function as expected? Please list.

The prerequisite branch, https://code.launchpad.net/~elopio/unity8/flake8

 * Did you perform an exploratory manual test run of your code change and any related functionality?

Yes. Tried with the hook, without the hook, with the run script, without the run script, with errors and without errors.

 * Did you make sure that your branch does not contain spurious tags?

Yes.

 * If you changed the packaging (debian), did you subscribe the ubuntu-unity team to this MP?

No packaging changes.

 * If you changed the UI, has there been a design review?

No UI changes.

To post a comment you must log in.
lp:~elopio/unity8/flake8-precommit updated
981. By Leo Arias

Cleaned the call.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Michał Sawicz (saviq) wrote :

Hmm we actually wanted a common "pre_push.sh" or so, that would run:
- cmake --build builddir --target test
- flake
- generate and check if qmltypes are updated

Ideally (but tricky without comparing to trunk, so maybe optional...)
- check whether any pngs are being added/modified and remind to use optipng on them

So, please rename the script to be generic, add the cmake check to it, and drop the original hook.

review: Needs Fixing
Revision history for this message
Michael Zanetti (mzanetti) wrote :

Do we really need 2 hooks?

I guess it can be a single bzr hook that calls multiple scripts/commands.

afaics the pyflake hook would prevent me from committing if something is not ok. For the other hook we intentionally only print a warning to the user and allow to uncommit, fix, recommit (reusing the commit message) or ignore the hook if pushing to a temporary branch. I'd prefer this one to behave the same, basically just including the python checks (and whatever Michal listed above) in the existing hook.

review: Needs Information
Revision history for this message
Michał Sawicz (saviq) wrote :

Yes agreed, the hook should warn, not block.

Unmerged revisions

981. By Leo Arias

Cleaned the call.

980. By Leo Arias

Improved the hook, added a check for mccabe complexity.

979. By Leo Arias

Added the static tests pre-commit hook.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bazaar/Makefile'
2--- .bazaar/Makefile 2013-06-05 22:03:08 +0000
3+++ .bazaar/Makefile 2014-06-27 15:11:16 +0000
4@@ -4,3 +4,4 @@
5
6 uninstall:
7 rm ~/.bazaar/plugins/makecheck_unity_phablet.py*
8+ rm ~/.bazaar/plugins/run_static_tests.py*
9
10=== added file '.bazaar/plugins/run_static_tests.py'
11--- .bazaar/plugins/run_static_tests.py 1970-01-01 00:00:00 +0000
12+++ .bazaar/plugins/run_static_tests.py 2014-06-27 15:11:16 +0000
13@@ -0,0 +1,47 @@
14+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
15+#
16+# Unity Static Pre-commit Tests
17+# Copyright (C) 2014 Canonical
18+#
19+# This program is free software: you can redistribute it and/or modify
20+# it under the terms of the GNU General Public License as published by
21+# the Free Software Foundation, either version 3 of the License, or
22+# (at your option) any later version.
23+#
24+# This program is distributed in the hope that it will be useful,
25+# but WITHOUT ANY WARRANTY; without even the implied warranty of
26+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+# GNU General Public License for more details.
28+#
29+# You should have received a copy of the GNU General Public License
30+# along with this program. If not, see <http://www.gnu.org/licenses/>.
31+#
32+
33+import os
34+import subprocess
35+
36+from bzrlib import branch, errors
37+
38+
39+def run_static_tests(
40+ local_branch, master_branch, old_revision_number, old_revision_id,
41+ future_revision_number, future_revision_id, tree_delta, future_tree):
42+ """Run static tests on the source code."""
43+ _run_python_static_tests()
44+
45+
46+def _run_python_static_tests():
47+ """Run static tests on python code."""
48+ if os.path.exists('run_python_static_tests.sh'):
49+ print('Running the python static tests.')
50+ try:
51+ subprocess.check_call(
52+ os.path.abspath('run_python_static_tests.sh'))
53+ except subprocess.CalledProcessError:
54+ raise errors.BzrError('Python static tests failed.')
55+ else:
56+ print('The python static tests will not be run.')
57+
58+
59+branch.Branch.hooks.install_named_hook(
60+ 'pre_commit', run_static_tests, 'Run static tests before commit')
61
62=== added file 'run_python_static_tests.sh'
63--- run_python_static_tests.sh 1970-01-01 00:00:00 +0000
64+++ run_python_static_tests.sh 2014-06-27 15:11:16 +0000
65@@ -0,0 +1,5 @@
66+#!/bin/sh
67+
68+# Flake8 checks code style using pep8, static erros using pyflakes and code
69+# complexity using mccabe.
70+flake8 . --max-complexity 10

Subscribers

People subscribed via source and target branches