Merge lp:~jml/pkgme/tweaks into lp:pkgme

Proposed by Jonathan Lange
Status: Merged
Approved by: James Westby
Approved revision: 67
Merged at revision: 63
Proposed branch: lp:~jml/pkgme/tweaks
Merge into: lp:pkgme
Diff against target: 62 lines (+8/-9)
3 files modified
pkgme/backend.py (+6/-7)
pkgme/backends/python/all_info (+1/-1)
pkgme/tests/test_backend.py (+1/-1)
To merge this branch: bzr merge lp:~jml/pkgme/tweaks
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+67729@code.launchpad.net

Description of the change

Bunch of tweaks to remove pyflakes and to use slightly more modern (and probably faster) approaches where needed.

 * Use key, not cmp (changes algorithmic complexity from N**2 to max(N, O(sort(N)))
 * Use try_imports to import things based on availability
 * Don't assign to unused variables

To post a comment you must log in.
Revision history for this message
Jonathan Lange (jml) wrote :

Oh also, changed the Python backend to use json.load rather than json.loads. All that means is that we let json worry about how much of the stream to store in memory, rather than loading it all in first.

lp:~jml/pkgme/tweaks updated
67. By Jonathan Lange

Don't read stdin ourselves. Let json do it.

Revision history for this message
James Westby (james-w) wrote :

Looks good to me, thanks.

Please go ahead and land.

Thanks,

James

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'pkgme/backend.py'
2--- pkgme/backend.py 2011-07-01 01:41:06 +0000
3+++ pkgme/backend.py 2011-07-12 16:49:04 +0000
4@@ -1,11 +1,10 @@
5+from operator import attrgetter
6 import os
7 import sys
8
9-try:
10- from sysconfig import get_platform
11-except ImportError:
12- # Python < 2.7
13- from distutils.util import get_platform
14+from testtools import try_imports
15+
16+get_platform = try_imports(['sysconfig.get_platform', 'distutils.util.get_platform'])
17
18 from pkgme.project_info import (
19 MultipleExternalHelpersInfo,
20@@ -115,7 +114,7 @@
21 def want(self, path):
22 try:
23 out = run_script(self.basepath, self.WANT_SCRIPT_NAME, path)
24- except ScriptMissing, e:
25+ except ScriptMissing:
26 raise AssertionError(
27 "Backend %s (%s) has no '%s' script"
28 % (self.name, self.basepath, self.WANT_SCRIPT_NAME))
29@@ -186,7 +185,7 @@
30 raise NoBackend()
31 backend = eligble[0]
32 if len(eligble) > 1:
33- eligble.sort(cmp=lambda x,y: cmp(x.name, y.name))
34+ eligble.sort(key=attrgetter('name'))
35 backend = eligble[0]
36 return backend.get_info(path)
37
38
39=== modified file 'pkgme/backends/python/all_info'
40--- pkgme/backends/python/all_info 2010-12-13 01:34:21 +0000
41+++ pkgme/backends/python/all_info 2011-07-12 16:49:04 +0000
42@@ -9,7 +9,7 @@
43
44
45 if __name__ == '__main__':
46- wanted = json.loads(sys.stdin.read())
47+ wanted = json.load(sys.stdin)
48 info_arg = "--pkgmeinfo=" + ",".join(wanted)
49 tempdir = tempfile.mkdtemp()
50 try:
51
52=== modified file 'pkgme/tests/test_backend.py'
53--- pkgme/tests/test_backend.py 2010-12-13 01:34:21 +0000
54+++ pkgme/tests/test_backend.py 2011-07-12 16:49:04 +0000
55@@ -204,7 +204,7 @@
56 self.assertEqual([], loader.load())
57
58 def test_ignores_missing_dirs(self):
59- tempdir = self.useFixture(TempdirFixture())
60+ self.useFixture(TempdirFixture())
61 loader = ExternalHelpersBackendLoader([self.getUniqueString()])
62 self.assertEqual([], loader.load())
63

Subscribers

People subscribed via source and target branches