← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~wgrant/launchpad/kill-spr-circular into lp:launchpad

 

William Grant has proposed merging lp:~wgrant/launchpad/kill-spr-circular into lp:launchpad with lp:~wgrant/launchpad/kill-spr-productrelease as a prerequisite.

Requested reviews:
  William Grant (wgrant): code

For more details, see:
https://code.launchpad.net/~wgrant/launchpad/kill-spr-circular/+merge/113541

Rearrange various Soyuz-related circular imports to move closer to a layered model rather than an intertangled web of doom.
-- 
https://code.launchpad.net/~wgrant/launchpad/kill-spr-circular/+merge/113541
Your team Launchpad code reviewers is subscribed to branch lp:launchpad.
=== modified file 'lib/lp/registry/model/distroseries.py'
--- lib/lp/registry/model/distroseries.py	2012-07-05 10:46:33 +0000
+++ lib/lp/registry/model/distroseries.py	2012-07-05 10:46:34 +0000
@@ -169,10 +169,6 @@
     )
 from lp.soyuz.model.section import Section
 from lp.soyuz.model.sourcepackagerelease import SourcePackageRelease
-from lp.soyuz.scripts.initialize_distroseries import (
-    InitializationError,
-    InitializeDistroSeries,
-    )
 from lp.translations.enums import LanguagePackType
 from lp.translations.model.distroseries_translations_copy import (
     copy_active_translations,
@@ -1623,6 +1619,10 @@
                                 overlay_pockets=(),
                                 overlay_components=()):
         """See `IDistroSeries`."""
+        from lp.soyuz.scripts.initialize_distroseries import (
+            InitializationError,
+            InitializeDistroSeries,
+            )
         if self.isDerivedSeries():
             raise DerivationError(
                 "DistroSeries %s already has parent series." % self.name)

=== modified file 'lib/lp/soyuz/adapters/overrides.py'
--- lib/lp/soyuz/adapters/overrides.py	2012-05-14 01:29:38 +0000
+++ lib/lp/soyuz/adapters/overrides.py	2012-07-05 10:46:34 +0000
@@ -38,6 +38,11 @@
 from lp.soyuz.model.binarypackagename import BinaryPackageName
 from lp.soyuz.model.binarypackagerelease import BinaryPackageRelease
 from lp.soyuz.model.component import Component
+from lp.soyuz.model.distroarchseries import DistroArchSeries
+from lp.soyuz.model.publishing import (
+    BinaryPackagePublishingHistory,
+    SourcePackagePublishingHistory,
+    )
 from lp.soyuz.model.section import Section
 
 
@@ -190,8 +195,6 @@
 
     def calculateSourceOverrides(self, archive, distroseries, pocket, spns,
                                  source_component=None):
-        # Avoid circular imports.
-        from lp.soyuz.model.publishing import SourcePackagePublishingHistory
 
         def eager_load(rows):
             bulk.load(Component, (row[1] for row in rows))
@@ -224,10 +227,6 @@
 
     def calculateBinaryOverrides(self, archive, distroseries, pocket,
                                  binaries):
-        # Avoid circular imports.
-        from lp.soyuz.model.distroarchseries import DistroArchSeries
-        from lp.soyuz.model.publishing import BinaryPackagePublishingHistory
-
         def eager_load(rows):
             bulk.load(Component, (row[2] for row in rows))
             bulk.load(Section, (row[3] for row in rows))
@@ -381,8 +380,6 @@
 
 
 def make_package_condition(archive, das, bpn):
-    # Avoid circular imports.
-    from lp.soyuz.model.publishing import BinaryPackagePublishingHistory
     return And(
         BinaryPackagePublishingHistory.archiveID == archive.id,
         BinaryPackagePublishingHistory.distroarchseriesID == das.id,
@@ -390,9 +387,6 @@
 
 
 def id_resolver(lookups):
-    # Avoid circular imports.
-    from lp.soyuz.model.publishing import SourcePackagePublishingHistory
-
     def _resolve(row):
         store = IStore(SourcePackagePublishingHistory)
         return tuple(

=== modified file 'lib/lp/soyuz/browser/queue.py'
--- lib/lp/soyuz/browser/queue.py	2012-07-03 17:09:00 +0000
+++ lib/lp/soyuz/browser/queue.py	2012-07-05 10:46:34 +0000
@@ -20,6 +20,7 @@
     NotFoundError,
     UnexpectedFormData,
     )
+from lp.registry.model.person import Person
 from lp.services.database.bulk import (
     load_referencing,
     load_related,
@@ -47,6 +48,10 @@
     QueueInconsistentStateError,
     )
 from lp.soyuz.interfaces.section import ISectionSet
+from lp.soyuz.model.archive import Archive
+from lp.soyuz.model.packagecopyjob import PackageCopyJob
+from lp.soyuz.model.queue import PackageUploadSource
+from lp.soyuz.model.sourcepackagerelease import SourcePackageRelease
 
 
 QUEUE_SIZE = 30
@@ -193,11 +198,6 @@
 
     def loadPackageCopyJobs(self, uploads):
         """Batch-load `PackageCopyJob`s and related information."""
-        # Avoid circular imports.
-        from lp.registry.model.person import Person
-        from lp.soyuz.model.archive import Archive
-        from lp.soyuz.model.packagecopyjob import PackageCopyJob
-
         package_copy_jobs = load_related(
             PackageCopyJob, uploads, ['package_copy_job_id'])
         load_related(Archive, package_copy_jobs, ['source_archive_id'])
@@ -211,10 +211,6 @@
         CompletePackageUpload.  This avoids many additional SQL queries
         in the +queue template.
         """
-        # Avoid circular imports.
-        from lp.soyuz.model.queue import PackageUploadSource
-        from lp.soyuz.model.sourcepackagerelease import SourcePackageRelease
-
         uploads = list(self.batchnav.currentBatch())
 
         if len(uploads) == 0:

=== modified file 'lib/lp/soyuz/interfaces/archivesubscriber.py'
--- lib/lp/soyuz/interfaces/archivesubscriber.py	2012-04-18 18:51:11 +0000
+++ lib/lp/soyuz/interfaces/archivesubscriber.py	2012-07-05 10:46:34 +0000
@@ -32,6 +32,7 @@
     )
 
 from lp import _
+from lp.app.interfaces.launchpad import IPrivacy
 from lp.registry.interfaces.person import IPerson
 from lp.services.fields import PersonChoice
 from lp.soyuz.enums import ArchiveSubscriberStatus
@@ -182,5 +183,4 @@
 
 def pas_to_privacy(pas):
     """Converts a PersonalArchiveSubscription to privacy"""
-    from lp.app.interfaces.launchpad import IPrivacy
     return IPrivacy(pas.archive)

=== modified file 'lib/lp/soyuz/model/archive.py'
--- lib/lp/soyuz/model/archive.py	2012-06-28 12:30:47 +0000
+++ lib/lp/soyuz/model/archive.py	2012-07-05 10:46:34 +0000
@@ -175,7 +175,6 @@
     )
 from lp.soyuz.model.archiveauthtoken import ArchiveAuthToken
 from lp.soyuz.model.archivedependency import ArchiveDependency
-from lp.soyuz.model.archivesubscriber import ArchiveSubscriber
 from lp.soyuz.model.binarypackagebuild import BinaryPackageBuild
 from lp.soyuz.model.binarypackagename import BinaryPackageName
 from lp.soyuz.model.binarypackagerelease import (
@@ -1813,6 +1812,7 @@
     def newSubscription(self, subscriber, registrant, date_expires=None,
                         description=None):
         """See `IArchive`."""
+        from lp.soyuz.model.archivesubscriber import ArchiveSubscriber
 
         # We do not currently allow subscriptions for non-private archives:
         if self.private is False:

=== modified file 'lib/lp/soyuz/model/archivesubscriber.py'
--- lib/lp/soyuz/model/archivesubscriber.py	2012-02-28 04:24:19 +0000
+++ lib/lp/soyuz/model/archivesubscriber.py	2012-07-05 10:46:34 +0000
@@ -31,6 +31,7 @@
 from zope.interface import implements
 
 from lp.registry.interfaces.person import validate_person
+from lp.registry.model.person import Person
 from lp.registry.model.teammembership import TeamParticipation
 from lp.services.database.constants import UTC_NOW
 from lp.services.database.decoratedresultset import DecoratedResultSet
@@ -93,9 +94,6 @@
 
     def getNonActiveSubscribers(self):
         """See `IArchiveSubscriber`."""
-        # Imported here because of circular imports.
-        from lp.registry.model.person import Person
-
         store = Store.of(self)
         if self.subscriber.is_team:
 
@@ -210,10 +208,6 @@
 
     def getByArchive(self, archive, current_only=True):
         """See `IArchiveSubscriberSet`."""
-        # Grab the extra Storm expressions, for this query,
-        # depending on the params:
-        # avoid circular imports.
-        from lp.registry.model.person import Person
         extra_exprs = self._getExprsForSubscriptionQueries(
             archive, current_only)
 

=== modified file 'lib/lp/soyuz/model/binarypackagebuild.py'
--- lib/lp/soyuz/model/binarypackagebuild.py	2012-06-29 08:40:05 +0000
+++ lib/lp/soyuz/model/binarypackagebuild.py	2012-07-05 10:46:34 +0000
@@ -90,12 +90,10 @@
     IBinaryPackageBuildSet,
     UnparsableDependencies,
     )
-from lp.soyuz.interfaces.publishing import active_publishing_status
 from lp.soyuz.model.binarypackagename import BinaryPackageName
 from lp.soyuz.model.binarypackagerelease import BinaryPackageRelease
 from lp.soyuz.model.buildpackagejob import BuildPackageJob
 from lp.soyuz.model.files import BinaryPackageFile
-from lp.soyuz.model.publishing import SourcePackagePublishingHistory
 from lp.soyuz.model.queue import (
     PackageUpload,
     PackageUploadBuild,
@@ -131,6 +129,7 @@
         return results.one()
 
     def _getLatestPublication(self):
+        from lp.soyuz.model.publishing import SourcePackagePublishingHistory
         store = Store.of(self)
         results = store.find(
             SourcePackagePublishingHistory,
@@ -154,6 +153,7 @@
     @property
     def current_source_publication(self):
         """See `IBuild`."""
+        from lp.soyuz.interfaces.publishing import active_publishing_status
         latest_publication = self._getLatestPublication()
         if (latest_publication is not None and
             latest_publication.status in active_publishing_status):

=== modified file 'lib/lp/soyuz/model/distroarchseries.py'
--- lib/lp/soyuz/model/distroarchseries.py	2012-01-10 09:55:24 +0000
+++ lib/lp/soyuz/model/distroarchseries.py	2012-07-05 10:46:34 +0000
@@ -54,11 +54,7 @@
 from lp.soyuz.interfaces.publishing import ICanPublishPackages
 from lp.soyuz.model.binarypackagename import BinaryPackageName
 from lp.soyuz.model.binarypackagerelease import BinaryPackageRelease
-from lp.soyuz.model.distroarchseriesbinarypackage import (
-    DistroArchSeriesBinaryPackage,
-    )
 from lp.soyuz.model.processor import Processor
-from lp.soyuz.model.publishing import BinaryPackagePublishingHistory
 
 
 class DistroArchSeries(SQLBase):
@@ -119,6 +115,8 @@
 
     def updatePackageCount(self):
         """See `IDistroArchSeries`."""
+        from lp.soyuz.model.publishing import BinaryPackagePublishingHistory
+
         query = """
             BinaryPackagePublishingHistory.distroarchseries = %s AND
             BinaryPackagePublishingHistory.archive IN %s AND
@@ -174,6 +172,8 @@
 
     def searchBinaryPackages(self, text):
         """See `IDistroArchSeries`."""
+        from lp.soyuz.model.publishing import BinaryPackagePublishingHistory
+
         store = getUtility(IStoreSelector).get(MAIN_STORE, SLAVE_FLAVOR)
         origin = [
             BinaryPackageRelease,
@@ -242,6 +242,9 @@
 
     def getBinaryPackage(self, name):
         """See `IDistroArchSeries`."""
+        from lp.soyuz.model.distroarchseriesbinarypackage import (
+            DistroArchSeriesBinaryPackage,
+            )
         if not IBinaryPackageName.providedBy(name):
             try:
                 name = BinaryPackageName.byName(name)
@@ -273,6 +276,8 @@
     def getReleasedPackages(self, binary_name, pocket=None,
                             include_pending=False, archive=None):
         """See IDistroArchSeries."""
+        from lp.soyuz.model.publishing import BinaryPackagePublishingHistory
+
         queries = []
 
         if not IBinaryPackageName.providedBy(binary_name):
@@ -307,6 +312,8 @@
 
     def getPendingPublications(self, archive, pocket, is_careful):
         """See `ICanPublishPackages`."""
+        from lp.soyuz.model.publishing import BinaryPackagePublishingHistory
+
         queries = [
             "distroarchseries = %s AND archive = %s"
             % sqlvalues(self, archive)

=== modified file 'lib/lp/soyuz/model/publishing.py'
--- lib/lp/soyuz/model/publishing.py	2012-07-05 10:46:33 +0000
+++ lib/lp/soyuz/model/publishing.py	2012-07-05 10:46:34 +0000
@@ -105,16 +105,19 @@
     )
 from lp.soyuz.interfaces.queue import QueueInconsistentStateError
 from lp.soyuz.interfaces.section import ISectionSet
+from lp.soyuz.model.binarypackagebuild import BinaryPackageBuild
 from lp.soyuz.model.binarypackagename import BinaryPackageName
 from lp.soyuz.model.binarypackagerelease import (
     BinaryPackageRelease,
     BinaryPackageReleaseDownloadCount,
     )
+from lp.soyuz.model.distroarchseries import DistroArchSeries
 from lp.soyuz.model.files import (
     BinaryPackageFile,
     SourcePackageReleaseFile,
     )
 from lp.soyuz.model.packagediff import PackageDiff
+from lp.soyuz.model.sourcepackagerelease import SourcePackageRelease
 from lp.soyuz.pas import determineArchitecturesToBuild
 
 
@@ -501,8 +504,6 @@
 
     def getBuiltBinaries(self, want_files=False):
         """See `ISourcePackagePublishingHistory`."""
-        from lp.soyuz.model.binarypackagebuild import BinaryPackageBuild
-        from lp.soyuz.model.distroarchseries import DistroArchSeries
         binary_publications = list(Store.of(self).find(
             BinaryPackagePublishingHistory,
             BinaryPackagePublishingHistory.binarypackagereleaseID ==
@@ -1566,13 +1567,6 @@
     def getBuildsForSourceIds(self, source_publication_ids, archive=None,
                               build_states=None, need_build_farm_job=False):
         """See `IPublishingSet`."""
-        # Import Build and DistroArchSeries locally to avoid circular
-        # imports, since that Build uses SourcePackagePublishingHistory
-        # and DistroArchSeries uses BinaryPackagePublishingHistory.
-        from lp.soyuz.model.binarypackagebuild import BinaryPackageBuild
-        from lp.soyuz.model.distroarchseries import (
-            DistroArchSeries)
-
         # If an archive was passed in as a parameter, add an extra expression
         # to filter by archive:
         extra_exprs = []
@@ -1696,14 +1690,6 @@
     def _getSourceBinaryJoinForSources(self, source_publication_ids,
         active_binaries_only=True):
         """Return the join linking sources with binaries."""
-        # Import Build and DistroArchSeries locally
-        # to avoid circular imports, since Build uses
-        # SourcePackagePublishingHistory, BinaryPackageRelease uses Build
-        # and DistroArchSeries uses BinaryPackagePublishingHistory.
-        from lp.soyuz.model.binarypackagebuild import BinaryPackageBuild
-        from lp.soyuz.model.distroarchseries import (
-            DistroArchSeries)
-
         join = [
             SourcePackagePublishingHistory.sourcepackagereleaseID ==
                 BinaryPackageBuild.source_package_release_id,
@@ -1735,14 +1721,6 @@
                                        one_or_more_source_publications,
                                        build_states=None):
         """See `IPublishingSet`."""
-        # Import Build, BinaryPackageRelease and DistroArchSeries locally
-        # to avoid circular imports, since Build uses
-        # SourcePackagePublishingHistory and DistroArchSeries uses
-        # BinaryPackagePublishingHistory.
-        from lp.soyuz.model.binarypackagebuild import BinaryPackageBuild
-        from lp.soyuz.model.distroarchseries import (
-            DistroArchSeries)
-
         # The default build state that we'll search for is FULLYBUILT
         if build_states is None:
             build_states = [BuildStatus.FULLYBUILT]
@@ -1775,10 +1753,6 @@
 
     def getBinaryFilesForSources(self, one_or_more_source_publications):
         """See `IPublishingSet`."""
-        # Import Build locally to avoid circular imports, since that
-        # Build already imports SourcePackagePublishingHistory.
-        from lp.soyuz.model.binarypackagebuild import BinaryPackageBuild
-
         source_publication_ids = self._extractIDs(
             one_or_more_source_publications)
 
@@ -1827,9 +1801,6 @@
     def getBinaryPublicationsForSources(self,
                                         one_or_more_source_publications):
         """See `IPublishingSet`."""
-        # Avoid circular imports.
-        from lp.soyuz.model.distroarchseries import DistroArchSeries
-
         source_publication_ids = self._extractIDs(
             one_or_more_source_publications)
 
@@ -1878,8 +1849,6 @@
         # Import PackageUpload and PackageUploadSource locally
         # to avoid circular imports, since PackageUpload uses
         # SourcePackagePublishingHistory.
-        from lp.soyuz.model.sourcepackagerelease import (
-            SourcePackageRelease)
         from lp.soyuz.model.queue import (
             PackageUpload, PackageUploadSource)
 
@@ -2096,8 +2065,6 @@
     # This may need tuning: its possible that grouping by the common
     # archives may yield better efficiency: the current code is
     # just a direct push-down of the previous in-python lookup to SQL.
-    from lp.soyuz.model.sourcepackagerelease import SourcePackageRelease
-
     series_clauses = []
     for context, package_names in context_sourcepackagenames.items():
         clause = And(

=== modified file 'lib/lp/soyuz/model/queue.py'
--- lib/lp/soyuz/model/queue.py	2012-07-04 13:02:32 +0000
+++ lib/lp/soyuz/model/queue.py	2012-07-05 10:46:34 +0000
@@ -74,7 +74,6 @@
     get_property_cache,
     )
 from lp.soyuz.adapters.notification import notify
-from lp.soyuz.adapters.overrides import SourceOverride
 from lp.soyuz.enums import (
     PackageUploadCustomFormat,
     PackageUploadStatus,
@@ -109,7 +108,6 @@
 from lp.soyuz.model.binarypackagename import BinaryPackageName
 from lp.soyuz.model.binarypackagerelease import BinaryPackageRelease
 from lp.soyuz.pas import BuildDaemonPackagesArchSpecific
-from lp.soyuz.scripts.processaccepted import close_bugs_for_queue_item
 
 # There are imports below in PackageUploadCustom for various bits
 # of the archivepublisher which cause circular import errors if they
@@ -453,6 +451,8 @@
 
         It does not close bugs for PPA sources.
         """
+        from lp.soyuz.scripts.processaccepted import close_bugs_for_queue_item
+
         if self.isPPA():
             debug(logger, "Not closing bugs for PPA source.")
             return
@@ -562,6 +562,8 @@
         This is the normal case, for uploads that are not delayed and are not
         attached to package copy jobs.
         """
+        from lp.soyuz.scripts.processaccepted import close_bugs_for_queue_item
+
         assert self.package_copy_job is None, (
             "This method is not for copy-job uploads.")
         assert not self.is_delayed_copy, (
@@ -1021,6 +1023,8 @@
     def _overrideSyncSource(self, new_component, new_section,
                             allowed_components):
         """Override source on the upload's `PackageCopyJob`, if any."""
+        from lp.soyuz.adapters.overrides import SourceOverride
+
         if self.package_copy_job is None:
             return False
 

=== modified file 'lib/lp/soyuz/model/sourcepackagerelease.py'
--- lib/lp/soyuz/model/sourcepackagerelease.py	2012-07-05 10:46:33 +0000
+++ lib/lp/soyuz/model/sourcepackagerelease.py	2012-07-05 10:46:34 +0000
@@ -69,7 +69,6 @@
 from lp.soyuz.model.binarypackagebuild import BinaryPackageBuild
 from lp.soyuz.model.files import SourcePackageReleaseFile
 from lp.soyuz.model.packagediff import PackageDiff
-from lp.soyuz.model.publishing import BinaryPackagePublishingHistory
 from lp.soyuz.model.queue import (
     PackageUpload,
     PackageUploadSource,
@@ -379,6 +378,7 @@
         # Avoid circular imports.
         from lp.soyuz.model.binarypackagerelease import BinaryPackageRelease
         from lp.soyuz.model.distroarchseries import DistroArchSeries
+        from lp.soyuz.model.publishing import BinaryPackagePublishingHistory
 
         BuildDAS = ClassAlias(DistroArchSeries, 'BuildDAS')
         PublishDAS = ClassAlias(DistroArchSeries, 'PublishDAS')
@@ -644,6 +644,7 @@
         from lp.soyuz.interfaces.publishing import active_publishing_status
         from lp.soyuz.model.binarypackagerelease import BinaryPackageRelease
         from lp.soyuz.model.distroarchseries import DistroArchSeries
+        from lp.soyuz.model.publishing import BinaryPackagePublishingHistory
 
         return Store.of(self).find(
             BinaryPackagePublishingHistory,

=== modified file 'lib/lp/soyuz/scripts/ftpmasterbase.py'
--- lib/lp/soyuz/scripts/ftpmasterbase.py	2012-06-29 08:40:05 +0000
+++ lib/lp/soyuz/scripts/ftpmasterbase.py	2012-07-05 10:46:34 +0000
@@ -23,6 +23,7 @@
 from lp.soyuz.adapters.packagelocation import build_package_location
 from lp.soyuz.enums import ArchivePurpose
 from lp.soyuz.interfaces.component import IComponentSet
+from lp.soyuz.interfaces.publishing import active_publishing_status
 
 
 class SoyuzScriptError(Exception):
@@ -144,9 +145,6 @@
         """Return a suitable `SourcePackagePublishingHistory`."""
         assert self.location is not None, 'Undefined location.'
 
-        # Avoiding circular imports.
-        from lp.soyuz.interfaces.publishing import active_publishing_status
-
         published_sources = self.location.archive.getPublishedSources(
             name=name, version=self.options.version,
             status=active_publishing_status,

=== modified file 'lib/lp/soyuz/scripts/gina/handlers.py'
--- lib/lp/soyuz/scripts/gina/handlers.py	2012-06-19 22:53:13 +0000
+++ lib/lp/soyuz/scripts/gina/handlers.py	2012-07-05 10:46:34 +0000
@@ -41,6 +41,8 @@
     )
 from lp.registry.interfaces.sourcepackage import SourcePackageType
 from lp.registry.model.sourcepackagename import SourcePackageName
+from lp.registry.model.distribution import Distribution
+from lp.registry.model.distroseries import DistroSeries
 from lp.services.database.constants import UTC_NOW
 from lp.services.database.sqlbase import (
     quote,
@@ -58,13 +60,22 @@
     active_publishing_status,
     IPublishingSet,
     )
+from lp.soyuz.model.binarypackagebuild import BinaryPackageBuild
+from lp.soyuz.model.binarypackagename import BinaryPackageName
+from lp.soyuz.model.binarypackagerelease import BinaryPackageRelease
 from lp.soyuz.model.component import Component
+from lp.soyuz.model.distroarchseries import DistroArchSeries
 from lp.soyuz.model.files import (
     BinaryPackageFile,
     SourcePackageReleaseFile,
     )
 from lp.soyuz.model.processor import Processor
+from lp.soyuz.model.publishing import (
+    BinaryPackagePublishingHistory,
+    SourcePackagePublishingHistory,
+    )
 from lp.soyuz.model.section import Section
+from lp.soyuz.model.sourcepackagerelease import SourcePackageRelease
 from lp.soyuz.scripts.gina.library import getLibraryAlias
 from lp.soyuz.scripts.gina.packages import (
     get_dsc_path,
@@ -198,9 +209,6 @@
 
     def ensure_archinfo(self, archtag):
         """Append retrived distroarchseries info to a dict."""
-        # Avoid circular imports.
-        from lp.soyuz.model.distroarchseries import DistroArchSeries
-
         if archtag in self.archinfo.keys():
             return
 
@@ -234,9 +242,6 @@
 
     def _get_distro(self, name):
         """Return the distro database object by name."""
-        # Avoid circular imports.
-        from lp.registry.model.distribution import Distribution
-
         distro = Distribution.selectOneBy(name=name)
         if not distro:
             raise DataSetupError("Error finding distribution %r" % name)
@@ -244,11 +249,7 @@
 
     def _get_distroseries(self, name):
         """Return the distroseries database object by name."""
-        # Avoid circular imports.
-        from lp.registry.model.distroseries import DistroSeries
-
-        dr = DistroSeries.selectOneBy(name=name,
-                                       distributionID=self.distro.id)
+        dr = DistroSeries.selectOneBy(name=name, distributionID=self.distro.id)
         if not dr:
             raise DataSetupError("Error finding distroseries %r" % name)
         return dr
@@ -578,10 +579,6 @@
 
         # Check here to see if this release has ever been published in
         # the distribution, no matter what status.
-
-        # Avoid circular imports.
-        from lp.soyuz.model.sourcepackagerelease import SourcePackageRelease
-
         query = """
                 SourcePackageRelease.sourcepackagename = %s AND
                 SourcePackageRelease.version = %s AND
@@ -606,9 +603,6 @@
 
         Returns the created SourcePackageRelease, or None if it failed.
         """
-        # Avoid circular imports.
-        from lp.soyuz.model.sourcepackagerelease import SourcePackageRelease
-
         displayname, emailaddress = src.maintainer
         comment = 'when the %s package was imported into %s' % (
             src.package, distroseries.displayname)
@@ -735,10 +729,6 @@
 
     def _checkPublishing(self, sourcepackagerelease):
         """Query for the publishing entry"""
-        # Avoid circular import.
-        from lp.soyuz.model.publishing import (
-            SourcePackagePublishingHistory)
-
         ret = SourcePackagePublishingHistory.select("""
             sourcepackagerelease = %s AND
             distroseries = %s AND
@@ -765,10 +755,6 @@
 
     def checkBin(self, binarypackagedata, distroarchinfo):
         """Returns a binarypackage -- if it exists."""
-        # Avoid circular imports.
-        from lp.soyuz.model.binarypackagerelease import BinaryPackageRelease
-        from lp.soyuz.model.binarypackagename import BinaryPackageName
-
         try:
             binaryname = BinaryPackageName.byName(binarypackagedata.package)
         except SQLObjectNotFound:
@@ -813,9 +799,6 @@
 
     def createBinaryPackage(self, bin, srcpkg, distroarchinfo, archtag):
         """Create a new binarypackage."""
-        # Avoid circular imports.
-        from lp.soyuz.model.binarypackagerelease import BinaryPackageRelease
-
         fdir, fname = os.path.split(bin.filename)
         to_upload = check_not_in_librarian(fname, bin.archive_root, fdir)
         fname, path = to_upload[0]
@@ -867,9 +850,6 @@
 
     def ensureBuild(self, binary, srcpkg, distroarchinfo, archtag):
         """Ensure a build record."""
-        # Avoid circular imports.
-        from lp.soyuz.model.binarypackagebuild import BinaryPackageBuild
-
         distroarchseries = distroarchinfo['distroarchseries']
         distribution = distroarchseries.distroseries.distribution
         clauseTables = [
@@ -934,9 +914,6 @@
 
     def publish(self, binarypackage, bpdata):
         """Create the publishing entry on db if does not exist."""
-        # Avoid circular imports.
-        from lp.soyuz.model.publishing import BinaryPackagePublishingHistory
-
         # These need to be pulled from the binary package data, not the
         # binary package release: the data represents data from /this
         # specific distroseries/, whereas the package represents data
@@ -992,9 +969,6 @@
 
     def _checkPublishing(self, binarypackage):
         """Query for the publishing entry"""
-        # Avoid circular imports.
-        from lp.soyuz.model.publishing import BinaryPackagePublishingHistory
-
         ret = BinaryPackagePublishingHistory.select("""
             binarypackagerelease = %s AND
             distroarchseries = %s AND

=== modified file 'lib/lp/soyuz/scripts/initialize_distroseries.py'
--- lib/lp/soyuz/scripts/initialize_distroseries.py	2012-06-29 08:40:05 +0000
+++ lib/lp/soyuz/scripts/initialize_distroseries.py	2012-07-05 10:46:34 +0000
@@ -19,6 +19,7 @@
 from lp.buildmaster.enums import BuildStatus
 from lp.registry.interfaces.distroseriesparent import IDistroSeriesParentSet
 from lp.registry.interfaces.pocket import PackagePublishingPocket
+from lp.registry.model.distroseries import DistroSeries
 from lp.services.database import bulk
 from lp.services.database.lpstorm import IMasterStore
 from lp.services.database.sqlbase import sqlvalues
@@ -103,9 +104,6 @@
         self, distroseries, parents=(), arches=(), archindep_archtag=None,
         packagesets=(), rebuild=False, overlays=(), overlay_pockets=(),
         overlay_components=()):
-        # Avoid circular imports
-        from lp.registry.model.distroseries import DistroSeries
-
         self.distroseries = distroseries
         self.parent_ids = [int(id) for id in parents]
         # Load parent objects in bulk...

=== modified file 'lib/lp/soyuz/scripts/packagecopier.py'
--- lib/lp/soyuz/scripts/packagecopier.py	2012-07-03 08:04:35 +0000
+++ lib/lp/soyuz/scripts/packagecopier.py	2012-07-05 10:46:34 +0000
@@ -56,7 +56,6 @@
     SoyuzScript,
     SoyuzScriptError,
     )
-from lp.soyuz.scripts.processaccepted import close_bugs_for_sourcepublication
 
 
 def re_upload_file(libraryfile, restricted=False):
@@ -772,6 +771,9 @@
         `BinaryPackagePublishingHistory` corresponding to the copied
         publications.
     """
+    from lp.soyuz.scripts.processaccepted import (
+        close_bugs_for_sourcepublication)
+
     copies = []
     custom_files = []
 

=== modified file 'lib/lp/soyuz/scripts/populate_archive.py'
--- lib/lp/soyuz/scripts/populate_archive.py	2011-07-07 14:00:10 +0000
+++ lib/lp/soyuz/scripts/populate_archive.py	2012-07-05 10:46:34 +0000
@@ -15,10 +15,14 @@
 
 from lp.app.errors import NotFoundError
 from lp.app.validators.name import valid_name
+from lp.registry.interfaces.person import IPersonSet
 from lp.soyuz.adapters.packagelocation import build_package_location
 from lp.soyuz.enums import ArchivePurpose
+from lp.soyuz.interfaces.archive import IArchiveSet
+from lp.soyuz.interfaces.archivearch import IArchiveArchSet
 from lp.soyuz.interfaces.component import IComponentSet
 from lp.soyuz.interfaces.packagecloner import IPackageCloner
+from lp.soyuz.interfaces.packagecopyrequest import IPackageCopyRequestSet
 from lp.soyuz.interfaces.processor import IProcessorFamilySet
 from lp.soyuz.scripts.ftpmasterbase import (
     SoyuzScript,
@@ -85,12 +89,6 @@
         :param packageset_tags: list of packagesets to limit the packages
             copied to.
         """
-        # Avoid circular imports.
-        from lp.registry.interfaces.person import IPersonSet
-        from lp.soyuz.interfaces.archive import IArchiveSet
-        from lp.soyuz.interfaces.archivearch import IArchiveArchSet
-        from lp.soyuz.interfaces.packagecopyrequest import (
-            IPackageCopyRequestSet)
 
         def loadProcessorFamilies(arch_tags):
             """Load processor families for specified arch tags."""

=== modified file 'lib/lp/soyuz/scripts/ppakeygenerator.py'
--- lib/lp/soyuz/scripts/ppakeygenerator.py	2010-08-20 20:31:18 +0000
+++ lib/lp/soyuz/scripts/ppakeygenerator.py	2012-07-05 10:46:34 +0000
@@ -15,6 +15,7 @@
     LaunchpadCronScript,
     LaunchpadScriptFailure,
     )
+from lp.soyuz.interfaces.archive import IArchiveSet
 
 
 class PPAKeyGenerator(LaunchpadCronScript):
@@ -37,9 +38,6 @@
 
     def main(self):
         """Generate signing keys for the selected PPAs."""
-        # Avoid circular imports.
-        from lp.soyuz.interfaces.archive import IArchiveSet
-
         owner_name = self.options.archive_owner_name
 
         if owner_name is not None:

=== modified file 'lib/lp/soyuz/scripts/ppareport.py'
--- lib/lp/soyuz/scripts/ppareport.py	2012-01-01 02:58:52 +0000
+++ lib/lp/soyuz/scripts/ppareport.py	2012-07-05 10:46:34 +0000
@@ -20,7 +20,10 @@
 from zope.component import getUtility
 
 from lp.registry.interfaces.distribution import IDistributionSet
-from lp.registry.model.person import get_recipients
+from lp.registry.model.person import (
+    get_recipients,
+    Person,
+    )
 from lp.services.config import config
 from lp.services.propertycache import cachedproperty
 from lp.services.scripts.base import (
@@ -29,6 +32,8 @@
     )
 from lp.services.webapp import canonical_url
 from lp.soyuz.enums import ArchivePurpose
+from lp.soyuz.model.archive import Archive
+from lp.soyuz.model.publishing import SourcePackagePublishingHistory
 
 
 class PPAReportScript(LaunchpadScript):
@@ -74,11 +79,6 @@
         if `self.options.archive_owner_name` is defined only return PPAs
         with matching owner names.
         """
-        # Avoiding circular imports.
-        from lp.soyuz.model.archive import Archive
-        from lp.soyuz.model.publishing import SourcePackagePublishingHistory
-        from lp.registry.model.person import Person
-
         distribution = getUtility(IDistributionSet).getByName('ubuntu')
         store = Store.of(distribution)
         origin = [

=== modified file 'lib/lp/soyuz/scripts/processaccepted.py'
--- lib/lp/soyuz/scripts/processaccepted.py	2012-01-01 02:58:52 +0000
+++ lib/lp/soyuz/scripts/processaccepted.py	2012-07-05 10:46:34 +0000
@@ -21,6 +21,7 @@
 
 from lp.app.errors import NotFoundError
 from lp.app.interfaces.launchpad import ILaunchpadCelebrities
+from lp.archivepublisher.publishing import GLOBAL_PUBLISHER_LOCK
 from lp.archiveuploader.tagfiles import parse_tagfile_content
 from lp.bugs.interfaces.bug import IBugSet
 from lp.bugs.interfaces.bugtask import BugTaskStatus
@@ -301,8 +302,6 @@
     @property
     def lockfilename(self):
         """See `LaunchpadScript`."""
-        # Avoid circular imports.
-        from lp.archivepublisher.publishing import GLOBAL_PUBLISHER_LOCK
         return GLOBAL_PUBLISHER_LOCK
 
     def add_my_options(self):


Follow ups