Merge lp:~lool/phablet-tools/static-checkers into lp:phablet-tools

Proposed by Loïc Minier
Status: Merged
Approved by: Sergio Schvezov
Approved revision: 196
Merged at revision: 183
Proposed branch: lp:~lool/phablet-tools/static-checkers
Merge into: lp:phablet-tools
Diff against target: 293 lines (+114/-40)
7 files modified
debian/control (+2/-0)
phablet-demo-setup (+6/-4)
phablet-dev-bootstrap (+12/-12)
phablet-network (+2/-2)
phabletutils/environment.py (+0/-4)
setup.py (+25/-18)
tests/test_static_checkers.py (+67/-0)
To merge this branch: bzr merge lp:~lool/phablet-tools/static-checkers
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Sergio Schvezov Approve
Review via email: mp+184432@code.launchpad.net

Commit message

Run pyflakes and pep8 static checkers in test suite and at build time; fix a pyflakes warning.

Description of the change

Run pyflakes and pep8 static checkers in test suite and at build time; fix a pyflakes warning.

Did a simple run against mako with files cached locally:
./phablet-flash ubuntu-system --channel daily-proposed --no-backup -d mako

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Sergio Schvezov (sergiusens) wrote :

Thanks

review: Approve
186. By Loïc Minier

Only run setup() when setup.py is run as a script; this allows importing it.

187. By Loïc Minier

Split out lists of bash, python and shell scripts as to import them from
testsuite.

188. By Loïc Minier

Fix typo spotted by checkbashisms.

189. By Loïc Minier

Run phablet-network with /bin/sh instead of /bin/bash; code is actually
sh-compatible and that's one less type of scripts. Did a test run with /bin/sh
and ran checkbashisms against it.

190. By Loïc Minier

Fix copy-paste typo that prevented pyflakes from running (duplicated test
name).

191. By Loïc Minier

Run pyflakes and pep8 against python scripts (these don't end in .py and aren't
seen by pyflakes / pep8); exclude some scripts from test_pep8 as these need to
be fixed first.

192. By Loïc Minier

PEP8 fixes.

193. By Loïc Minier

Test shell scripts syntax with sh -n.

194. By Loïc Minier

Factor some code in new get_output() function.

195. By Loïc Minier

Sort alphabetically.

196. By Loïc Minier

Run checkbashisms if available; don't build-dep on it though as devscripts is
fairly large.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Loïc Minier (lool) wrote :

I've pushed some more revs to include the scripts and some other
bonuses; would you mind taking another look?

On Sat, Sep 07, 2013, Sergio Schvezov wrote:
> Review: Approve
>
> Thanks
> --
> https://code.launchpad.net/~lool/phablet-tools/static-checkers/+merge/184432
> You are the owner of lp:~lool/phablet-tools/static-checkers.

--
Loïc Minier

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2013-09-04 19:57:35 +0000
3+++ debian/control 2013-09-07 14:22:18 +0000
4@@ -3,6 +3,8 @@
5 Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
6 XSBC-Original-Maintainer: Sergio Schvezov <sergio.schvezov@canonical.com>
7 Build-Depends: debhelper (>= 9.0.0),
8+ pep8,
9+ pyflakes,
10 python (>= 2.7),
11 python-configobj,
12 python-lzma,
13
14=== modified file 'phablet-demo-setup'
15--- phablet-demo-setup 2013-05-29 14:39:31 +0000
16+++ phablet-demo-setup 2013-09-07 14:22:18 +0000
17@@ -30,6 +30,7 @@
18 apt-get update
19 '''
20
21+
22 def parse_arguments():
23 '''Parses arguments passed in to script.'''
24 parser = argparse.ArgumentParser(
25@@ -64,7 +65,7 @@
26
27 def setup_fake_pictures(script):
28 script.write('tar -C /home/phablet/Pictures/ --strip-components=1 -xzf '
29- '/usr/share/demo-assets/pictures.tgz\n')
30+ '/usr/share/demo-assets/pictures.tgz\n')
31 script.write('chown -R phablet:phablet /home/phablet/Pictures\n')
32 return script
33
34@@ -102,15 +103,16 @@
35 script = setup_fake_conversations(script)
36 if not args.disable_fake_messages:
37 log.info('Setting up for demo message notifications')
38- script.write('/usr/bin/apt-get install -y indicators-client-examples\n')
39+ script.write(
40+ '/usr/bin/apt-get install -y indicators-client-examples\n')
41 if not args.disable_fake_pictures:
42 log.info('Setting up for demo pictures')
43 script.write('/usr/bin/apt-get install -y demo-assets-pictures\n')
44 script = setup_fake_pictures(script)
45- script_file = tempfile.NamedTemporaryFile(delete=False)
46+ script_file = tempfile.NamedTemporaryFile(delete=False)
47 with script_file as f:
48 f.write(script.getvalue())
49- script.close()
50+ script.close()
51 provision_device(args.serial, script_file.name)
52
53
54
55=== modified file 'phablet-dev-bootstrap'
56--- phablet-dev-bootstrap 2013-08-09 15:08:06 +0000
57+++ phablet-dev-bootstrap 2013-09-07 14:22:18 +0000
58@@ -39,7 +39,7 @@
59
60
61 class StringSplitAction(argparse.Action):
62- def __call__(self, parser, namespace, values, option_string=None):
63+ def __call__(self, parser, namespace, values, option_string=None):
64 setattr(namespace, self.dest, values.split(','))
65
66
67@@ -56,16 +56,16 @@
68 try:
69 if os.path.isfile(target_directory):
70 raise OSError('%s is not a directory' %
71- target_directory)
72+ target_directory)
73 elif not os.path.isdir(target_directory):
74 log.debug('Creating sync directory %s' % target_directory)
75 os.mkdir(target_directory)
76 elif os.listdir(target_directory):
77 raise OSError('%s is not empty and not using -c' %
78- target_directory)
79+ target_directory)
80 except OSError as e:
81 if not e.message:
82- log.error('Cannot setup environment in %s' %
83+ log.error('Cannot setup environment in %s' %
84 target_directory)
85 else:
86 log.error(e.message)
87@@ -86,7 +86,7 @@
88 subprocess.check_call(['repo',
89 'sync',
90 '-j%s' % jobs]
91- )
92+ )
93 except subprocess.CalledProcessError:
94 log.error('Error while trying to sync repository')
95 exit(1)
96@@ -126,28 +126,29 @@
97 help='''Comma separated list of devices to Setup
98 such as maguro, manta, mako, grouper''',
99 action=StringSplitAction,
100- )
101+ )
102 parser.add_argument('-j',
103 '--jobs',
104 dest='jobs',
105 help='''Ammount of sync jobs''',
106 default='1',
107- )
108+ )
109 parser.add_argument('-c',
110 '--continue',
111 dest='continue_sync',
112 action='store_true',
113 help='''Continue a previously started sync''',
114 default=False,
115- )
116+ )
117 parser.add_argument('-r',
118 '--reference',
119- help='''Use another dev environment as reference for git''',
120+ help='Use another dev environment as reference for '
121+ 'git',
122 default='',
123- )
124+ )
125 parser.add_argument('target_directory',
126 help='Target directory for sources',
127- )
128+ )
129 return parser.parse_args()
130
131
132@@ -165,4 +166,3 @@
133 if __name__ == "__main__":
134 args = parse_arguments()
135 main(args)
136-
137
138=== modified file 'phablet-network'
139--- phablet-network 2013-08-26 18:52:46 +0000
140+++ phablet-network 2013-09-07 14:22:18 +0000
141@@ -1,4 +1,4 @@
142-#!/bin/bash
143+#!/bin/sh
144 # This program is free software: you can redistribute it and/or modify it
145 # under the terms of the the GNU General Public License version 3, as
146 # published by the Free Software Foundation.
147@@ -87,7 +87,7 @@
148
149 find_active_network() {
150 wireless_adapter="$(nmcli -t -f device,type dev | egrep wireless | cut -d: -f1)"
151- network_active_uuid="$(nmcli -t -f name,uuid,devices,vpn con status | grep $wireless_adapter | egrep ":no$"| cut -d: -f2)"
152+ network_active_uuid="$(nmcli -t -f name,uuid,devices,vpn con status | grep $wireless_adapter | egrep ':no$'| cut -d: -f2)"
153 network_file=$(sudo grep "$network_active_uuid" $NETWORK_MANAGER/* | grep uuid | cut -d: -f1)
154
155 if [ -z "$network_active_uuid" ]
156
157=== modified file 'phabletutils/environment.py'
158--- phabletutils/environment.py 2013-09-06 05:33:58 +0000
159+++ phabletutils/environment.py 2013-09-07 14:22:18 +0000
160@@ -156,10 +156,6 @@
161 settings.download_dir, args.project))
162 uri = settings.system_image_uri
163 files, command_part = ubuntuimage.get_files(download_dir, uri, json)
164- recovery = cdimage.get_file(file_key='recovery_img',
165- series=args.series,
166- download_dir=download_dir,
167- device=device)
168 return projects.UbuntuTouchSystem(
169 file_list=files,
170 command_part=command_part,
171
172=== modified file 'setup.py'
173--- setup.py 2013-08-26 18:52:46 +0000
174+++ setup.py 2013-09-07 14:22:18 +0000
175@@ -3,21 +3,28 @@
176 from setuptools import find_packages
177 from setuptools import setup
178
179-setup(
180- name='phablet-tools',
181- version='0.1',
182- description='Scripts to deploy Ubuntu on mobile devices',
183- author='Sergio Schvezov',
184- author_email='sergio.schvezov@canonical.com',
185- license='GPLv3',
186- packages=find_packages(exclude=("tests",)),
187- scripts=['phablet-flash',
188- 'phablet-click-test-setup',
189- 'phablet-demo-setup',
190- 'phablet-network',
191- 'phablet-dev-bootstrap',
192- 'phablet-test-run',
193- 'repo',
194- ],
195- test_suite='tests',
196-)
197+PYTHON_SCRIPTS = [
198+ 'phablet-click-test-setup',
199+ 'phablet-demo-setup',
200+ 'phablet-dev-bootstrap',
201+ 'phablet-flash',
202+ 'repo',
203+ ]
204+
205+SH_SCRIPTS = [
206+ 'phablet-network',
207+ 'phablet-test-run',
208+ ]
209+
210+if __name__ == "__main__":
211+ setup(
212+ name='phablet-tools',
213+ version='0.1',
214+ description='Scripts to deploy Ubuntu on mobile devices',
215+ author='Sergio Schvezov',
216+ author_email='sergio.schvezov@canonical.com',
217+ license='GPLv3',
218+ packages=find_packages(exclude=("tests",)),
219+ scripts=PYTHON_SCRIPTS + SH_SCRIPTS,
220+ test_suite='tests',
221+ )
222
223=== added file 'tests/test_static_checkers.py'
224--- tests/test_static_checkers.py 1970-01-01 00:00:00 +0000
225+++ tests/test_static_checkers.py 2013-09-07 14:22:18 +0000
226@@ -0,0 +1,67 @@
227+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
228+# Copyright (C) 2013 Canonical Ltd.
229+# Author: Loïc Minier <loic.minier@ubuntu.com>
230+
231+# This program is free software: you can redistribute it and/or modify
232+# it under the terms of the GNU General Public License as published by
233+# the Free Software Foundation; version 3 of the License.
234+#
235+# This program is distributed in the hope that it will be useful,
236+# but WITHOUT ANY WARRANTY; without even the implied warranty of
237+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
238+# GNU General Public License for more details.
239+#
240+# You should have received a copy of the GNU General Public License
241+# along with this program. If not, see <http://www.gnu.org/licenses/>.
242+
243+"""Static checkers against source files."""
244+
245+import subprocess
246+import testtools
247+
248+from setup import PYTHON_SCRIPTS, SH_SCRIPTS
249+
250+
251+# external script which is only pyflakes-clean, not pep8-clean
252+PEP8_EXCLUDES = ["repo", ]
253+
254+
255+def has_command(command):
256+ """Returns whether a command is in the PATH or not."""
257+ returncode = subprocess.call(['which', command],
258+ stdout=open('/dev/null', 'w'))
259+ return returncode == 0
260+
261+
262+def get_output(command):
263+ proc = subprocess.Popen(command,
264+ stdout=subprocess.PIPE,
265+ stderr=subprocess.PIPE)
266+ return proc.communicate()
267+
268+
269+class TestStaticCheckers(testtools.TestCase):
270+ @testtools.skipUnless(has_command("checkbashisms"),
271+ "checkbashisms not found")
272+ def test_bashisms(self):
273+ (stdout, stderr) = get_output(['checkbashisms', ] + SH_SCRIPTS)
274+ self.assertEquals('', stdout)
275+ self.assertEquals('', stderr)
276+
277+ @testtools.skipUnless(has_command("pep8"), "pep8 not found")
278+ def test_pep8(self):
279+ scripts = [p for p in PYTHON_SCRIPTS if p not in PEP8_EXCLUDES]
280+ (stdout, stderr) = get_output(['pep8', '.'] + scripts)
281+ self.assertEquals('', stdout)
282+ self.assertEquals('', stderr)
283+
284+ @testtools.skipUnless(has_command("pyflakes"), "pyflakes not found")
285+ def test_pyflakes(self):
286+ (stdout, stderr) = get_output(['pyflakes', '.'] + PYTHON_SCRIPTS)
287+ self.assertEquals('', stdout)
288+ self.assertEquals('', stderr)
289+
290+ def test_sh_syntax(self):
291+ (stdout, stderr) = get_output(['sh', '-n'] + SH_SCRIPTS)
292+ self.assertEquals('', stdout)
293+ self.assertEquals('', stderr)

Subscribers

People subscribed via source and target branches