launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #17471
[Merge] lp:~wgrant/launchpad/build-find-methods into lp:launchpad
William Grant has proposed merging lp:~wgrant/launchpad/build-find-methods into lp:launchpad.
Commit message:
Move BinaryPackageBuildSet.getBySourceAndLocation to getRelevantToSourceAndLocation, making way for a less magical getBySourceAndLocation that can be used in all but one place.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~wgrant/launchpad/build-find-methods/+merge/240709
Start phasing out the overly-vague-and-magical BinaryPackageBuildSet.getBySourceAndLocation, since all but one callsite just need a direct lookup in the given Archive and DAS. The old method is now getRelevantToSourceAndLocation to scare people away, with a sensible getBySourceAndLocation in its place.
--
https://code.launchpad.net/~wgrant/launchpad/build-find-methods/+merge/240709
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wgrant/launchpad/build-find-methods into lp:launchpad.
=== modified file 'lib/lp/archiveuploader/nascentuploadfile.py'
--- lib/lp/archiveuploader/nascentuploadfile.py 2014-10-31 08:05:00 +0000
+++ lib/lp/archiveuploader/nascentuploadfile.py 2014-11-05 11:14:18 +0000
@@ -848,7 +848,7 @@
# Check if there's a suitable existing build.
build = getUtility(IBinaryPackageBuildSet).getBySourceAndLocation(
- sourcepackagerelease, self.policy.archive, dar)
+ sourcepackagerelease, self.policy.archive, dar)
if build is not None:
build.updateStatus(BuildStatus.FULLYBUILT)
self.logger.debug("Updating build for %s: %s" % (
=== modified file 'lib/lp/soyuz/doc/sourcepackagerelease-build-lookup.txt'
--- lib/lp/soyuz/doc/sourcepackagerelease-build-lookup.txt 2014-10-31 08:05:00 +0000
+++ lib/lp/soyuz/doc/sourcepackagerelease-build-lookup.txt 2014-11-05 11:14:18 +0000
@@ -7,7 +7,7 @@
IBinaryPackageBuildSet can create and look up build records.
-It provides a 'getBySourceAndLocation' method which allows the
+It provides a 'getRelevantToSourceAndLocation' method which allows the
application to lookup for BinaryPackageBuild records for
SourcePackageRelease in a given DistroArchSeries and Archive.
@@ -48,8 +48,6 @@
>>> evo_release = hoary_evo_source['1.0'].sourcepackagerelease
>>> from lp.buildmaster.enums import BuildStatus
- >>> from lp.soyuz.interfaces.binarypackagebuild import (
- ... IBinaryPackageBuildSet)
>>> evo_build_i386 = getUtility(IBinaryPackageBuildSet).new(
... evo_release, ubuntu.main_archive, hoary_i386, pocket_release,
... status=BuildStatus.FULLYBUILT)
@@ -66,14 +64,14 @@
The build record can be retrieved on hoary/i386 architecture.
>>> bpbs = getUtility(IBinaryPackageBuildSet)
- >>> test_build_i386 = bpbs.getBySourceAndLocation(
+ >>> test_build_i386 = bpbs.getRelevantToSourceAndLocation(
... evo_release, ubuntu.main_archive, hoary_i386)
>>> test_build_i386 == evo_build_i386
True
However a hoary/hppa build is not available.
- >>> test_build_hppa = bpbs.getBySourceAndLocation(
+ >>> test_build_hppa = bpbs.getRelevantToSourceAndLocation(
... evo_release, ubuntu.main_archive, hoary_hppa)
>>> print test_build_hppa
None
@@ -107,7 +105,7 @@
In practical terms it means that another build is not necessary in
this context.
- >>> breezy_autotest_build = bpbs.getBySourceAndLocation(
+ >>> breezy_autotest_build = bpbs.getRelevantToSourceAndLocation(
... evo_release, ubuntu.main_archive, breezy_autotest_i386)
>>> print breezy_autotest_build.title
i386 build of evolution 1.0 in ubuntu hoary RELEASE
@@ -116,7 +114,7 @@
== Sources with architecture-independent and specific binaries ==
Even if the source package builds an architecture-independent package,
-no Build record will be returned by getBySourceAndLocation() if
+no Build record will be returned by getRelevantToSourceAndLocation() if
arch-specific binary packages were not built (see bug #65712 for further
information).
@@ -148,7 +146,7 @@
The build record for foo in hoary/i386 was created.
- >>> test_build_i386 = bpbs.getBySourceAndLocation(
+ >>> test_build_i386 = bpbs.getRelevantToSourceAndLocation(
... foo_pub_src.sourcepackagerelease, ubuntu.main_archive, hoary_i386)
>>> print test_build_i386.title
i386 build of foo 1.0 in ubuntu hoary RELEASE
@@ -162,7 +160,7 @@
foo-bin 1.0 in hoary i386
foo-bin 1.0 in hoary hppa
- >>> test_build_hppa = bpbs.getBySourceAndLocation(
+ >>> test_build_hppa = bpbs.getRelevantToSourceAndLocation(
... foo_pub_src.sourcepackagerelease, ubuntu.main_archive, hoary_hppa)
>>> print test_build_hppa
None
@@ -181,7 +179,7 @@
No suitable build will be found for it.
- >>> test_build_i386_ppa = bpbs.getBySourceAndLocation(
+ >>> test_build_i386_ppa = bpbs.getRelevantToSourceAndLocation(
... copy.sourcepackagerelease, cprov.archive, hoary_i386)
>>> print test_build_i386_ppa
None
@@ -206,14 +204,14 @@
The copied source build lookup in the PPA returns the build created in
the PPA context, not the PRIMARY archive one.
- >>> test_build_i386_ppa = bpbs.getBySourceAndLocation(
+ >>> test_build_i386_ppa = bpbs.getRelevantToSourceAndLocation(
... copy.sourcepackagerelease, cprov.archive, hoary_i386)
>>> test_build_i386_ppa == evo_build_i386_ppa
True
As expected, the hoary/hppa build is still missing in both archives.
- >>> test_build_hppa_ppa = bpbs.getBySourceAndLocation(
+ >>> test_build_hppa_ppa = bpbs.getRelevantToSourceAndLocation(
... copy.sourcepackagerelease, cprov.archive, hoary_hppa)
>>> print test_build_hppa_ppa
None
@@ -225,12 +223,12 @@
... copy.sourcepackagerelease, cprov.archive, hoary_hppa,
... pocket_release)
- >>> test_build_hppa_ppa = bpbs.getBySourceAndLocation(
+ >>> test_build_hppa_ppa = bpbs.getRelevantToSourceAndLocation(
... copy.sourcepackagerelease, cprov.archive, hoary_hppa)
>>> print test_build_hppa_ppa.title
hppa build of evolution 1.0 in ubuntu hoary RELEASE
- >>> test_build_hppa = bpbs.getBySourceAndLocation(
+ >>> test_build_hppa = bpbs.getRelevantToSourceAndLocation(
... evo_release, ubuntu.main_archive, hoary_hppa)
>>> print test_build_hppa
None
@@ -255,7 +253,7 @@
... status=PackagePublishingStatus.PUBLISHED)
>>> foo_source_release = foo_pub_src.sourcepackagerelease
- >>> build_primary = bpbs.getBySourceAndLocation(
+ >>> build_primary = bpbs.getRelevantToSourceAndLocation(
... foo_source_release, ubuntu.main_archive, hoary_i386)
>>> print build_primary.title
@@ -281,7 +279,7 @@
bug #181736 report for previous mistakes in this area.
>>> cprov_spr = cprov_src.sourcepackagerelease
- >>> cprov_build = bpbs.getBySourceAndLocation(
+ >>> cprov_build = bpbs.getRelevantToSourceAndLocation(
... cprov_spr, cprov.archive, hoary_i386)
>>> print cprov_build.title
@@ -290,28 +288,6 @@
>>> print cprov_build.archive.displayname
Primary Archive for Ubuntu Linux
-Another possible situation is when the user wants to rebuild the
-same source published in hoary to another suite, let's say
-breezy-autotest in his PPA.
-
- >>> cprov_foo_src = cprov.archive.getPublishedSources(name=u'foo').first()
-
- >>> breezy_autotest = ubuntu.getSeries('breezy-autotest')
- >>> copy = cprov_foo_src.copyTo(
- ... breezy_autotest, pocket_release, cprov.archive)
- >>> copy.status = PackagePublishingStatus.PUBLISHED
- >>> flush_database_updates()
-
-When only the source is copied we do want to rebuild, so it's correct
-when the build lookup returns None.
-
- >>> copied_release = copy.sourcepackagerelease
- >>> breezy_autotest_i386 = breezy_autotest['i386']
- >>> copied_build_candidate = bpbs.getBySourceAndLocation(
- ... copied_release, cprov.archive, breezy_autotest_i386)
- >>> print copied_build_candidate
- None
-
It's even possible to copy source and binaries from hoary to warty
suite in Celso's PPA.
@@ -333,7 +309,7 @@
>>> copied_source_release = copied_source.sourcepackagerelease
>>> warty_i386 = warty['i386']
- >>> copied_build_candidate = bpbs.getBySourceAndLocation(
+ >>> copied_build_candidate = bpbs.getRelevantToSourceAndLocation(
... copied_source_release, cprov.archive, warty_i386)
>>> print copied_build_candidate.title
@@ -362,7 +338,7 @@
original build that happened in the primary archive.
>>> mark_spr = mark_src.sourcepackagerelease
- >>> mark_build = bpbs.getBySourceAndLocation(
+ >>> mark_build = bpbs.getRelevantToSourceAndLocation(
... mark_spr, mark.archive, hoary_i386)
>>> print mark_build.title
=== modified file 'lib/lp/soyuz/interfaces/binarypackagebuild.py'
--- lib/lp/soyuz/interfaces/binarypackagebuild.py 2014-11-03 04:32:01 +0000
+++ lib/lp/soyuz/interfaces/binarypackagebuild.py 2014-11-05 11:14:18 +0000
@@ -313,6 +313,20 @@
:param builder: An optional `IBuilder`.
"""
+ def getBySourceAndLocation(source_package_release, archive,
+ distro_arch_series):
+ """Return a build by its source, archive and architecture.
+
+ This is the natural key, and lookups don't consider copies
+ between archives, just the archive in which the build originally
+ occurred.
+
+ :param source_package_release: The `ISourcePackageRelease` that is
+ built.
+ :param archive: The `IArchive` containing the build.
+ :param distro_arch_series: The `IDistroArchSeries` built against.
+ """
+
def getBuildsForBuilder(builder_id, status=None, name=None, pocket=None,
arch_tag=None):
"""Return build records touched by a builder.
@@ -366,7 +380,7 @@
:return: a list of `IBuild` records not target to PPA archives.
"""
- def getBySourceAndLocation(sourcepackagerelease, archive,
+ def getRelevantToSourceAndLocation(sourcepackagerelease, archive,
distroarchseries):
"""Return build for the given source, archive and distroarchseries.
=== modified file 'lib/lp/soyuz/model/binarypackagebuild.py'
--- lib/lp/soyuz/model/binarypackagebuild.py 2014-11-03 14:56:43 +0000
+++ lib/lp/soyuz/model/binarypackagebuild.py 2014-11-05 11:14:18 +0000
@@ -957,6 +957,13 @@
bfj.id for bfj in build_farm_jobs))
return DecoratedResultSet(rows, pre_iter_hook=self.preloadBuildsData)
+ def getBySourceAndLocation(self, source_package_release, archive,
+ distro_arch_series):
+ return IStore(BinaryPackageBuild).find(
+ BinaryPackageBuild,
+ source_package_release=source_package_release,
+ archive=archive, distro_arch_series=distro_arch_series).one()
+
def handleOptionalParamsForBuildQueries(
self, clauses, origin, status=None, name=None, pocket=None,
arch_tag=None):
@@ -1201,8 +1208,8 @@
% [(tag, build.id) for tag, build in results])
return mapped_results
- def getBySourceAndLocation(self, sourcepackagerelease, archive,
- distroarchseries):
+ def getRelevantToSourceAndLocation(self, sourcepackagerelease, archive,
+ distroarchseries):
"""See IBinaryPackageBuildSet."""
# First we try to follow any binaries built from the given source
# in a distroarchseries with the given architecturetag and published
@@ -1433,7 +1440,7 @@
Return the just-created `IBinaryPackageBuild` record already
scored or None if a suitable build is already present.
"""
- build_candidate = self.getBySourceAndLocation(
+ build_candidate = self.getRelevantToSourceAndLocation(
sourcepackagerelease, archive, arch)
# Check DistroArchSeries database IDs because the object belongs
=== modified file 'lib/lp/soyuz/scripts/tests/test_add_missing_builds.py'
--- lib/lp/soyuz/scripts/tests/test_add_missing_builds.py 2014-10-31 08:05:00 +0000
+++ lib/lp/soyuz/scripts/tests/test_add_missing_builds.py 2014-11-05 11:14:18 +0000
@@ -137,7 +137,7 @@
code, stdout, stderr = self.runScript(args)
self.assertEqual(
code, 0,
- "The script returned with a non zero exit code: %s\n%s\n%s" % (
+ "The script returned with a non zero exit code: %s\n%s\n%s" % (
code, stdout, stderr))
# Sync database changes made in the external process.
=== modified file 'lib/lp/soyuz/tests/test_build_set.py'
--- lib/lp/soyuz/tests/test_build_set.py 2014-11-03 04:34:22 +0000
+++ lib/lp/soyuz/tests/test_build_set.py 2014-11-05 11:14:18 +0000
@@ -216,6 +216,25 @@
IBinaryPackageBuildSet).getBuildsBySourcePackageRelease([])
self.assertEquals([], builds)
+ def test_getBySourceAndLocation(self):
+ self.setUpBuilds()
+ self.assertEqual(
+ self.builds[0],
+ getUtility(IBinaryPackageBuildSet).getBySourceAndLocation(
+ self.builds[0].source_package_release, self.builds[0].archive,
+ self.builds[0].distro_arch_series))
+ self.assertEqual(
+ self.builds[1],
+ getUtility(IBinaryPackageBuildSet).getBySourceAndLocation(
+ self.builds[1].source_package_release, self.builds[1].archive,
+ self.builds[1].distro_arch_series))
+ self.assertIs(
+ None,
+ getUtility(IBinaryPackageBuildSet).getBySourceAndLocation(
+ self.builds[1].source_package_release,
+ self.factory.makeArchive(),
+ self.builds[1].distro_arch_series))
+
class BuildRecordCreationTests(TestNativePublishingBase):
"""Test the creation of build records."""
@@ -368,14 +387,14 @@
class TestGetBySourceAndLocation(TestCaseWithFactory):
- """Tests for BinaryPackageBuildSet.getBySourceAndLocation()."""
+ """Tests for BinaryPackageBuildSet.getRelevantToSourceAndLocation()."""
layer = ZopelessDatabaseLayer
def test_can_find_build_in_derived_distro_parent(self):
# If a derived distribution inherited its binaries from its
- # parent then getBySourceAndLocation() should look in the parent
- # to find the build.
+ # parent then getRelevantToSourceAndLocation() should look in
+ # the parent to find the build.
dsp = self.factory.makeDistroSeriesParent()
parent_archive = dsp.parent_series.main_archive
@@ -413,6 +432,6 @@
# Searching for the build in the derived series architecture
# should automatically pick it up from the parent.
found_build = getUtility(
- IBinaryPackageBuildSet).getBySourceAndLocation(
+ IBinaryPackageBuildSet).getRelevantToSourceAndLocation(
spr, derived_archive, das_derived)
self.assertEqual(orig_build, found_build)
Follow ups