Merge lp:~dpniel/ubuntu-autopilot-tests/add_pyflakes_pep8 into lp:ubuntu-autopilot-tests

Proposed by Dan Chapman 
Status: Merged
Approved by: Dan Chapman 
Approved revision: 65
Merged at revision: 65
Proposed branch: lp:~dpniel/ubuntu-autopilot-tests/add_pyflakes_pep8
Merge into: lp:ubuntu-autopilot-tests
Diff against target: 114 lines (+94/-1)
3 files modified
checkformat/run-pep8 (+6/-0)
checkformat/run-pyflakes (+74/-0)
debian/rules (+14/-1)
To merge this branch: bzr merge lp:~dpniel/ubuntu-autopilot-tests/add_pyflakes_pep8
Reviewer Review Type Date Requested Status
Nicholas Skaggs (community) Approve
Review via email: mp+206927@code.launchpad.net

Description of the change

Adds pyflakes and pep8 checks to debian rules for use before mergeing. Lets get some standards involved :-D

To post a comment you must log in.
Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

So this is intended to be manually run as part of reviews; and folks submitting merges can run beforehand to check for themselves?

Revision history for this message
Dan Chapman  (dpniel) wrote :

Yes indeed, i noticed jackson did all the pep-8 errors a while back but pyflakes were left untouched. So it made me think we could do with something we could manually run when doing merges. I'm not sure having a 'tests' directory in the root seems a bit out of place and confusing for someone looking at the branch. What's your thoughts?

Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

What if we simply renamed the folder to specify what it is? Something like checkformat or ? I suppose anything but tests. If so, I'm happy to merge this. Also should we just run flake8?

Revision history for this message
Nicholas Skaggs (nskaggs) :
review: Needs Information
Revision history for this message
Dan Chapman  (dpniel) wrote :

I suppose we could just run flake8 but I have no idea how to configure it, for if we need to exclude certain pyflake errors etc. I'll go take a look through the manual see how it all works

65. By Dan Chapman 

Changed folder name as suggested

Revision history for this message
Dan Chapman  (dpniel) wrote :

folder named changed so good to go now :-)

Revision history for this message
Nicholas Skaggs (nskaggs) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'checkformat'
2=== added file 'checkformat/pyflakes.exclude'
3=== added file 'checkformat/run-pep8'
4--- checkformat/run-pep8 1970-01-01 00:00:00 +0000
5+++ checkformat/run-pep8 2014-02-27 16:29:56 +0000
6@@ -0,0 +1,6 @@
7+#! /bin/sh
8+#
9+# Test PEP-8 conformance.
10+
11+pep8 ubuntu_autopilot_tests \
12+ xubuntu_autopilot_tests
13
14=== added file 'checkformat/run-pyflakes'
15--- checkformat/run-pyflakes 1970-01-01 00:00:00 +0000
16+++ checkformat/run-pyflakes 2014-02-27 16:29:56 +0000
17@@ -0,0 +1,74 @@
18+#!/usr/bin/env python
19+#
20+# Utility script to run pyflakes with the modules we care about and
21+# exclude errors we know to be fine.
22+
23+# Taken from Review Board, MIT license
24+
25+import os
26+import re
27+import subprocess
28+import sys
29+
30+
31+module_exclusions = [
32+ 'debian',
33+
34+]
35+
36+whitelist = [
37+
38+ 'tests/run-pyflakes',
39+]
40+
41+
42+def scan_for_modules():
43+ return [entry
44+ for entry in os.listdir(os.getcwd())
45+ if ((os.path.isdir(entry) or entry.endswith(".py")) and
46+ entry not in module_exclusions)] + whitelist
47+
48+
49+def main():
50+ cur_dir = os.path.dirname(__file__)
51+ os.chdir(os.path.join(cur_dir, ".."))
52+ modules = sys.argv[1:]
53+
54+ if not modules:
55+ # The user didn't specify anything specific. Scan for modules.
56+ modules = scan_for_modules()
57+
58+ os.environ['PYFLAKES_NODOCTEST'] = '1'
59+ p = subprocess.Popen(['pyflakes3'] + modules,
60+ stderr=subprocess.PIPE,
61+ stdout=subprocess.PIPE,
62+ close_fds=True, universal_newlines=True)
63+
64+ contents = p.communicate()[0].splitlines()
65+
66+ # Read in the exclusions file
67+ exclusions = {}
68+ with open(os.path.join(cur_dir, "pyflakes.exclude"), "r") as fp:
69+ for line in fp.readlines():
70+ if not line.startswith("#"):
71+ exclusions[line.rstrip()] = 1
72+
73+ # Now filter thin
74+ error = False
75+ for line in contents:
76+ if line.startswith('#'):
77+ continue
78+
79+ line = line.rstrip()
80+ test_line = re.sub(r':[0-9]+:', r':*:', line, 1)
81+ test_line = re.sub(r'line [0-9]+', r'line *', test_line)
82+
83+ if test_line not in exclusions:
84+ print line
85+ error = True
86+ if error:
87+ sys.exit(1)
88+
89+
90+if __name__ == "__main__":
91+ main()
92
93=== modified file 'debian/rules'
94--- debian/rules 2013-10-28 19:29:54 +0000
95+++ debian/rules 2014-02-27 16:29:56 +0000
96@@ -10,4 +10,17 @@
97 #export DH_VERBOSE=1
98
99 %:
100- dh $@ --with python2
101+ dh $@ --with python3
102+
103+check:
104+ # Sanity-check before upload.
105+ find -name debian -prune -o -name \*.py -print | xargs py3compile
106+ find -type f \( -name \*.pyc -o -name \*.pyo \) -print0 | xargs -0r rm -f
107+ find -name __pycache__ -print0 | xargs -0r rm -rf
108+ # Check the syntax of any shell scripts.
109+ set -e; for x in $$(find -type f \! -name \*.po \! -name \*.pot -print0 | xargs -0 file -i | grep "text/x-shellscript" | cut -d':' -f1); do \
110+ sh -n $$x; \
111+ done
112+ # Check the syntax of any Python scripts.
113+ ./checkformat/run-pyflakes
114+ ./checkformat/run-pep8

Subscribers

People subscribed via source and target branches