[PATCH 5 of 5] dispatch: use modern import convention

Gregory Szorc gregory.szorc at gmail.com
Sun Jun 28 14:49:43 CDT 2015


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1435520824 25200
#      Sun Jun 28 12:47:04 2015 -0700
# Node ID 54b772a871d8c8c66b14788e8698cefc00435116
# Parent  305b6fcf8fe7026984db07dfce459ff4ffb432f4
dispatch: use modern import convention

A mixed imports warning disappears because there is no longer any
ambiguity between "commands" since "commands" is imported as part of a
"from . import X" block.

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -4,15 +4,36 @@
 #
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
-from i18n import _
-import os, sys, atexit, signal, pdb, socket, errno, shlex, time, traceback, re
+from __future__ import absolute_import
+
+import atexit
 import difflib
-import util, commands, hg, fancyopts, extensions, hook, error
-import cmdutil, encoding
-import ui as uimod
-import demandimport
+import errno
+import os
+import pdb
+import shlex
+import signal
+import socket
+import sys
+import time
+import traceback
+
+from .i18n import _
+from . import (
+    cmdutil,
+    commands,
+    demandimport,
+    encoding,
+    error,
+    extensions,
+    fancyopts,
+    hg,
+    hook,
+    ui as uimod,
+    util,
+)
 
 class request(object):
     def __init__(self, args, ui=None, repo=None, fin=None, fout=None,
                  ferr=None):
@@ -907,9 +928,9 @@ def lsprofile(ui, func, fp):
                     " - Ignored\n") % format)
         format = 'text'
 
     try:
-        from mercurial import lsprof
+        from . import lsprof
     except ImportError:
         raise util.Abort(_(
             'lsprof not available - install from '
             'http://codespeak.net/svn/user/arigo/hack/misc/lsprof/'))
diff --git a/tests/test-module-imports.t b/tests/test-module-imports.t
--- a/tests/test-module-imports.t
+++ b/tests/test-module-imports.t
@@ -110,11 +110,8 @@ here that we should still endeavor to fi
 hidden by deduplication algorithm in the cycle detector, so fixing
 these may expose other cycles.
 
   $ hg locate 'mercurial/**.py' 'hgext/**.py' | sed 's-\\-/-g' | python "$import_checker" -
-  mercurial/dispatch.py mixed imports
-     stdlib:    commands
-     relative:  error, extensions, fancyopts, hg, hook, util
   mercurial/fileset.py mixed imports
      stdlib:    parser
      relative:  error, merge, util
   mercurial/revset.py mixed imports


More information about the Mercurial-devel mailing list