Patchwork [v2] convert: bzr use absolute_import

login
register
mail settings
Submitter timeless@mozdev.org
Date March 11, 2016, 4:48 a.m.
Message ID <d120ac6af6634abe404e.1457671712@waste.org>
Download mbox | patch
Permalink /patch/13754/
State Superseded
Commit 098bb566058089fffc594265584402dce5cb323d
Headers show

Comments

timeless@mozdev.org - March 11, 2016, 4:48 a.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1456936372 0
#      Wed Mar 02 16:32:52 2016 +0000
# Node ID d120ac6af6634abe404e5562562d2cc8231bb821
# Parent  1c658391b22fb4d98ccfb60c0e57315b55634117
convert: bzr use absolute_import

Patch

diff --git a/hgext/convert/bzr.py b/hgext/convert/bzr.py
--- a/hgext/convert/bzr.py
+++ b/hgext/convert/bzr.py
@@ -7,9 +7,16 @@ 
 
 # This module is for handling 'bzr', that was formerly known as Bazaar-NG;
 # it cannot access 'bar' repositories, but they were never used very much
+from __future__ import absolute_import
 
 import os
-from mercurial import demandimport, error
+from mercurial import (
+    demandimport,
+    error
+)
+from mercurial.i18n import _
+from . import common
+
 # these do not work with demandimport, blacklist
 demandimport.ignore.extend([
         'bzrlib.transactions',
@@ -17,49 +24,50 @@ 
         'ElementPath',
     ])
 
-from mercurial.i18n import _
-from mercurial import error
-from common import NoRepo, commit, converter_source
-
 try:
     # bazaar imports
-    from bzrlib import bzrdir, revision, errors
-    from bzrlib.revisionspec import RevisionSpec
+    import bzrlib.bzrdir
+    import bzrlib.errors
+    import bzrlib.revision
+    import bzrlib.revisionspec.RevisionSpec
+    bzrdir = bzrlib.bzrdir
+    errors = bzrlib.errors
+    revision = bzrlib.revision
+    revisionspec = bzrlib.revisionspec
 except ImportError:
     pass
 
 supportedkinds = ('file', 'symlink')
 
-class bzr_source(converter_source):
+class bzr_source(common.converter_source):
     """Reads Bazaar repositories by using the Bazaar Python libraries"""
 
     def __init__(self, ui, path, revs=None):
         super(bzr_source, self).__init__(ui, path, revs=revs)
 
         if not os.path.exists(os.path.join(path, '.bzr')):
-            raise NoRepo(_('%s does not look like a Bazaar repository')
-                         % path)
+            raise common.NoRepo(_('%s does not look like a Bazaar repository')
+                              % path)
 
         try:
             # access bzrlib stuff
             bzrdir
         except NameError:
-            raise NoRepo(_('Bazaar modules could not be loaded'))
+            raise common.NoRepo(_('Bazaar modules could not be loaded'))
 
         path = os.path.abspath(path)
         self._checkrepotype(path)
         try:
             self.sourcerepo = bzrdir.BzrDir.open(path).open_repository()
         except errors.NoRepositoryPresent:
-            raise NoRepo(_('%s does not look like a Bazaar repository')
-                         % path)
+            raise common.NoRepo(_('%s does not look like a Bazaar repository')
+                              % path)
         self._parentids = {}
 
     def _checkrepotype(self, path):
         # Lightweight checkouts detection is informational but probably
         # fragile at API level. It should not terminate the conversion.
         try:
-            from bzrlib import bzrdir
             dir = bzrdir.BzrDir.open_containing(path)[0]
             try:
                 tree = dir.open_workingtree(recommend_upgrade=False)
@@ -102,7 +110,7 @@ 
             revid = None
             for branch in self._bzrbranches():
                 try:
-                    r = RevisionSpec.from_string(self.revs[0])
+                    r = revisionspec.RevisionSpec.from_string(self.revs[0])
                     info = r.in_history(branch)
                 except errors.BzrError:
                     pass
@@ -160,7 +168,7 @@ 
         branch = self.recode(rev.properties.get('branch-nick', u'default'))
         if branch == 'trunk':
             branch = 'default'
-        return commit(parents=parents,
+        return common.commit(parents=parents,
                 date='%d %d' % (rev.timestamp, -rev.timezone),
                 author=self.recode(rev.committer),
                 desc=self.recode(rev.message),
diff --git a/tests/test-check-py3-compat.t b/tests/test-check-py3-compat.t
--- a/tests/test-check-py3-compat.t
+++ b/tests/test-check-py3-compat.t
@@ -25,7 +25,6 @@ 
   hgext/__init__.py not using absolute_import
   hgext/color.py not using absolute_import
   hgext/convert/__init__.py not using absolute_import
-  hgext/convert/bzr.py not using absolute_import
   hgext/convert/common.py not using absolute_import
   hgext/convert/convcmd.py not using absolute_import
   hgext/convert/cvs.py not using absolute_import