Merge lp:~jml/pkgme/split-write-packaging into lp:pkgme

Proposed by Jonathan Lange
Status: Merged
Approved by: Jonathan Lange
Approved revision: 143
Merged at revision: 136
Proposed branch: lp:~jml/pkgme/split-write-packaging
Merge into: lp:pkgme
Diff against target: 222 lines (+110/-25)
4 files modified
buildout.cfg (+1/-0)
pkgme/__init__.py (+32/-3)
pkgme/tests/test_write_packaging.py (+75/-21)
versions.cfg (+2/-1)
To merge this branch: bzr merge lp:~jml/pkgme/split-write-packaging
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+121666@code.launchpad.net

Commit message

Split write_packaging so that there's a way to get information.

Description of the change

Reasonably simple thing to let pkgme-service get the info that pkgme finds.

It just blows up ``write_packaging`` into its constituent parts. I considered making ``write_packaging`` return info. I didn't. I don't know why.

Switched to use treeshape to make the tests a bit more declarative.

get_packaging_info really ought to include the want reasons & scores from rejected backends, but I think that ought to be a simple change.

Thanks,
jml

To post a comment you must log in.
lp:~jml/pkgme/split-write-packaging updated
142. By Jonathan Lange

PEP 8

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

67 + # Do these imports in the function to reduce the side-effects of importing
68 + # pkgme. This avoids the need for setup.py of the tool being packaged
69 + # from having to find all the imported dependencies when running the
70 + # extension pkgme_info setup.py command.

There's no imports in that function. Maybe it was supposed to be in the previous function?

Thanks,

James

review: Approve
lp:~jml/pkgme/split-write-packaging updated
143. By Jonathan Lange

Move the comment

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'buildout.cfg'
2--- buildout.cfg 2012-08-24 19:50:26 +0000
3+++ buildout.cfg 2012-08-29 16:20:27 +0000
4@@ -32,5 +32,6 @@
5 # python-subunit is needed for those that use testr
6 eggs = pkgme
7 python-subunit
8+ treeshape
9 include-site-packages = false
10 interpreter = py
11
12=== modified file 'pkgme/__init__.py'
13--- pkgme/__init__.py 2012-08-28 10:57:30 +0000
14+++ pkgme/__init__.py 2012-08-29 16:20:27 +0000
15@@ -21,25 +21,54 @@
16 __metaclass__ = type
17 __all__ = [
18 '__version__',
19+ 'get_packaging_info',
20 'write_packaging',
21+ 'write_packaging_info',
22 ]
23
24
25 __version__ = '0.3.1'
26
27
28-def write_packaging(path, distribution=None, allowed_backend_names=None):
29+
30+def get_packaging_info(path, distribution=None, allowed_backend_names=None):
31+ """Get the packaging information for 'path'.
32+
33+ :param path: Path to the thing being packaged.
34+ :param distribution: Name of the distribution being packaged for.
35+ :param allowed_backend_names: List of allowed backend names. If not,
36+ provided, all backends are allowed.
37+ :return: A ``ProjectInfo`` object.
38+ """
39 # Do these imports in the function to reduce the side-effects of importing
40 # pkgme. This avoids the need for setup.py of the tool being packaged
41 # from having to find all the imported dependencies when running the
42 # extension pkgme_info setup.py command.
43 from pkgme.backend import get_info_for
44- from pkgme.package_files import default_package_file_group
45- from pkgme.write import Writer
46 info = get_info_for(path, allowed_backend_names=allowed_backend_names)
47 if distribution:
48 from pkgme.info_elements import Distribution
49 from pkgme.project_info import DictInfo, FallbackInfo
50 info = FallbackInfo(DictInfo({Distribution.name: distribution}), info)
51+ return info
52+
53+
54+def write_packaging_info(path, info):
55+ """Write packaging information for 'path'.
56+
57+ :param path: Path to write the packaging information to.
58+ :param info: A ``ProjectInfo`` containing everything we need to package it.
59+ """
60+ # Do these imports in the function to reduce the side-effects of importing
61+ # pkgme. This avoids the need for setup.py of the tool being packaged
62+ # from having to find all the imported dependencies when running the
63+ # extension pkgme_info setup.py command.
64+ from pkgme.package_files import default_package_file_group
65+ from pkgme.write import Writer
66 files = default_package_file_group.get_files(info)
67 Writer().write(files, path)
68+
69+
70+def write_packaging(path, distribution=None, allowed_backend_names=None):
71+ info = get_packaging_info(path, distribution, allowed_backend_names)
72+ write_packaging_info(path, info)
73
74=== modified file 'pkgme/tests/test_write_packaging.py'
75--- pkgme/tests/test_write_packaging.py 2012-02-04 18:24:41 +0000
76+++ pkgme/tests/test_write_packaging.py 2012-08-29 16:20:27 +0000
77@@ -1,8 +1,14 @@
78 import os
79
80+from fixtures import TempDir
81 from testtools import TestCase
82+from treeshape import HasFileTree
83
84-from pkgme import write_packaging
85+from pkgme import (
86+ get_packaging_info,
87+ write_packaging,
88+ write_packaging_info,
89+ )
90 from pkgme.backend import StaticBackend
91 from pkgme.info_elements import (
92 Architecture,
93@@ -16,21 +22,18 @@
94 from pkgme.testing import (
95 ControlSourceStanzaHasField,
96 StaticLoaderFixture,
97- TempdirFixture,
98 )
99
100
101+def ControlHasSourceName(name):
102+ control_path = os.path.join(DEBIAN_DIR, Control.filename)
103+ return HasFileTree(
104+ {control_path:
105+ {'content': ControlSourceStanzaHasField("Source", name)}})
106+
107+
108 class WritePackagingTests(TestCase):
109
110- def assert_control_has_source_name(self, name, tempdir):
111- control_path = os.path.join(
112- tempdir.path, DEBIAN_DIR, Control.filename)
113- with open(control_path) as f:
114- control_contents = f.read()
115- self.assertThat(
116- control_contents,
117- ControlSourceStanzaHasField("Source", name))
118-
119 def make_info(self, name):
120 info = DictInfo(
121 {
122@@ -45,25 +48,76 @@
123 def test_write_packaging(self):
124 name = PackageName.clean(self.getUniqueString())
125 info = self.make_info(name)
126- tempdir = self.useFixture(TempdirFixture())
127+ tempdir = self.useFixture(TempDir()).path
128 backend = StaticBackend(
129- self.getUniqueString(), 10, info, expected_path=tempdir.path)
130+ self.getUniqueString(), 10, info, expected_path=tempdir)
131 self.useFixture(StaticLoaderFixture([backend]))
132- write_packaging(tempdir.path)
133- self.assert_control_has_source_name(name, tempdir)
134+ write_packaging(tempdir)
135+ self.assertThat(tempdir, ControlHasSourceName(name))
136
137 def test_write_packaging_passes_allowed_backend_names(self):
138 name = PackageName.clean(self.getUniqueString())
139- other_name = name+"WRONG"
140+ other_name = name + "WRONG"
141 info1 = self.make_info(name)
142 info2 = self.make_info(other_name)
143- tempdir = self.useFixture(TempdirFixture())
144+ tempdir = self.useFixture(TempDir()).path
145 backend1 = StaticBackend(
146- self.getUniqueString(), 10, info1, expected_path=tempdir.path)
147+ self.getUniqueString(), 10, info1, expected_path=tempdir)
148 backend2 = StaticBackend(
149 self.getUniqueString(), 20, info2)
150 self.useFixture(StaticLoaderFixture(
151 [backend1, backend2]))
152- write_packaging(tempdir.path,
153- allowed_backend_names=[backend1.name])
154- self.assert_control_has_source_name(name, tempdir)
155+ write_packaging(tempdir, allowed_backend_names=[backend1.name])
156+ self.assertThat(tempdir, ControlHasSourceName(name))
157+
158+
159+class TestWritePackagingInformation(TestCase):
160+
161+ def test_writes_packaging(self):
162+ path = self.useFixture(TempDir()).path
163+ package_name = PackageName.clean(self.getUniqueString())
164+ info = DictInfo(
165+ {
166+ PackageName.name: package_name,
167+ Maintainer.name: self.getUniqueString(),
168+ Architecture.name: "all",
169+ Description.name: self.getUniqueString(),
170+ Version.name: "1",
171+ })
172+ write_packaging_info(path, info)
173+ self.assertThat(path, ControlHasSourceName(package_name))
174+
175+
176+class TestGetPackagingInfo(TestCase):
177+
178+ def make_info(self):
179+ return DictInfo(
180+ {
181+ PackageName.name: PackageName.clean(self.getUniqueString()),
182+ Maintainer.name: self.getUniqueString(),
183+ Architecture.name: "all",
184+ Description.name: self.getUniqueString(),
185+ Version.name: "1",
186+ })
187+
188+ def test_get_packaging_info(self):
189+ info = self.make_info()
190+ tempdir = self.useFixture(TempDir()).path
191+ backend = StaticBackend(
192+ self.getUniqueString(), 10, info, expected_path=tempdir)
193+ self.useFixture(StaticLoaderFixture([backend]))
194+ found = get_packaging_info(tempdir)
195+ self.assertEqual(found, info)
196+
197+ def test_allowed_backend_names(self):
198+ info1 = self.make_info()
199+ info2 = self.make_info()
200+ tempdir = self.useFixture(TempDir()).path
201+ backend1 = StaticBackend(
202+ self.getUniqueString(), 10, info1, expected_path=tempdir)
203+ backend2 = StaticBackend(
204+ self.getUniqueString(), 20, info2)
205+ self.useFixture(StaticLoaderFixture([backend1, backend2]))
206+ found = get_packaging_info(
207+ tempdir, allowed_backend_names=[backend1.name])
208+ self.assertEqual(found, info1)
209
210=== modified file 'versions.cfg'
211--- versions.cfg 2012-08-24 19:50:26 +0000
212+++ versions.cfg 2012-08-29 16:20:27 +0000
213@@ -25,7 +25,8 @@
214 python-subunit = 0.0.8
215 simplejson = 2.6.1
216 testresources = 0.2.5
217-testtools = 0.9.15
218+testtools = 0.9.16
219+treeshape = 0.2.0
220 wadllib = 1.3.1
221 wsgi-intercept = 0.5.1
222 z3c.recipe.scripts = 1.0.1

Subscribers

People subscribed via source and target branches