Fixing Import Cycles.

Pulkit Goyal 7895pulkit at gmail.com
Wed Feb 24 02:02:13 UTC 2016


Hello Everyone,

I was working on fixing import cycles in the codebase. The first import
cycle was between hgext/largefiles/basestore and
hgext/largefiles/localstore. The dependency can be solved by resolving the
dependency of localstore on basestore. The dependency was of StoreError
class which was required in the both the files but the only reason to
import basestore in localstore.

So rather we define the StoreError class in localstore rather than
basestore. Its necessary to import localstore in basestore. So this is the
only way around. I guess.

diff -r 2e11f6756d9c hgext/largefiles/basestore.py
--- a/hgext/largefiles/basestore.py    Tue Feb 16 14:49:29 2016 +0000
+++ b/hgext/largefiles/basestore.py    Wed Feb 24 07:25:57 2016 +0530
@@ -14,23 +14,7 @@
 from mercurial.i18n import _

 import lfutil
-
-class StoreError(Exception):
-    '''Raised when there is a problem getting files from or putting
-    files to a central store.'''
-    def __init__(self, filename, hash, url, detail):
-        self.filename = filename
-        self.hash = hash
-        self.url = url
-        self.detail = detail
-
-    def longmessage(self):
-        return (_("error getting id %s from url %s for file %s: %s\n") %
-                 (self.hash, util.hidepassword(self.url), self.filename,
-                  self.detail))
-
-    def __str__(self):
-        return "%s: %s" % (util.hidepassword(self.url), self.detail)
+import localstore

 class basestore(object):
     def __init__(self, ui, repo, url):
@@ -96,7 +80,7 @@

         try:
             gothash = self._getfile(tmpfile, filename, hash)
-        except StoreError as err:
+        except localstore.StoreError as err:
             self.ui.warn(err.longmessage())
             gothash = ""
         tmpfile.close()
@@ -160,7 +144,7 @@
         '''
         raise NotImplementedError('abstract method')

-import localstore, wirestore
+import wirestore

 _storeprovider = {
     'file':  [localstore.localstore],
diff -r 2e11f6756d9c hgext/largefiles/localstore.py
--- a/hgext/largefiles/localstore.py    Tue Feb 16 14:49:29 2016 +0000
+++ b/hgext/largefiles/localstore.py    Wed Feb 24 07:25:57 2016 +0530
@@ -11,9 +11,25 @@
 from mercurial.i18n import _

 import lfutil
-import basestore

-class localstore(basestore.basestore):
+class StoreError(Exception):
+    '''Raised when there is a problem getting files from or putting
+    files to a central store.'''
+    def __init__(self, filename, hash, url, detail):
+        self.filename = filename
+        self.hash = hash
+        self.url = url
+        self.detail = detail
+
+    def longmessage(self):
+        return (_("error getting id %s from url %s for file %s: %s\n") %
+                 (self.hash, util.hidepassword(self.url), self.filename,
+                  self.detail))
+
+    def __str__(self):
+        return "%s: %s" % (util.hidepassword(self.url), self.detail)
+
+class localstore():
     '''localstore first attempts to grab files out of the store in the
remote
     Mercurial repository.  Failing that, it attempts to grab the files from
     the user cache.'''

Well now I feel like i going on the right track but still I doubt. After
running hg locate 'mercurial/**.py' 'hgext/**.py' | sed 's-\\-/-g' | python
"$import_checker" - I am getting new import cycles so I think i fixed this
one.

Regards
Pulkit Goyal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20160224/6cf4508b/attachment.html>


More information about the Mercurial-devel mailing list