Merge lp:~vila/uci-engine/fix-run-python into lp:uci-engine

Proposed by Vincent Ladeuil
Status: Merged
Approved by: Vincent Ladeuil
Approved revision: 842
Merged at revision: 856
Proposed branch: lp:~vila/uci-engine/fix-run-python
Merge into: lp:uci-engine
Diff against target: 85 lines (+25/-8)
3 files modified
charms/precise/chroot-builder/hooks/hooks.py (+1/-1)
charms/precise/system-image-server/hooks/hooks.py (+1/-1)
run-python (+23/-6)
To merge this branch: bzr merge lp:~vila/uci-engine/fix-run-python
Reviewer Review Type Date Requested Status
Evan (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+238261@code.launchpad.net

Commit message

Fix more bare exit() (instead of sys.exit()) calls.

Description of the change

I ran into another exit() call (instead of sys.exit()) in run-python so I fixed it.

I then found a couple of other call sites and fixed them too.

See https://code.launchpad.net/~vila/uci-engine/1314179-sys-exit/+merge/217593 for details.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:842
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/1585/
Executed test runs:

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/1585/rebuild

review: Approve (continuous-integration)
Revision history for this message
Evan (ev) wrote :

I think this is a good opportunity to start adding some static analysis checks, both for clear errors like this and style adherence.

Would you mind adding a small test that does something like:

grep '\(^\| \)exit(' * -rsI && echo "The exit constant should not be used outside the interactive interpreter. Please use sys.exit(). https://docs.python.org/2/library/constants.html#exit"

Otherwise looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charms/precise/chroot-builder/hooks/hooks.py'
2--- charms/precise/chroot-builder/hooks/hooks.py 2014-10-07 10:04:01 +0000
3+++ charms/precise/chroot-builder/hooks/hooks.py 2014-10-14 09:09:16 +0000
4@@ -192,4 +192,4 @@
5
6
7 if __name__ == '__main__':
8- exit(main())
9+ sys.exit(main())
10
11=== modified file 'charms/precise/system-image-server/hooks/hooks.py'
12--- charms/precise/system-image-server/hooks/hooks.py 2014-05-29 17:00:29 +0000
13+++ charms/precise/system-image-server/hooks/hooks.py 2014-10-14 09:09:16 +0000
14@@ -153,4 +153,4 @@
15 start(charmconfig)
16
17 if __name__ == '__main__':
18- exit(main())
19+ sys.exit(main())
20
21=== modified file 'run-python'
22--- run-python 2014-10-07 10:04:01 +0000
23+++ run-python 2014-10-14 09:09:16 +0000
24@@ -1,14 +1,31 @@
25 #!/usr/bin/env python
26+# Ubuntu CI Engine
27+# Copyright 2014 Canonical Ltd.
28+
29+# This program is free software: you can redistribute it and/or modify it
30+# under the terms of the GNU Affero General Public License version 3, as
31+# published by the Free Software Foundation.
32+
33+# This program is distributed in the hope that it will be useful, but
34+# WITHOUT ANY WARRANTY; without even the implied warranties of
35+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
36+# PURPOSE. See the GNU Affero General Public License for more details.
37+
38+# You should have received a copy of the GNU Affero General Public License
39+# along with this program. If not, see <http://www.gnu.org/licenses/>.
40
41 import os
42 import sys
43
44
45+HERE = os.path.abspath(os.path.dirname(__file__))
46+
47+
48 def _usage():
49 print('Usage: %s script [arg [arg...]]' % sys.argv[0])
50 print('Sets up a PYTHONPATH with our ci-utils so that python scripts '
51 'can be launched properly')
52- exit(0)
53+ sys.exit(0)
54
55
56 def _parse_args(args):
57@@ -21,7 +38,7 @@
58 '''return the path to the component of the script'''
59 script = os.path.abspath(script)
60 if basedir not in script:
61- exit('ERROR: scripts must reside in source tree')
62+ sys.exit('ERROR: scripts must reside in source tree')
63 script = script[len(basedir) + 1:]
64 return script.split('/')[0]
65
66@@ -29,9 +46,8 @@
67 def main(args):
68 script, args = _parse_args(args)
69
70- here = os.path.abspath(os.path.dirname(__file__))
71- ci_utils = os.path.join(here, 'ci-utils')
72- comp = _component_path(here, script)
73+ ci_utils = os.path.join(HERE, 'ci-utils')
74+ comp = _component_path(HERE, script)
75
76 python_path = os.environ.get('PYTHONPATH')
77 if python_path:
78@@ -42,5 +58,6 @@
79
80 os.execv(script, args)
81
82+
83 if __name__ == '__main__':
84- exit(main(sys.argv[1:]))
85+ sys.exit(main(sys.argv[1:]))

Subscribers

People subscribed via source and target branches