← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~wgrant/launchpad/bug-750640 into lp:launchpad

 

William Grant has proposed merging lp:~wgrant/launchpad/bug-750640 into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #750640 in Launchpad itself: "If the source version differs from the binary version, it is not specified in the Package index for that binary"
  https://bugs.launchpad.net/launchpad/+bug/750640

For more details, see:
https://code.launchpad.net/~wgrant/launchpad/bug-750640/+merge/56276

Stanzas in apt Packages files only need to include the Source field if the details differ from the binary's. If the name differs, it should be "Source: sourcename". If the version differs, it should be "Source: sourcename (sourceversion)". NMAF always acts as if the name differs, never omitting the field nor including the version.

This branch fixes that behaviour, and adds tests.
-- 
https://code.launchpad.net/~wgrant/launchpad/bug-750640/+merge/56276
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wgrant/launchpad/bug-750640 into lp:launchpad.
=== modified file 'lib/lp/soyuz/model/publishing.py'
--- lib/lp/soyuz/model/publishing.py	2011-03-24 05:21:26 +0000
+++ lib/lp/soyuz/model/publishing.py	2011-04-05 00:22:27 +0000
@@ -1007,9 +1007,15 @@
         if bpr.essential:
             essential = 'yes'
 
+        source = None
+        if bpr.version != spr.version:
+            source = '%s (%s)' % (spr.name, spr.version)
+        elif bpr.name != spr.name:
+            source = spr.name
+
         fields = IndexStanzaFields()
         fields.append('Package', bpr.name)
-        fields.append('Source', spr.name)
+        fields.append('Source', source)
         fields.append('Priority', self.priority.title.lower())
         fields.append('Section', self.section.name)
         fields.append('Installed-Size', bpr.installedsize)

=== modified file 'lib/lp/soyuz/tests/test_publish_archive_indexes.py'
--- lib/lp/soyuz/tests/test_publish_archive_indexes.py	2010-08-21 13:54:20 +0000
+++ lib/lp/soyuz/tests/test_publish_archive_indexes.py	2011-04-05 00:22:27 +0000
@@ -13,6 +13,12 @@
 from lp.soyuz.tests.test_publishing import TestNativePublishingBase
 
 
+def get_field(stanza_fields, name):
+    for key, value in stanza_fields.fields:
+        if key == name:
+            return value
+
+
 class TestNativeArchiveIndexes(TestNativePublishingBase):
 
     def setUp(self):
@@ -240,6 +246,33 @@
              ],
             pub_binary.getIndexStanza().splitlines())
 
+    def testBinaryOmitsIdenticalSourceName(self):
+        # Binaries omit the Source field if it identical to Package.
+        pub_source = self.getPubSource(sourcename='foo')
+        pub_binary = self.getPubBinaries(
+            binaryname='foo', pub_source=pub_source)[0]
+        self.assertIs(
+            None,
+            get_field(pub_binary.buildIndexStanzaFields(), 'Source'))
+
+    def testBinaryIncludesDifferingSourceName(self):
+        # Binaries include a Source field if their name differs.
+        pub_source = self.getPubSource(sourcename='foo')
+        pub_binary = self.getPubBinaries(
+            binaryname='foo-bin', pub_source=pub_source)[0]
+        self.assertEqual(
+            u'foo',
+            get_field(pub_binary.buildIndexStanzaFields(), 'Source'))
+
+    def testBinaryIncludesDifferingSourceVersion(self):
+        # Binaries also include a Source field if their versions differ.
+        pub_source = self.getPubSource(sourcename='foo', version='666')
+        pub_binary = self.getPubBinaries(
+            binaryname='foo', version='999', pub_source=pub_source)[0]
+        self.assertEqual(
+            u'foo (666)',
+            get_field(pub_binary.buildIndexStanzaFields(), 'Source'))
+
 
 class TestNativeArchiveIndexesReparsing(TestNativePublishingBase):
     """Tests for ensuring the native archive indexes that we publish

=== modified file 'lib/lp/soyuz/tests/test_publishing.py'
--- lib/lp/soyuz/tests/test_publishing.py	2011-03-06 23:24:11 +0000
+++ lib/lp/soyuz/tests/test_publishing.py	2011-04-05 00:22:27 +0000
@@ -329,7 +329,7 @@
                     build, binaryname + '-dbgsym', filecontent, summary,
                     description, shlibdep, depends, recommends, suggests,
                     conflicts, replaces, provides, pre_depends, enhances,
-                    breaks, BinaryPackageFormat.DDEB)
+                    breaks, BinaryPackageFormat.DDEB, version=version)
                 pub_binaries += self.publishBinaryInArchive(
                     binarypackagerelease_ddeb, archive.debug_archive, status,
                     pocket, scheduleddeletiondate, dateremoved)
@@ -340,7 +340,7 @@
                 build, binaryname, filecontent, summary, description,
                 shlibdep, depends, recommends, suggests, conflicts, replaces,
                 provides, pre_depends, enhances, breaks, format,
-                binarypackagerelease_ddeb,
+                binarypackagerelease_ddeb, version=version,
                 user_defined_fields=user_defined_fields)
             pub_binaries += self.publishBinaryInArchive(
                 binarypackagerelease, archive, status, pocket,
@@ -363,7 +363,7 @@
         depends=None, recommends=None, suggests=None, conflicts=None,
         replaces=None, provides=None, pre_depends=None, enhances=None,
         breaks=None, format=BinaryPackageFormat.DEB, debug_package=None,
-        user_defined_fields=None, homepage=None):
+        user_defined_fields=None, homepage=None, version=None):
         """Return the corresponding `BinaryPackageRelease`."""
         sourcepackagerelease = build.source_package_release
         distroarchseries = build.distro_arch_series
@@ -373,8 +373,11 @@
         binarypackagename = getUtility(
             IBinaryPackageNameSet).getOrCreateByName(binaryname)
 
+        if version is None:
+            version = sourcepackagerelease.version
+
         binarypackagerelease = build.createBinaryPackageRelease(
-            version=sourcepackagerelease.version,
+            version=version,
             component=sourcepackagerelease.component,
             section=sourcepackagerelease.section,
             binarypackagename=binarypackagename,