py3: make files use absolute_import and print_function
This patch includes addition of absolute_import and print_function to the
files where they are missing. The modern importing conventions are also followed.
--- a/hgext/highlight/__init__.py Fri Jul 01 19:17:45 2016 -0700
+++ b/hgext/highlight/__init__.py Sun Jul 03 22:28:24 2016 +0530
@@ -26,9 +26,21 @@
match (even matches with a low confidence score) will be used.
"""
-import highlight
-from mercurial.hgweb import webcommands, webutil, common
-from mercurial import extensions, encoding, fileset
+from __future__ import absolute_import
+
+from . import highlight
+from mercurial.hgweb import (
+ common,
+ webcommands,
+ webutil,
+)
+
+from mercurial import (
+ encoding,
+ extensions,
+ fileset,
+)
+
# Note for extension authors: ONLY specify testedwith = 'internal' for
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
# be specifying the version(s) of Mercurial they are tested with, or
--- a/hgext/highlight/highlight.py Fri Jul 01 19:17:45 2016 -0700
+++ b/hgext/highlight/highlight.py Sun Jul 03 22:28:24 2016 +0530
@@ -8,14 +8,27 @@
# The original module was split in an interface and an implementation
# file to defer pygments loading and speedup extension setup.
+from __future__ import absolute_import
+
+import pygments
+import pygments.formatters
+import pygments.lexers
+import pygments.util
+
from mercurial import demandimport
demandimport.ignore.extend(['pkgutil', 'pkg_resources', '__main__'])
-from mercurial import util, encoding
+
+from mercurial import (
+ encoding,
+ util,
+)
-from pygments import highlight
-from pygments.util import ClassNotFound
-from pygments.lexers import guess_lexer, guess_lexer_for_filename, TextLexer
-from pygments.formatters import HtmlFormatter
+highlight = pygments.highlight
+ClassNotFound = pygments.util.ClassNotFound
+guess_lexer = pygments.lexers.guess_lexer
+guess_lexer_for_filename = pygments.lexers.guess_lexer_for_filename
+TextLexer = pygments.lexers.TextLexer
+HtmlFormatter = pygments.formatters.HtmlFormatter
SYNTAX_CSS = ('\n<link rel="stylesheet" href="{url}highlightcss" '
'type="text/css" />')
--- a/hgext/share.py Fri Jul 01 19:17:45 2016 -0700
+++ b/hgext/share.py Sun Jul 03 22:28:24 2016 +0530
@@ -37,10 +37,22 @@
The default naming mode is "identity."
'''
+from __future__ import absolute_import
+
+import errno
from mercurial.i18n import _
-from mercurial import cmdutil, commands, hg, util, extensions, bookmarks, error
-from mercurial.hg import repository, parseurl
-import errno
+from mercurial import (
+ bookmarks,
+ cmdutil,
+ commands,
+ error,
+ extensions,
+ hg,
+ util,
+)
+
+repository = hg.repository
+parseurl = hg.parseurl
cmdtable = {}
command = cmdutil.command(cmdtable)
--- a/hgext/win32text.py Fri Jul 01 19:17:45 2016 -0700
+++ b/hgext/win32text.py Sun Jul 03 22:28:24 2016 +0530
@@ -41,10 +41,16 @@
# or pretxnchangegroup.cr = python:hgext.win32text.forbidcr
'''
+from __future__ import absolute_import
+
+import re
from mercurial.i18n import _
-from mercurial.node import short
-from mercurial import util
-import re
+from mercurial.node import (
+ short,
+)
+from mercurial import (
+ util,
+)
# Note for extension authors: ONLY specify testedwith = 'internal' for
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
--- a/i18n/polib.py Fri Jul 01 19:17:45 2016 -0700
+++ b/i18n/polib.py Sun Jul 03 22:28:24 2016 +0530
@@ -13,6 +13,8 @@
:func:`~polib.mofile` convenience functions.
"""
+from __future__ import absolute_import
+
__author__ = 'David Jean Louis <izimobil@gmail.com>'
__version__ = '0.6.4'
__all__ = ['pofile', 'POFile', 'POEntry', 'mofile', 'MOFile', 'MOEntry',
--- a/tests/heredoctest.py Fri Jul 01 19:17:45 2016 -0700
+++ b/tests/heredoctest.py Sun Jul 03 22:28:24 2016 +0530
@@ -1,4 +1,4 @@
-from __future__ import absolute_import
+from __future__ import absolute_import, print_function
import sys
--- a/tests/md5sum.py Fri Jul 01 19:17:45 2016 -0700
+++ b/tests/md5sum.py Sun Jul 03 22:28:24 2016 +0530
@@ -6,12 +6,17 @@
# of the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2, which is
# GPL-compatible.
-import sys, os
+from __future__ import absolute_import
+
+import os
+import sys
try:
- from hashlib import md5
+ import hashlib
+ md5 = hashlib.md5
except ImportError:
- from md5 import md5
+ import md5
+ md5 = md5.md5
try:
import msvcrt
--- a/tests/readlink.py Fri Jul 01 19:17:45 2016 -0700
+++ b/tests/readlink.py Sun Jul 03 22:28:24 2016 +0530
@@ -1,8 +1,10 @@
#!/usr/bin/env python
-from __future__ import print_function
+from __future__ import absolute_import, print_function
-import errno, os, sys
+import errno
+import os
+import sys
for f in sys.argv[1:]:
try:
--- a/tests/run-tests.py Fri Jul 01 19:17:45 2016 -0700
+++ b/tests/run-tests.py Sun Jul 03 22:28:24 2016 +0530
@@ -43,31 +43,31 @@
# completes fairly quickly, includes both shell and Python scripts, and
# includes some scripts that run daemon processes.)
-from __future__ import print_function
+from __future__ import absolute_import, print_function
-from distutils import version
import difflib
+import distutils.version as version
import errno
import json
import optparse
import os
+import random
+import re
import shutil
-import subprocess
import signal
import socket
+import subprocess
import sys
import tempfile
+import threading
import time
-import random
-import re
-import threading
-import killdaemons as killmod
+import unittest
+import xml.dom.minidom as minidom
+
try:
import Queue as queue
except ImportError:
import queue
-from xml.dom import minidom
-import unittest
if os.environ.get('RTUNICODEPEDANTRY', False):
try:
@@ -475,6 +475,7 @@
pass
def killdaemons(pidfile):
+ import killdaemons as killmod
return killmod.killdaemons(pidfile, tryhard=False, remove=True,
logfn=vlog)
@@ -2493,7 +2494,8 @@
def _outputcoverage(self):
"""Produce code coverage output."""
- from coverage import coverage
+ import coverage
+ coverage = coverage.coverage
vlog('# Producing coverage report')
# chdir is the easiest way to get short, relative paths in the
--- a/tests/test-check-py3-compat.t Fri Jul 01 19:17:45 2016 -0700
+++ b/tests/test-check-py3-compat.t Sun Jul 03 22:28:24 2016 +0530
@@ -8,17 +8,8 @@
hgext/fsmonitor/pywatchman/__init__.py requires print_function
hgext/fsmonitor/pywatchman/capabilities.py not using absolute_import
hgext/fsmonitor/pywatchman/pybser.py not using absolute_import
- hgext/highlight/__init__.py not using absolute_import
- hgext/highlight/highlight.py not using absolute_import
- hgext/share.py not using absolute_import
- hgext/win32text.py not using absolute_import
i18n/check-translation.py not using absolute_import
- i18n/polib.py not using absolute_import
setup.py not using absolute_import
- tests/heredoctest.py requires print_function
- tests/md5sum.py not using absolute_import
- tests/readlink.py not using absolute_import
- tests/run-tests.py not using absolute_import
tests/test-demandimport.py not using absolute_import
#if py3exe
--- a/tests/test-commandserver.t Fri Jul 01 19:17:45 2016 -0700
+++ b/tests/test-commandserver.t Sun Jul 03 22:28:24 2016 +0530
@@ -13,11 +13,12 @@
$ hg init repo
$ cd repo
+ >>> from __future__ import print_function
>>> from hgclient import readchannel, runcommand, check
>>> @check
... def hellomessage(server):
... ch, data = readchannel(server)
- ... print '%c, %r' % (ch, data)
+ ... print('%c, %r' % (ch, data))
... # run an arbitrary command to make sure the next thing the server
... # sends isn't part of the hello message
... runcommand(server, ['id'])
@@ -99,7 +100,7 @@
... server.stdin.close()
...
... # server exits with 1 if the pipe closed while reading the command
- ... print 'server exit code =', server.wait()
+ ... print('server exit code =', server.wait())
server exit code = 1
>>> from hgclient import readchannel, runcommand, check, stringio
@@ -206,10 +207,11 @@
#endif
$ cat <<EOF > hook.py
+ > from __future__ import print_function
> import sys
> def hook(**args):
- > print 'hook talking'
- > print 'now try to read something: %r' % sys.stdin.read()
+ > print('hook talking')
+ > print('now try to read something: %r' % sys.stdin.read())
> EOF
>>> from hgclient import readchannel, runcommand, check, stringio
@@ -610,18 +612,19 @@
run commandserver in commandserver, which is silly but should work:
+ >>> from __future__ import print_function
>>> from hgclient import readchannel, runcommand, check, stringio
>>> @check
... def nested(server):
- ... print '%c, %r' % readchannel(server)
+ ... print('%c, %r' % readchannel(server))
... class nestedserver(object):
... stdin = stringio('getencoding\n')
... stdout = stringio()
... runcommand(server, ['serve', '--cmdserver', 'pipe'],
... output=nestedserver.stdout, input=nestedserver.stdin)
... nestedserver.stdout.seek(0)
- ... print '%c, %r' % readchannel(nestedserver) # hello
- ... print '%c, %r' % readchannel(nestedserver) # getencoding
+ ... print('%c, %r' % readchannel(nestedserver)) # hello
+ ... print('%c, %r' % readchannel(nestedserver)) # getencoding
o, 'capabilities: getencoding runcommand\nencoding: *\npid: *' (glob)
*** runcommand serve --cmdserver pipe
o, 'capabilities: getencoding runcommand\nencoding: *\npid: *' (glob)
@@ -632,11 +635,12 @@
$ cd ..
+ >>> from __future__ import print_function
>>> from hgclient import readchannel, runcommand, check
>>> @check
... def hellomessage(server):
... ch, data = readchannel(server)
- ... print '%c, %r' % (ch, data)
+ ... print('%c, %r' % (ch, data))
... # run an arbitrary command to make sure the next thing the server
... # sends isn't part of the hello message
... runcommand(server, ['id'])
@@ -672,11 +676,12 @@
#if unix-socket unix-permissions
+ >>> from __future__ import print_function
>>> from hgclient import unixserver, readchannel, runcommand, check, stringio
>>> server = unixserver('.hg/server.sock', '.hg/server.log')
>>> def hellomessage(conn):
... ch, data = readchannel(conn)
- ... print '%c, %r' % (ch, data)
+ ... print('%c, %r' % (ch, data))
... runcommand(conn, ['id'])
>>> check(hellomessage, server.connect)
o, 'capabilities: getencoding runcommand\nencoding: *\npid: *' (glob)
@@ -723,6 +728,7 @@
> [cmdserver]
> log = inexistent/path.log
> EOF
+ >>> from __future__ import print_function
>>> from hgclient import unixserver, readchannel, check
>>> server = unixserver('.hg/server.sock', '.hg/server.log')
>>> def earlycrash(conn):
@@ -730,7 +736,7 @@
... try:
... ch, data = readchannel(conn)
... if not data.startswith(' '):
- ... print '%c, %r' % (ch, data)
+ ... print('%c, %r' % (ch, data))
... except EOFError:
... break
>>> check(earlycrash, server.connect)
--- a/tests/test-generaldelta.t Fri Jul 01 19:17:45 2016 -0700
+++ b/tests/test-generaldelta.t Sun Jul 03 22:28:24 2016 +0530
@@ -18,11 +18,12 @@
> done
$ cd ..
+ >>> from __future__ import print_function
>>> import os
>>> regsize = os.stat("repo/.hg/store/00manifest.i").st_size
>>> gdsize = os.stat("gdrepo/.hg/store/00manifest.i").st_size
>>> if regsize < gdsize:
- ... print 'generaldata increased size of manifest'
+ ... print('generaldata increased size of manifest')
Verify rev reordering doesnt create invalid bundles (issue4462)
This requires a commit tree that when pulled will reorder manifest revs such
--- a/tests/test-hgweb-commands.t Fri Jul 01 19:17:45 2016 -0700
+++ b/tests/test-hgweb-commands.t Sun Jul 03 22:28:24 2016 +0530
@@ -2104,9 +2104,10 @@
Graph json escape of multibyte character
$ get-with-headers.py 127.0.0.1:$HGPORT 'graph/' > out
+ >>> from __future__ import print_function
>>> for line in open("out"):
... if line.startswith("var data ="):
- ... print line,
+ ... print(line, end='')
var data = [["061dd13ba3c3", [0, 1], [[0, 0, 1, -1, ""]], "\u80fd", "test", "1970-01-01", ["unstable", true], ["tip"], ["something"]], ["cad8025a2e87", [0, 1], [[0, 0, 1, 3, "FF0000"]], "branch commit with null character: \u0000", "test", "1970-01-01", ["unstable", false], [], []], ["1d22e65f027e", [0, 1], [[0, 0, 1, 3, ""]], "branch", "test", "1970-01-01", ["stable", true], [], []], ["a4f92ed23982", [0, 1], [[0, 0, 1, 3, ""]], "Added tag 1.0 for changeset 2ef0ac749a14", "test", "1970-01-01", ["default", true], [], []], ["2ef0ac749a14", [0, 1], [], "base", "test", "1970-01-01", ["default", false], ["1.0"], ["anotherthing"]]];
capabilities
--- a/tests/test-import.t Fri Jul 01 19:17:45 2016 -0700
+++ b/tests/test-import.t Sun Jul 03 22:28:24 2016 +0530
@@ -53,7 +53,8 @@
regardless of the commit message in the patch)
$ cat > dummypatch.py <<EOF
- > print 'patching file a'
+ > from __future__ import print_function
+ > print('patching file a')
> file('a', 'wb').write('line2\n')
> EOF
$ hg clone -r0 a b
--- a/tests/test-status.t Fri Jul 01 19:17:45 2016 -0700
+++ b/tests/test-status.t Sun Jul 03 22:28:24 2016 +0530
@@ -203,8 +203,9 @@
]
$ hg status -A -Tpickle > pickle
+ >>> from __future__ import print_function
>>> import pickle
- >>> print sorted((x['status'], x['path']) for x in pickle.load(open("pickle")))
+ >>> print(sorted((x['status'], x['path']) for x in pickle.load(open("pickle"))))
[('!', 'deleted'), ('?', 'pickle'), ('?', 'unknown'), ('A', 'added'), ('A', 'copied'), ('C', '.hgignore'), ('C', 'modified'), ('I', 'ignored'), ('R', 'removed')]
$ rm pickle
--- a/tests/test-unified-test.t Fri Jul 01 19:17:45 2016 -0700
+++ b/tests/test-unified-test.t Sun Jul 03 22:28:24 2016 +0530
@@ -26,24 +26,25 @@
Doctest commands:
- >>> print 'foo'
+ >>> from __future__ import print_function
+ >>> print('foo')
foo
$ echo interleaved
interleaved
>>> for c in 'xyz':
- ... print c
+ ... print(c)
x
y
z
- >>> print
+ >>> print()
>>> foo = 'global name'
>>> def func():
- ... print foo, 'should be visible in func()'
+ ... print(foo, 'should be visible in func()')
>>> func()
global name should be visible in func()
- >>> print '''multiline
- ... string'''
+ >>> print('''multiline
+ ... string''')
multiline
string