[PATCH] py3: conditionalize the cPickle import
timeless
timeless at gmail.com
Thu May 26 13:50:07 EDT 2016
r-.
this is wrong. you need to access a member variable in order to
trigger demandload.
(I know, i have this properly patched in a series)
On Thu, May 26, 2016 at 1:34 PM, Pulkit Goyal <7895pulkit at gmail.com> wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit at gmail.com>
> # Date 1464284031 -19800
> # Thu May 26 23:03:51 2016 +0530
> # Node ID b83b78ad91f594b3eb38921505b216f82141a74e
> # Parent ee935a6e1ea2894c16e866bca25591aa93fb566d
> py3: conditionalize the cPickle import
>
> The cPickle is renamed to _pickle in python3 and this C extension is available
> in pickle which was not included in earlier versions. So imports are conditionalized
> to import cPickle in py2 and pickle in py3. Moreover the use of pickle in py2 is
> switched to cPickle as the C extension is faster.
>
> diff --git a/hgext/convert/common.py b/hgext/convert/common.py
> --- a/hgext/convert/common.py
> +++ b/hgext/convert/common.py
> @@ -7,7 +7,6 @@
> from __future__ import absolute_import
>
> import base64
> -import cPickle as pickle
> import datetime
> import errno
> import os
> @@ -21,6 +20,11 @@
> util,
> )
>
> +try:
> + import cPickle as pickle
> +except ImportError:
> + import pickle
> +
> propertycache = util.propertycache
>
> def encodeargs(args):
> diff --git a/hgext/convert/cvsps.py b/hgext/convert/cvsps.py
> --- a/hgext/convert/cvsps.py
> +++ b/hgext/convert/cvsps.py
> @@ -6,7 +6,6 @@
> # GNU General Public License version 2 or any later version.
> from __future__ import absolute_import
>
> -import cPickle as pickle
> import os
> import re
>
> @@ -16,6 +15,11 @@
> util,
> )
>
> +try:
> + import cPickle as pickle
> +except ImportError:
> + import pickle
> +
> class logentry(object):
> '''Class logentry has the following attributes:
> .author - author name as CVS knows it
> diff --git a/hgext/convert/subversion.py b/hgext/convert/subversion.py
> --- a/hgext/convert/subversion.py
> +++ b/hgext/convert/subversion.py
> @@ -3,7 +3,6 @@
> # Copyright(C) 2007 Daniel Holth et al
> from __future__ import absolute_import
>
> -import cPickle as pickle
> import os
> import re
> import sys
> @@ -21,6 +20,11 @@
>
> from . import common
>
> +try:
> + import cPickle as pickle
> +except ImportError:
> + import pickle
> +
> stringio = util.stringio
> propertycache = util.propertycache
> urlerr = util.urlerr
> diff --git a/hgext/histedit.py b/hgext/histedit.py
> --- a/hgext/histedit.py
> +++ b/hgext/histedit.py
> @@ -173,7 +173,6 @@
>
> import errno
> import os
> -import pickle
> import sys
>
> from mercurial.i18n import _
> @@ -197,6 +196,11 @@
> util,
> )
>
> +try:
> + import cPickle as pickle
> +except ImportError:
> + import pickle
> +
> release = lock.release
> cmdtable = {}
> command = cmdutil.command(cmdtable)
> diff --git a/mercurial/formatter.py b/mercurial/formatter.py
> --- a/mercurial/formatter.py
> +++ b/mercurial/formatter.py
> @@ -7,7 +7,6 @@
>
> from __future__ import absolute_import
>
> -import cPickle
> import os
>
> from .i18n import _
> @@ -22,6 +21,11 @@
> templater,
> )
>
> +try:
> + import cPickle as pickle
> +except ImportError:
> + import pickle
> +
> class baseformatter(object):
> def __init__(self, ui, topic, opts):
> self._ui = ui
> @@ -107,7 +111,7 @@
> self._data.append(self._item)
> def end(self):
> baseformatter.end(self)
> - self._ui.write(cPickle.dumps(self._data))
> + self._ui.write(pickle.dumps(self._data))
>
> def _jsonifyobj(v):
> if isinstance(v, tuple):
> 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
> @@ -45,10 +45,9 @@
> hgext/clonebundles.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> hgext/color.py: invalid syntax: invalid syntax (<unknown>, line *) (glob)
> hgext/convert/bzr.py: error importing module: <SystemError> Parent module 'hgext.convert' not loaded, cannot perform relative import (line *) (glob)
> - hgext/convert/common.py: error importing module: <ImportError> No module named 'cPickle' (line *) (glob)
> hgext/convert/convcmd.py: error importing: <SyntaxError> invalid syntax (bundle*.py, line *) (error at bundlerepo.py:*) (glob)
> hgext/convert/cvs.py: error importing module: <SystemError> Parent module 'hgext.convert' not loaded, cannot perform relative import (line *) (glob)
> - hgext/convert/cvsps.py: error importing module: <ImportError> No module named 'cPickle' (line *) (glob)
> + hgext/convert/cvsps.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> hgext/convert/darcs.py: error importing module: <SystemError> Parent module 'hgext.convert' not loaded, cannot perform relative import (line *) (glob)
> hgext/convert/filemap.py: error importing module: <SystemError> Parent module 'hgext.convert' not loaded, cannot perform relative import (line *) (glob)
> hgext/convert/git.py: error importing module: <SystemError> Parent module 'hgext.convert' not loaded, cannot perform relative import (line *) (glob)
> @@ -56,7 +55,7 @@
> hgext/convert/hg.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> hgext/convert/monotone.py: error importing module: <SystemError> Parent module 'hgext.convert' not loaded, cannot perform relative import (line *) (glob)
> hgext/convert/p*.py: error importing module: <SystemError> Parent module 'hgext.convert' not loaded, cannot perform relative import (line *) (glob)
> - hgext/convert/subversion.py: error importing module: <ImportError> No module named 'cPickle' (line *) (glob)
> + hgext/convert/subversion.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> hgext/convert/transport.py: error importing module: <ImportError> No module named 'svn.client' (line *) (glob)
> hgext/eol.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> hgext/extdiff.py: error importing module: <SyntaxError> invalid syntax (archival.py, line *) (line *) (glob)
> @@ -109,9 +108,9 @@
> mercurial/exchange.py: error importing module: <SyntaxError> invalid syntax (bundle*.py, line *) (line *) (glob)
> mercurial/extensions.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> mercurial/filelog.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> - mercurial/filemerge.py: error importing: <ImportError> No module named 'cPickle' (error at formatter.py:*) (glob)
> + mercurial/filemerge.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> mercurial/fileset.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> - mercurial/formatter.py: error importing module: <ImportError> No module named 'cPickle' (line *) (glob)
> + mercurial/formatter.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> mercurial/graphmod.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> mercurial/help.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> mercurial/hg.py: error importing: <SyntaxError> invalid syntax (bundle*.py, line *) (error at bundlerepo.py:*) (glob)
> @@ -151,7 +150,7 @@
> mercurial/templatefilters.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> mercurial/templatekw.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> mercurial/templater.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> - mercurial/ui.py: error importing: <ImportError> No module named 'cPickle' (error at formatter.py:*) (glob)
> + mercurial/ui.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> mercurial/unionrepo.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> mercurial/url.py: error importing module: <ImportError> No module named 'httplib' (line *) (glob)
> mercurial/verify.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
More information about the Mercurial-devel
mailing list