py3: manually import pycompat.open into files that need it
authorGregory Szorc <gregory.szorc@gmail.com>
Sun, 06 Oct 2019 13:28:56 -0400
changeset 43085 eef9a2d67051
parent 43084 c2e284cee333
child 43086 bbcbb82e3589
py3: manually import pycompat.open into files that need it We want to eliminate the source transformer. Currently it inserts a `from mercurial.pycompat import ...` at the top of files to alias some builtins. This commit replaces the implicit import of `open` with an explicit import on files that need it and changes the source transformer to no longer import `open`. As part of this, we needed to store an explicit local for `open` in the Python 2 code path in `pycompat` so the import works. (Builtins that are automatically in scope cannot be imported.) Differential Revision: https://phab.mercurial-scm.org/D7005
hgext/churn.py
hgext/convert/common.py
hgext/convert/convcmd.py
hgext/convert/cvs.py
hgext/convert/cvsps.py
hgext/convert/hg.py
hgext/convert/monotone.py
hgext/convert/subversion.py
hgext/fastannotate/context.py
hgext/fastannotate/protocol.py
hgext/fastannotate/revmap.py
hgext/fsmonitor/__init__.py
hgext/histedit.py
hgext/infinitepush/__init__.py
hgext/infinitepush/store.py
hgext/largefiles/lfutil.py
hgext/largefiles/localstore.py
hgext/largefiles/overrides.py
hgext/largefiles/proto.py
hgext/mq.py
hgext/patchbomb.py
hgext/rebase.py
hgext/releasenotes.py
hgext/relink.py
hgext/remotefilelog/__init__.py
hgext/remotefilelog/basepack.py
hgext/remotefilelog/basestore.py
hgext/remotefilelog/debugcommands.py
hgext/remotefilelog/remotefilelogserver.py
hgext/remotefilelog/shallowutil.py
hgext/transplant.py
mercurial/__init__.py
mercurial/archival.py
mercurial/changegroup.py
mercurial/cmdutil.py
mercurial/commands.py
mercurial/context.py
mercurial/crecord.py
mercurial/debugcommands.py
mercurial/extensions.py
mercurial/filemerge.py
mercurial/hgweb/common.py
mercurial/hgweb/server.py
mercurial/httpconnection.py
mercurial/mail.py
mercurial/match.py
mercurial/patch.py
mercurial/posix.py
mercurial/profiling.py
mercurial/pycompat.py
mercurial/server.py
mercurial/shelve.py
mercurial/statprof.py
mercurial/streamclone.py
mercurial/subrepo.py
mercurial/ui.py
mercurial/util.py
mercurial/utils/procutil.py
--- a/hgext/churn.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/hgext/churn.py	Sun Oct 06 13:28:56 2019 -0400
@@ -15,6 +15,7 @@
 import time
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     cmdutil,
     encoding,
--- a/hgext/convert/common.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/hgext/convert/common.py	Sun Oct 06 13:28:56 2019 -0400
@@ -15,6 +15,7 @@
 import subprocess
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     encoding,
     error,
--- a/hgext/convert/convcmd.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/hgext/convert/convcmd.py	Sun Oct 06 13:28:56 2019 -0400
@@ -11,6 +11,7 @@
 import shutil
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     encoding,
     error,
--- a/hgext/convert/cvs.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/hgext/convert/cvs.py	Sun Oct 06 13:28:56 2019 -0400
@@ -12,6 +12,7 @@
 import socket
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     encoding,
     error,
--- a/hgext/convert/cvsps.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/hgext/convert/cvsps.py	Sun Oct 06 13:28:56 2019 -0400
@@ -11,6 +11,7 @@
 import re
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     encoding,
     error,
--- a/hgext/convert/hg.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/hgext/convert/hg.py	Sun Oct 06 13:28:56 2019 -0400
@@ -23,6 +23,7 @@
 import time
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     bookmarks,
     context,
--- a/hgext/convert/monotone.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/hgext/convert/monotone.py	Sun Oct 06 13:28:56 2019 -0400
@@ -11,6 +11,7 @@
 import re
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     error,
     pycompat,
--- a/hgext/convert/subversion.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/hgext/convert/subversion.py	Sun Oct 06 13:28:56 2019 -0400
@@ -8,6 +8,7 @@
 import xml.dom.minidom
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     encoding,
     error,
--- a/hgext/fastannotate/context.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/hgext/fastannotate/context.py	Sun Oct 06 13:28:56 2019 -0400
@@ -13,6 +13,7 @@
 import os
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     error,
     linelog as linelogmod,
--- a/hgext/fastannotate/protocol.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/hgext/fastannotate/protocol.py	Sun Oct 06 13:28:56 2019 -0400
@@ -10,6 +10,7 @@
 import os
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     error,
     extensions,
--- a/hgext/fastannotate/revmap.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/hgext/fastannotate/revmap.py	Sun Oct 06 13:28:56 2019 -0400
@@ -13,6 +13,7 @@
 import struct
 
 from mercurial.node import hex
+from mercurial.pycompat import open
 from mercurial import (
     error as hgerror,
     pycompat,
--- a/hgext/fsmonitor/__init__.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/hgext/fsmonitor/__init__.py	Sun Oct 06 13:28:56 2019 -0400
@@ -117,7 +117,7 @@
 
 from mercurial.i18n import _
 from mercurial.node import hex
-
+from mercurial.pycompat import open
 from mercurial import (
     context,
     encoding,
--- a/hgext/histedit.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/hgext/histedit.py	Sun Oct 06 13:28:56 2019 -0400
@@ -206,6 +206,7 @@
 import struct
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     bundle2,
     cmdutil,
--- a/hgext/infinitepush/__init__.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/hgext/infinitepush/__init__.py	Sun Oct 06 13:28:56 2019 -0400
@@ -103,6 +103,8 @@
 
 from mercurial.i18n import _
 
+from mercurial.pycompat import open
+
 from mercurial.utils import (
     procutil,
     stringutil,
--- a/hgext/infinitepush/store.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/hgext/infinitepush/store.py	Sun Oct 06 13:28:56 2019 -0400
@@ -11,6 +11,7 @@
 import subprocess
 import tempfile
 
+from mercurial.pycompat import open
 from mercurial import (
     node,
     pycompat,
--- a/hgext/largefiles/lfutil.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/hgext/largefiles/lfutil.py	Sun Oct 06 13:28:56 2019 -0400
@@ -16,6 +16,7 @@
 
 from mercurial.i18n import _
 from mercurial.node import hex
+from mercurial.pycompat import open
 
 from mercurial import (
     dirstate,
--- a/hgext/largefiles/localstore.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/hgext/largefiles/localstore.py	Sun Oct 06 13:28:56 2019 -0400
@@ -10,6 +10,7 @@
 from __future__ import absolute_import
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import util
 
 from . import (
--- a/hgext/largefiles/overrides.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/hgext/largefiles/overrides.py	Sun Oct 06 13:28:56 2019 -0400
@@ -14,6 +14,8 @@
 
 from mercurial.i18n import _
 
+from mercurial.pycompat import open
+
 from mercurial.hgweb import webcommands
 
 from mercurial import (
--- a/hgext/largefiles/proto.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/hgext/largefiles/proto.py	Sun Oct 06 13:28:56 2019 -0400
@@ -8,6 +8,7 @@
 import re
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 
 from mercurial import (
     error,
--- a/hgext/mq.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/hgext/mq.py	Sun Oct 06 13:28:56 2019 -0400
@@ -76,6 +76,7 @@
     nullrev,
     short,
 )
+from mercurial.pycompat import open
 from mercurial import (
     cmdutil,
     commands,
--- a/hgext/patchbomb.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/hgext/patchbomb.py	Sun Oct 06 13:28:56 2019 -0400
@@ -83,6 +83,7 @@
 import socket
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     cmdutil,
     commands,
--- a/hgext/rebase.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/hgext/rebase.py	Sun Oct 06 13:28:56 2019 -0400
@@ -24,6 +24,7 @@
     nullrev,
     short,
 )
+from mercurial.pycompat import open
 from mercurial import (
     bookmarks,
     cmdutil,
--- a/hgext/releasenotes.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/hgext/releasenotes.py	Sun Oct 06 13:28:56 2019 -0400
@@ -18,6 +18,7 @@
 import re
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     config,
     error,
--- a/hgext/relink.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/hgext/relink.py	Sun Oct 06 13:28:56 2019 -0400
@@ -12,6 +12,7 @@
 import stat
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     error,
     hg,
--- a/hgext/remotefilelog/__init__.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/hgext/remotefilelog/__init__.py	Sun Oct 06 13:28:56 2019 -0400
@@ -132,6 +132,7 @@
 
 from mercurial.node import hex
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     changegroup,
     changelog,
--- a/hgext/remotefilelog/basepack.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/hgext/remotefilelog/basepack.py	Sun Oct 06 13:28:56 2019 -0400
@@ -9,6 +9,7 @@
 import time
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     node as nodemod,
     policy,
--- a/hgext/remotefilelog/basestore.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/hgext/remotefilelog/basestore.py	Sun Oct 06 13:28:56 2019 -0400
@@ -9,6 +9,7 @@
 
 from mercurial.i18n import _
 from mercurial.node import bin, hex
+from mercurial.pycompat import open
 from mercurial import (
     error,
     pycompat,
--- a/hgext/remotefilelog/debugcommands.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/hgext/remotefilelog/debugcommands.py	Sun Oct 06 13:28:56 2019 -0400
@@ -12,6 +12,7 @@
 
 from mercurial.node import bin, hex, nullid, short
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     error,
     filelog,
--- a/hgext/remotefilelog/remotefilelogserver.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/hgext/remotefilelog/remotefilelogserver.py	Sun Oct 06 13:28:56 2019 -0400
@@ -14,6 +14,7 @@
 
 from mercurial.i18n import _
 from mercurial.node import bin, hex, nullid
+from mercurial.pycompat import open
 from mercurial import (
     changegroup,
     changelog,
--- a/hgext/remotefilelog/shallowutil.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/hgext/remotefilelog/shallowutil.py	Sun Oct 06 13:28:56 2019 -0400
@@ -15,6 +15,7 @@
 import tempfile
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     error,
     node,
--- a/hgext/transplant.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/hgext/transplant.py	Sun Oct 06 13:28:56 2019 -0400
@@ -18,6 +18,7 @@
 import os
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     bundlerepo,
     cmdutil,
--- a/mercurial/__init__.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/mercurial/__init__.py	Sun Oct 06 13:28:56 2019 -0400
@@ -172,7 +172,7 @@
                 l = (
                     b'; from mercurial.pycompat import '
                     b'delattr, getattr, hasattr, setattr, '
-                    b'open, unicode\n'
+                    b'unicode\n'
                 )
                 for u in tokenize.tokenize(io.BytesIO(l).readline):
                     if u.type in (tokenize.ENCODING, token.ENDMARKER):
@@ -221,7 +221,7 @@
     # ``replacetoken`` or any mechanism that changes semantics of module
     # loading is changed. Otherwise cached bytecode may get loaded without
     # the new transformation mechanisms applied.
-    BYTECODEHEADER = b'HG\x00\x0c'
+    BYTECODEHEADER = b'HG\x00\x0d'
 
     class hgloader(importlib.machinery.SourceFileLoader):
         """Custom module loader that transforms source code.
--- a/mercurial/archival.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/mercurial/archival.py	Sun Oct 06 13:28:56 2019 -0400
@@ -17,6 +17,7 @@
 
 from .i18n import _
 from .node import nullrev
+from .pycompat import open
 
 from . import (
     error,
--- a/mercurial/changegroup.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/mercurial/changegroup.py	Sun Oct 06 13:28:56 2019 -0400
@@ -18,6 +18,7 @@
     nullrev,
     short,
 )
+from .pycompat import open
 
 from . import (
     error,
--- a/mercurial/cmdutil.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/mercurial/cmdutil.py	Sun Oct 06 13:28:56 2019 -0400
@@ -19,6 +19,7 @@
     nullrev,
     short,
 )
+from .pycompat import open
 
 from . import (
     bookmarks,
--- a/mercurial/commands.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/mercurial/commands.py	Sun Oct 06 13:28:56 2019 -0400
@@ -22,6 +22,7 @@
     wdirhex,
     wdirrev,
 )
+from .pycompat import open
 from . import (
     archival,
     bookmarks,
--- a/mercurial/context.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/mercurial/context.py	Sun Oct 06 13:28:56 2019 -0400
@@ -23,6 +23,7 @@
     wdirfilenodeids,
     wdirhex,
 )
+from .pycompat import open
 from . import (
     copies,
     dagop,
--- a/mercurial/crecord.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/mercurial/crecord.py	Sun Oct 06 13:28:56 2019 -0400
@@ -16,6 +16,7 @@
 import signal
 
 from .i18n import _
+from .pycompat import open
 from . import (
     encoding,
     error,
--- a/mercurial/debugcommands.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/mercurial/debugcommands.py	Sun Oct 06 13:28:56 2019 -0400
@@ -32,6 +32,7 @@
     nullrev,
     short,
 )
+from .pycompat import open
 from . import (
     bundle2,
     changegroup,
--- a/mercurial/extensions.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/mercurial/extensions.py	Sun Oct 06 13:28:56 2019 -0400
@@ -18,6 +18,7 @@
     _,
     gettext,
 )
+from .pycompat import open
 
 from . import (
     cmdutil,
--- a/mercurial/filemerge.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/mercurial/filemerge.py	Sun Oct 06 13:28:56 2019 -0400
@@ -18,6 +18,7 @@
     nullid,
     short,
 )
+from .pycompat import open
 
 from . import (
     encoding,
--- a/mercurial/hgweb/common.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/mercurial/hgweb/common.py	Sun Oct 06 13:28:56 2019 -0400
@@ -14,6 +14,7 @@
 import os
 import stat
 
+from ..pycompat import open
 from .. import (
     encoding,
     pycompat,
--- a/mercurial/hgweb/server.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/mercurial/hgweb/server.py	Sun Oct 06 13:28:56 2019 -0400
@@ -17,6 +17,7 @@
 import wsgiref.validate
 
 from ..i18n import _
+from ..pycompat import open
 
 from .. import (
     encoding,
--- a/mercurial/httpconnection.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/mercurial/httpconnection.py	Sun Oct 06 13:28:56 2019 -0400
@@ -13,6 +13,7 @@
 import os
 
 from .i18n import _
+from .pycompat import open
 from . import (
     pycompat,
     util,
--- a/mercurial/mail.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/mercurial/mail.py	Sun Oct 06 13:28:56 2019 -0400
@@ -19,6 +19,7 @@
 import time
 
 from .i18n import _
+from .pycompat import open
 from . import (
     encoding,
     error,
--- a/mercurial/match.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/mercurial/match.py	Sun Oct 06 13:28:56 2019 -0400
@@ -13,6 +13,7 @@
 import re
 
 from .i18n import _
+from .pycompat import open
 from . import (
     encoding,
     error,
--- a/mercurial/patch.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/mercurial/patch.py	Sun Oct 06 13:28:56 2019 -0400
@@ -24,6 +24,7 @@
     hex,
     short,
 )
+from .pycompat import open
 from . import (
     copies,
     diffhelper,
--- a/mercurial/posix.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/mercurial/posix.py	Sun Oct 06 13:28:56 2019 -0400
@@ -21,6 +21,7 @@
 import unicodedata
 
 from .i18n import _
+from .pycompat import open
 from . import (
     encoding,
     error,
--- a/mercurial/profiling.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/mercurial/profiling.py	Sun Oct 06 13:28:56 2019 -0400
@@ -10,6 +10,7 @@
 import contextlib
 
 from .i18n import _
+from .pycompat import open
 from . import (
     encoding,
     error,
--- a/mercurial/pycompat.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/mercurial/pycompat.py	Sun Oct 06 13:28:56 2019 -0400
@@ -354,6 +354,7 @@
     sysstr = identity
     strurl = identity
     bytesurl = identity
+    open = open
 
     # this can't be parsed on Python 3
     exec(b'def raisewithtb(exc, tb):\n' b'    raise exc, None, tb\n')
--- a/mercurial/server.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/mercurial/server.py	Sun Oct 06 13:28:56 2019 -0400
@@ -10,6 +10,7 @@
 import os
 
 from .i18n import _
+from .pycompat import open
 
 from . import (
     chgserver,
--- a/mercurial/shelve.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/mercurial/shelve.py	Sun Oct 06 13:28:56 2019 -0400
@@ -28,6 +28,7 @@
 import stat
 
 from .i18n import _
+from .pycompat import open
 from . import (
     bookmarks,
     bundle2,
--- a/mercurial/statprof.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/mercurial/statprof.py	Sun Oct 06 13:28:56 2019 -0400
@@ -114,6 +114,7 @@
 import threading
 import time
 
+from .pycompat import open
 from . import (
     encoding,
     pycompat,
--- a/mercurial/streamclone.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/mercurial/streamclone.py	Sun Oct 06 13:28:56 2019 -0400
@@ -12,6 +12,7 @@
 import struct
 
 from .i18n import _
+from .pycompat import open
 from .interfaces import repository
 from . import (
     cacheutil,
--- a/mercurial/subrepo.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/mercurial/subrepo.py	Sun Oct 06 13:28:56 2019 -0400
@@ -19,6 +19,7 @@
 import xml.dom.minidom
 
 from .i18n import _
+from .pycompat import open
 from . import (
     cmdutil,
     encoding,
--- a/mercurial/ui.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/mercurial/ui.py	Sun Oct 06 13:28:56 2019 -0400
@@ -22,6 +22,7 @@
 
 from .i18n import _
 from .node import hex
+from .pycompat import open
 
 from . import (
     color,
--- a/mercurial/util.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/mercurial/util.py	Sun Oct 06 13:28:56 2019 -0400
@@ -35,6 +35,7 @@
 import warnings
 
 from .thirdparty import attr
+from .pycompat import open
 from hgdemandimport import tracing
 from . import (
     encoding,
--- a/mercurial/utils/procutil.py	Sun Oct 06 13:17:19 2019 -0400
+++ b/mercurial/utils/procutil.py	Sun Oct 06 13:28:56 2019 -0400
@@ -20,6 +20,7 @@
 import time
 
 from ..i18n import _
+from ..pycompat import open
 
 from .. import (
     encoding,