[PATCH 3 of 5] cmdutil: use absolute_import

Gregory Szorc gregory.szorc at gmail.com
Sat Jan 2 13:30:52 CST 2016


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1451760144 28800
#      Sat Jan 02 10:42:24 2016 -0800
# Node ID 6e6d6908446300b3ffe26dae645d59c8a8ac53c0
# Parent  932b8e6ce49a4b352b7c08c33d5274e07b64ec02
cmdutil: use absolute_import

Now that @command doesn't write back into commands when it is being
executed during the loading of commands.py itself, we are unblocked
from converting cmdutil to absolute_import.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1,27 +1,57 @@
 # cmdutil.py - help for command processing in mercurial
 #
 # Copyright 2005-2007 Matt Mackall <mpm at selenic.com>
 #
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
-from node import hex, bin, nullid, nullrev, short
-from i18n import _
-import os, sys, errno, re, tempfile, cStringIO
-import util, scmutil, templater, patch, error, templatekw, revlog, copies
-import match as matchmod
-import repair, graphmod, revset, phases, obsolete, pathutil
-import changelog
-import bookmarks
-import encoding
-import formatter
-import crecord as crecordmod
-import lock as lockmod
+from __future__ import absolute_import
+
+import cStringIO
+import errno
+import os
+import re
+import sys
+import tempfile
+
+from .i18n import _
+from .node import (
+    bin,
+    hex,
+    nullid,
+    nullrev,
+    short,
+)
+
+from . import (
+    bookmarks,
+    changelog,
+    copies,
+    crecord as crecordmod,
+    encoding,
+    error,
+    formatter,
+    graphmod,
+    lock as lockmod,
+    match as matchmod,
+    obsolete,
+    patch,
+    pathutil,
+    phases,
+    registrar,
+    repair,
+    revlog,
+    revset,
+    scmutil,
+    templatekw,
+    templater,
+    util,
+)
 
 def ishunk(x):
     hunkclasses = (crecordmod.uihunk, patch.recordhunk)
     return isinstance(x, hunkclasses)
 
 def newandmodified(chunks, originalchunks):
     newlyaddedandmodifiedfiles = set()
     for chunk in chunks:
@@ -73,17 +103,17 @@ def recordfilter(ui, originalhunks, oper
         newchunks, newopts = filterchunks(ui, originalhunks, usecurses,
                                           testfile, operation)
     finally:
         ui.write = oldwrite
     return newchunks, newopts
 
 def dorecord(ui, repo, commitfunc, cmdsuggest, backupall,
             filterfn, *pats, **opts):
-    import merge as mergemod
+    from . import merge as mergemod
 
     if not ui.interactive():
         if cmdsuggest:
             msg = _('running non-interactively, use %s instead') % cmdsuggest
         else:
             msg = _('running non-interactively')
         raise error.Abort(msg)
 
@@ -861,17 +891,17 @@ def tryimportone(ui, repo, hunk, parents
     :parents: nodes that will be parent of the created commit
     :opts: the full dict of option passed to the import command
     :msgs: list to save commit message to.
            (used in case we need to save it when failing)
     :updatefunc: a function that update a repo to a given node
                  updatefunc(<repo>, <node>)
     """
     # avoid cycle context -> subrepo -> cmdutil
-    import context
+    from . import context
     extractdata = patch.extract(ui, hunk)
     tmpname = extractdata.get('filename')
     message = extractdata.get('message')
     user = extractdata.get('user')
     date = extractdata.get('date')
     branch = extractdata.get('branch')
     nodeid = extractdata.get('nodeid')
     p1 = extractdata.get('p1')
@@ -2496,17 +2526,17 @@ def commit(ui, repo, commitfunc, pats, o
         if scmutil.addremove(repo, matcher, "", opts) != 0:
             raise error.Abort(
                 _("failed to mark all new/missing files as added/removed"))
 
     return commitfunc(ui, repo, message, matcher, opts)
 
 def amend(ui, repo, commitfunc, old, extra, pats, opts):
     # avoid cycle context -> subrepo -> cmdutil
-    import context
+    from . import context
 
     # amend will reuse the existing user if not specified, but the obsolete
     # marker creation requires that the current user's name is specified.
     if obsolete.isenabled(repo, obsolete.createmarkersopt):
         ui.username() # raise exception if username not set
 
     ui.note(_('amending changeset %s\n') % old)
     base = old.p1()
@@ -3294,17 +3324,17 @@ def command(table):
         def decorator(func):
             if synopsis:
                 table[name] = func, list(options), synopsis
             else:
                 table[name] = func, list(options)
 
             if norepo or optionalrepo or inferrepo:
                 aliases = parsealiases(name)
-                import commands
+                from . import commands
 
             if norepo:
                 if commanduseregistrar:
                     registrar.commands['norepo'] |= set(aliases)
                 else:
                     commands.norepo += ' %s' % ' '.join(aliases)
 
             if optionalrepo:
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
@@ -93,17 +93,16 @@
   hgext/transplant.py not using absolute_import
   hgext/win32mbcs.py not using absolute_import
   hgext/win32text.py not using absolute_import
   hgext/zeroconf/Zeroconf.py not using absolute_import
   hgext/zeroconf/Zeroconf.py requires print_function
   hgext/zeroconf/__init__.py not using absolute_import
   i18n/check-translation.py not using absolute_import
   i18n/polib.py not using absolute_import
-  mercurial/cmdutil.py not using absolute_import
   mercurial/commands.py not using absolute_import
   mercurial/dispatch.py requires print_function
   mercurial/keepalive.py requires print_function
   mercurial/lsprof.py requires print_function
   mercurial/lsprofcalltree.py requires print_function
   mercurial/mail.py requires print_function
   setup.py not using absolute_import
   tests/filterpyflakes.py requires print_function


More information about the Mercurial-devel mailing list