Merge lp:~james-w/pkgme/python-dependencies into lp:pkgme

Proposed by James Westby
Status: Merged
Merged at revision: 61
Proposed branch: lp:~james-w/pkgme/python-dependencies
Merge into: lp:pkgme
Prerequisite: lp:~james-w/pkgme/clean-not-validate
Diff against target: 236 lines (+97/-11)
8 files modified
pkgme/distutils_command/pkgme_info.py (+20/-2)
pkgme/info_elements.py (+18/-0)
pkgme/package_files.py (+2/-0)
pkgme/templates/rules (+3/-0)
pkgme/tests/test_distutils_command.py (+21/-0)
pkgme/tests/test_info_elements.py (+20/-1)
pkgme/tests/test_package_files.py (+10/-7)
setup.py (+3/-1)
To merge this branch: bzr merge lp:~james-w/pkgme/python-dependencies
Reviewer Review Type Date Requested Status
Jonathan Lange Approve
pkgme committers Pending
Review via email: mp+67325@code.launchpad.net

Description of the change

Hi,

This branch adds a couple of new features to the Python backend in order to
have Build-Depends and Depends filled in correctly.

In testing this I found that pkgme's stated dependencies were incomplete, so
it fixes that too.

Thanks,

James

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

I think I follow this.

Not sure why build_depends concatenates a string rather than appending to a list and returning ', '.join(dependencies), but it's not a big deal.

Is there a way to avoid hard-coding "/usr/share/python"? I would have thought it was unnecessary after adding the extra dependencies to setup.py.

More generally, I find the 'getattr(self, method_name)()' pattern easier to follow if there's a standard prefix for those methods. (e.g. 'test_', 'cmd_', etc.) It would be churlish to ask you to change it in this branch.

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

> I think I follow this.
>
> Not sure why build_depends concatenates a string rather than appending to a
> list and returning ', '.join(dependencies), but it's not a big deal.

It's mainly that it gets a string as the input. It would still work your way
though, so I'll change it.

> Is there a way to avoid hard-coding "/usr/share/python"? I would have thought
> it was unnecessary after adding the extra dependencies to setup.py.

Actually you raise an interesting point. This isn't provided by python-debian,
it's actually part of the python packages on Debian/Ubuntu (and nowhere else I think).
That's obviously not very portable, but it was the closest thing to hand to get
this functionality.

A better solution is likely to be to re-implement that logic so that it is
portable.

Also, is /usr/share/python usually on sys.path?

> More generally, I find the 'getattr(self, method_name)()' pattern easier to
> follow if there's a standard prefix for those methods. (e.g. 'test_', 'cmd_',
> etc.) It would be churlish to ask you to change it in this branch.

It would be pretty easy to do though.

Thanks,

James

Revision history for this message
Jonathan Lange (jml) wrote :

On Fri, Jul 8, 2011 at 9:05 PM, James Westby <email address hidden> wrote:
>> I think I follow this.
>>
>> Not sure why build_depends concatenates a string rather than appending to a
>> list and returning ', '.join(dependencies), but it's not a big deal.
>
> It's mainly that it gets a string as the input. It would still work your way
> though, so I'll change it.
>

Ta.

>> Is there a way to avoid hard-coding "/usr/share/python"? I would have thought
>> it was unnecessary after adding the extra dependencies to setup.py.
>
> Actually you raise an interesting point. This isn't provided by python-debian,
> it's actually part of the python packages on Debian/Ubuntu (and nowhere else I think).
> That's obviously not very portable, but it was the closest thing to hand to get
> this functionality.
>
> A better solution is likely to be to re-implement that logic so that it is
> portable.
>

OK, that makes sense. It's probably worth adding a comment along these lines.

> Also, is /usr/share/python usually on sys.path?
>

No. Or at least, not as far as I can tell.

>> More generally, I find the 'getattr(self, method_name)()' pattern easier to
>> follow if there's a standard prefix for those methods. (e.g. 'test_', 'cmd_',
>> etc.) It would be churlish to ask you to change it in this branch.
>
> It would be pretty easy to do though.

Yeah :)

I'd be happy to do a follow-up branch for this.

jml

Revision history for this message
Jonathan Lange (jml) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'pkgme/distutils_command/pkgme_info.py'
2--- pkgme/distutils_command/pkgme_info.py 2011-04-15 17:17:04 +0000
3+++ pkgme/distutils_command/pkgme_info.py 2011-07-08 12:55:21 +0000
4@@ -3,6 +3,9 @@
5 import sys
6 import textwrap
7
8+sys.path.insert(1, "/usr/share/python")
9+from debpython import pydist
10+
11
12 class pkgme_info(Command):
13
14@@ -51,12 +54,12 @@
15 def maintainer(self):
16 if (self.distribution.get_maintainer() != 'UNKNOWN' and
17 self.distribution.get_maintainer_email() != 'UNKNOWN'):
18- return "%s <%s>"%(
19+ return "%s <%s>" % (
20 self.distribution.get_maintainer(),
21 self.distribution.get_maintainer_email())
22 elif (self.distribution.get_author() != 'UNKNOWN' and
23 self.distribution.get_author_email() != 'UNKNOWN'):
24- return "%s <%s>"%(
25+ return "%s <%s>" % (
26 self.distribution.get_author(),
27 self.distribution.get_author_email())
28 else:
29@@ -72,3 +75,18 @@
30
31 def buildsystem(self):
32 return "python_distutils"
33+
34+ def build_depends(self):
35+ basics = "python-all, python-setuptools"
36+ if getattr(self.distribution, "install_requires", None) is not None:
37+ for pkg in self.distribution.install_requires:
38+ dep = pydist.guess_dependency(pkg)
39+ if dep:
40+ basics += ", %s" % dep
41+ return basics
42+
43+ def debhelper_addons(self):
44+ return "python2"
45+
46+ def depends(self):
47+ return "${python:Depends}"
48
49=== modified file 'pkgme/info_elements.py'
50--- pkgme/info_elements.py 2011-07-08 12:55:21 +0000
51+++ pkgme/info_elements.py 2011-07-08 12:55:21 +0000
52@@ -87,6 +87,24 @@
53 name = "build_depends"
54 description = """The build dependencies of the package."""
55
56+ @classmethod
57+ def clean(cls, value):
58+ if value is None:
59+ value = "debhelper (>= 7)"
60+ # FIXME: should replace if the dependency isn't strict
61+ # enough
62+ # FIXME: check is too lax, needs to parse and compare package
63+ # names
64+ if "debhelper" not in value:
65+ value += ", debhelper (>= 7)"
66+ return value
67+
68+
69+class DebhelperAddons(InfoElement):
70+
71+ name = "debhelper_addons"
72+ description = """The debhelper addons to use."""
73+
74
75 class Architecture(InfoElement):
76
77
78=== modified file 'pkgme/package_files.py'
79--- pkgme/package_files.py 2011-05-12 21:52:36 +0000
80+++ pkgme/package_files.py 2011-07-08 12:55:21 +0000
81@@ -7,6 +7,7 @@
82 Architecture,
83 BuildDepends,
84 Buildsystem,
85+ DebhelperAddons,
86 Depends,
87 Description,
88 Homepage,
89@@ -100,6 +101,7 @@
90
91 elements = [
92 Buildsystem,
93+ DebhelperAddons,
94 ]
95
96 filename = "rules"
97
98=== modified file 'pkgme/templates/rules'
99--- pkgme/templates/rules 2010-11-06 03:53:23 +0000
100+++ pkgme/templates/rules 2011-07-08 12:55:21 +0000
101@@ -5,4 +5,7 @@
102 #if $buildsystem
103 --buildsystem=${buildsystem} #slurp
104 #end if
105+#if $debhelper_addons
106+--with=${debhelper_addons} #slurp
107+#end if
108
109
110=== modified file 'pkgme/tests/test_distutils_command.py'
111--- pkgme/tests/test_distutils_command.py 2010-11-17 21:35:30 +0000
112+++ pkgme/tests/test_distutils_command.py 2011-07-08 12:55:21 +0000
113@@ -115,3 +115,24 @@
114 version = "123"
115 cmd = self.get_cmd_with_metadata(dict(version=version))
116 self.assertEqual(version, cmd.version())
117+
118+ def test_build_depends_includes_python_all(self):
119+ cmd = self.get_cmd_with_metadata({})
120+ self.assertIn("python-all", cmd.build_depends())
121+
122+ def test_build_depends_includes_python_setuptools(self):
123+ cmd = self.get_cmd_with_metadata({})
124+ self.assertIn("python-setuptools", cmd.build_depends())
125+
126+ def test_build_depends_examines_install_requires(self):
127+ cmd = self.get_cmd_with_metadata({})
128+ cmd.distribution.install_requires = ["foo"]
129+ self.assertIn("python-foo", cmd.build_depends())
130+
131+ def test_debhelper_addons_is_python2(self):
132+ cmd = self.get_cmd_with_metadata({})
133+ self.assertEqual("python2", cmd.debhelper_addons())
134+
135+ def test_depends_is_python_depends(self):
136+ cmd = self.get_cmd_with_metadata({})
137+ self.assertEqual("${python:Depends}", cmd.depends())
138
139=== modified file 'pkgme/tests/test_info_elements.py'
140--- pkgme/tests/test_info_elements.py 2011-07-08 12:55:21 +0000
141+++ pkgme/tests/test_info_elements.py 2011-07-08 12:55:21 +0000
142@@ -1,6 +1,10 @@
143 from testtools import TestCase
144
145-from pkgme.info_elements import InfoElement, MissingInfoError
146+from pkgme.info_elements import (
147+ BuildDepends,
148+ InfoElement,
149+ MissingInfoError,
150+ )
151 from pkgme.project_info import DictInfo
152
153
154@@ -80,3 +84,18 @@
155 original_value = self.getUniqueString()
156 project_info = DictInfo({TestElement.name: original_value})
157 self.assertEqual(original_value, TestElement.get_value(project_info))
158+
159+
160+class BuildDependsTestCase(TestCase):
161+
162+ def test_clean_inserts_debhelper(self):
163+ value = BuildDepends.clean(None)
164+ self.assertEqual("debhelper (>= 7)", value)
165+
166+ def test_clean_adds_debhelper(self):
167+ value = BuildDepends.clean("python")
168+ self.assertEqual("python, debhelper (>= 7)", value)
169+
170+ def test_clean_doesnt_add_debhelper_if_present(self):
171+ value = BuildDepends.clean("python, debhelper")
172+ self.assertEqual("python, debhelper", value)
173
174=== modified file 'pkgme/tests/test_package_files.py'
175--- pkgme/tests/test_package_files.py 2011-06-15 18:54:40 +0000
176+++ pkgme/tests/test_package_files.py 2011-07-08 12:55:21 +0000
177@@ -8,6 +8,7 @@
178 Architecture,
179 BuildDepends,
180 Buildsystem,
181+ DebhelperAddons,
182 Depends,
183 Description,
184 Homepage,
185@@ -181,6 +182,14 @@
186 "%%:\n\tdh $@ --buildsystem=%s \n" % buildsystem,
187 package_file.get_contents())
188
189+ def test_content_with_debhelper_addons(self):
190+ debhelper_addons = self.getUniqueString()
191+ args = {DebhelperAddons.name: debhelper_addons}
192+ package_file = self.get_object(args)
193+ self.assertIn(
194+ "%%:\n\tdh $@ --with=%s \n" % debhelper_addons,
195+ package_file.get_contents())
196+
197 def test_overwrite(self):
198 package_file = self.get_object()
199 self.assertEqual(True, package_file.overwrite)
200@@ -328,19 +337,13 @@
201
202 def test_get_contents_sets_build_depends(self):
203 build_depends = self.getUniqueString()
204+ build_depends = BuildDepends.clean(build_depends)
205 args = {BuildDepends.name: build_depends}
206 package_file = self.get_object(args)
207 self.assertThat(
208 package_file.get_contents(),
209 ControlSourceStanzaHasField("Build-Depends", build_depends))
210
211- def test_get_contents_without_build_depends(self):
212- args = {BuildDepends.name: None}
213- package_file = self.get_object(args)
214- self.assertThat(
215- package_file.get_contents(),
216- ControlSourceStanzaDoesntHaveField("Build-Depends"))
217-
218 def test_get_contents_sets_architecture(self):
219 architecture = self.getUniqueString()
220 args = {Architecture.name: architecture}
221
222=== modified file 'setup.py'
223--- setup.py 2011-07-08 12:55:21 +0000
224+++ setup.py 2011-07-08 12:55:21 +0000
225@@ -64,8 +64,10 @@
226 test_suite='pkgme.tests',
227 install_requires = [
228 'argparse',
229- 'cheetah',
230+ 'Cheetah',
231+ 'python_debian',
232 'fixtures',
233+ 'Markdown', # "Required" by Cheetah, but only a suggests in the packaging.
234 'testtools',
235 ],
236 entry_points = {

Subscribers

People subscribed via source and target branches

to all changes: