[PATCH 2 of 3] py3: condiionalize thread import

Pulkit Goyal 7895pulkit at gmail.com
Thu Jun 30 05:47:19 EDT 2016


# HG changeset patch
# User Pulkit Goyal <7895pulkit at gmail.com>
# Date 1467113601 -19800
#      Tue Jun 28 17:03:21 2016 +0530
# Node ID 91320eb3d9ce90433ec843525e5563dbad5193e2
# Parent  752f11e6e60f6214335dd761e6bb045d63747bbb
py3: condiionalize thread import

The thread module is renamed to _thread in python 3. Now we import util.thread and
 hence a test is added in check-code too.

diff -r 752f11e6e60f -r 91320eb3d9ce contrib/check-code.py
--- a/contrib/check-code.py	Tue Jun 28 16:01:53 2016 +0530
+++ b/contrib/check-code.py	Tue Jun 28 17:03:21 2016 +0530
@@ -331,6 +331,7 @@
     (r'^import cPickle', "don't use cPickle, use util.pickle"),
     (r'^import pickle', "don't use pickle, use util.pickle"),
     (r'^import httplib', "don't use httplib, use util.httplib"),
+    (r'^import thread\n', "don't use thread, use util.thread"),
     (r'\.next\(\)', "don't use .next(), use next(...)"),
 
     # rules depending on implementation of repquote()
diff -r 752f11e6e60f -r 91320eb3d9ce mercurial/keepalive.py
--- a/mercurial/keepalive.py	Tue Jun 28 16:01:53 2016 +0530
+++ b/mercurial/keepalive.py	Tue Jun 28 17:03:21 2016 +0530
@@ -113,12 +113,12 @@
 import hashlib
 import socket
 import sys
-import thread
 
 from . import (
     util,
 )
 
+thread = util.thread
 httplib = util.httplib
 urlerr = util.urlerr
 urlreq = util.urlreq
diff -r 752f11e6e60f -r 91320eb3d9ce mercurial/pycompat.py
--- a/mercurial/pycompat.py	Tue Jun 28 16:01:53 2016 +0530
+++ b/mercurial/pycompat.py	Tue Jun 28 17:03:21 2016 +0530
@@ -18,6 +18,13 @@
     pickle.dumps # silence pyflakes
 
 try:
+    import thread
+    thread.LockType
+except ImportError:
+    import _thread as thread
+    thread.LockType
+
+try:
     import httplib
     httplib.HTTPException
 except ImportError:
diff -r 752f11e6e60f -r 91320eb3d9ce mercurial/util.py
--- a/mercurial/util.py	Tue Jun 28 16:01:53 2016 +0530
+++ b/mercurial/util.py	Tue Jun 28 17:03:21 2016 +0530
@@ -56,6 +56,7 @@
     #'urlreq',
     'stringio',
     'socketserver',
+    'thread',
     'xmlrpclib',
 ):
     globals()[attr] = getattr(pycompat, attr)
diff -r 752f11e6e60f -r 91320eb3d9ce tests/test-check-py3-compat.t
--- a/tests/test-check-py3-compat.t	Tue Jun 28 16:01:53 2016 +0530
+++ b/tests/test-check-py3-compat.t	Tue Jun 28 17:03:21 2016 +0530
@@ -115,7 +115,6 @@
   mercurial/hook.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
   mercurial/httpconnection.py: error importing: <ImportError> No module named 'rfc822' (error at __init__.py:*) (glob)
   mercurial/httppeer.py: error importing module: <SyntaxError> invalid syntax (bundle2.py, line *) (line *) (glob)
-  mercurial/keepalive.py: error importing module: <ImportError> No module named 'thread' (line *) (glob)
   mercurial/localrepo.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
   mercurial/mail.py: error importing module: <AttributeError> module 'email' has no attribute 'Header' (line *) (glob)
   mercurial/manifest.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)


More information about the Mercurial-devel mailing list