Patchwork [08,of,10] parsers: switch to policy importer

login
register
mail settings
Submitter Yuya Nishihara
Date May 20, 2017, 8:41 a.m.
Message ID <505725caf94ef1d8ae1c.1495269675@mimosa>
Download mbox | patch
Permalink /patch/20768/
State Accepted
Headers show

Comments

Yuya Nishihara - May 20, 2017, 8:41 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1471058636 -32400
#      Sat Aug 13 12:23:56 2016 +0900
# Node ID 505725caf94ef1d8ae1cd29ec89cce668294f096
# Parent  354d8983dc0596b6ba1491084a9bfc0ee04ed188
parsers: switch to policy importer

Patch

diff --git a/contrib/check-py3-compat.py b/contrib/check-py3-compat.py
--- a/contrib/check-py3-compat.py
+++ b/contrib/check-py3-compat.py
@@ -17,7 +17,6 @@  import traceback
 
 # Modules that have both Python and C implementations.
 _dualmodules = (
-    'parsers.py',
 )
 
 def check_compat_py2(f):
diff --git a/contrib/import-checker.py b/contrib/import-checker.py
--- a/contrib/import-checker.py
+++ b/contrib/import-checker.py
@@ -26,7 +26,6 @@  allowsymbolimports = (
 
 # Modules that have both Python and C implementations.
 _dualmodules = (
-    'parsers.py',
 )
 
 # Modules that must be aliased because they are commonly confused with
diff --git a/contrib/wix/dist.wxs b/contrib/wix/dist.wxs
--- a/contrib/wix/dist.wxs
+++ b/contrib/wix/dist.wxs
@@ -17,7 +17,7 @@ 
           <File Name="mercurial.cext.diffhelpers.pyd" />
           <File Name="mercurial.cext.mpatch.pyd" />
           <File Name="mercurial.cext.osutil.pyd" />
-          <File Name="mercurial.parsers.pyd" />
+          <File Name="mercurial.cext.parsers.pyd" />
           <File Name="pyexpat.pyd" />
           <File Name="bz2.pyd" />
           <File Name="select.pyd" />
diff --git a/mercurial/__init__.py b/mercurial/__init__.py
--- a/mercurial/__init__.py
+++ b/mercurial/__init__.py
@@ -23,7 +23,6 @@  modulepolicy = policy.policy
 # Modules that have both Python and C implementations. See also the
 # set of .py files under mercurial/pure/.
 _dualmodules = {
-    'mercurial.parsers',
 }
 
 class hgimporter(object):
diff --git a/mercurial/dirs.c b/mercurial/cext/dirs.c
rename from mercurial/dirs.c
rename to mercurial/cext/dirs.c
diff --git a/mercurial/manifest.c b/mercurial/cext/manifest.c
rename from mercurial/manifest.c
rename to mercurial/cext/manifest.c
diff --git a/mercurial/parsers.c b/mercurial/cext/parsers.c
rename from mercurial/parsers.c
rename to mercurial/cext/parsers.c
diff --git a/mercurial/pathencode.c b/mercurial/cext/pathencode.c
rename from mercurial/pathencode.c
rename to mercurial/cext/pathencode.c
diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -19,14 +19,16 @@  from . import (
     encoding,
     error,
     match as matchmod,
-    parsers,
     pathutil,
+    policy,
     pycompat,
     scmutil,
     txnutil,
     util,
 )
 
+parsers = policy.importmod(r'parsers')
+
 propertycache = util.propertycache
 filecache = scmutil.filecache
 _rangemask = 0x7fffffff
diff --git a/mercurial/encoding.py b/mercurial/encoding.py
--- a/mercurial/encoding.py
+++ b/mercurial/encoding.py
@@ -14,6 +14,7 @@  import unicodedata
 
 from . import (
     error,
+    policy,
     pycompat,
 )
 
@@ -318,7 +319,7 @@  def _asciilower(s):
 def asciilower(s):
     # delay importing avoids cyclic dependency around "parsers" in
     # pure Python build (util => i18n => encoding => parsers => util)
-    from . import parsers
+    parsers = policy.importmod(r'parsers')
     impl = getattr(parsers, 'asciilower', _asciilower)
     global asciilower
     asciilower = impl
@@ -334,7 +335,7 @@  def _asciiupper(s):
 def asciiupper(s):
     # delay importing avoids cyclic dependency around "parsers" in
     # pure Python build (util => i18n => encoding => parsers => util)
-    from . import parsers
+    parsers = policy.importmod(r'parsers')
     impl = getattr(parsers, 'asciiupper', _asciiupper)
     global asciiupper
     asciiupper = impl
diff --git a/mercurial/manifest.py b/mercurial/manifest.py
--- a/mercurial/manifest.py
+++ b/mercurial/manifest.py
@@ -19,11 +19,12 @@  from .node import (
 from . import (
     error,
     mdiff,
-    parsers,
+    policy,
     revlog,
     util,
 )
 
+parsers = policy.importmod(r'parsers')
 propertycache = util.propertycache
 
 def _parsev1(data):
diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -76,11 +76,13 @@  from .i18n import _
 from . import (
     error,
     node,
-    parsers,
     phases,
+    policy,
     util,
 )
 
+parsers = policy.importmod(r'parsers')
+
 _pack = struct.pack
 _unpack = struct.unpack
 _calcsize = struct.calcsize
diff --git a/mercurial/pure/parsers.py b/mercurial/pure/parsers.py
--- a/mercurial/pure/parsers.py
+++ b/mercurial/pure/parsers.py
@@ -10,8 +10,8 @@  from __future__ import absolute_import
 import struct
 import zlib
 
-from .node import nullid
-from . import pycompat
+from ..node import nullid
+from .. import pycompat
 stringio = pycompat.stringio
 
 
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -32,12 +32,14 @@  from . import (
     ancestor,
     error,
     mdiff,
-    parsers,
+    policy,
     pycompat,
     templatefilters,
     util,
 )
 
+parsers = policy.importmod(r'parsers')
+
 _pack = struct.pack
 _unpack = struct.unpack
 # Aliased for performance.
diff --git a/mercurial/store.py b/mercurial/store.py
--- a/mercurial/store.py
+++ b/mercurial/store.py
@@ -15,12 +15,14 @@  import stat
 from .i18n import _
 from . import (
     error,
-    parsers,
+    policy,
     pycompat,
     util,
     vfs as vfsmod,
 )
 
+parsers = policy.importmod(r'parsers')
+
 # This avoids a collision between a file named foo and a dir named
 # foo.i or foo.d
 def _encodedir(path):
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -45,13 +45,13 @@  from . import (
     encoding,
     error,
     i18n,
-    parsers,
     policy,
     pycompat,
 )
 
 base85 = policy.importmod(r'base85')
 osutil = policy.importmod(r'osutil')
+parsers = policy.importmod(r'parsers')
 
 b85decode = base85.b85decode
 b85encode = base85.b85encode
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -635,10 +635,10 @@  extmodules = [
                                         'mercurial/cext/mpatch.c'],
               include_dirs=common_include_dirs,
               depends=common_depends),
-    Extension('mercurial.parsers', ['mercurial/dirs.c',
-                                    'mercurial/manifest.c',
-                                    'mercurial/parsers.c',
-                                    'mercurial/pathencode.c'],
+    Extension('mercurial.cext.parsers', ['mercurial/cext/dirs.c',
+                                         'mercurial/cext/manifest.c',
+                                         'mercurial/cext/parsers.c',
+                                         'mercurial/cext/pathencode.c'],
               include_dirs=common_include_dirs,
               depends=common_depends),
     Extension('mercurial.cext.osutil', ['mercurial/cext/osutil.c'],
diff --git a/tests/fakedirstatewritetime.py b/tests/fakedirstatewritetime.py
--- a/tests/fakedirstatewritetime.py
+++ b/tests/fakedirstatewritetime.py
@@ -11,10 +11,12 @@  from mercurial import (
     context,
     dirstate,
     extensions,
-    parsers,
+    policy,
     util,
 )
 
+parsers = policy.importmod(r'parsers')
+
 def pack_dirstate(fakenow, orig, dmap, copymap, pl, now):
     # execute what original parsers.pack_dirstate should do actually
     # for consistency
diff --git a/tests/test-parseindex2.py b/tests/test-parseindex2.py
--- a/tests/test-parseindex2.py
+++ b/tests/test-parseindex2.py
@@ -14,9 +14,11 @@  from mercurial.node import (
     nullrev,
 )
 from mercurial import (
-    parsers,
+    policy,
 )
 
+parsers = policy.importmod(r'parsers')
+
 # original python implementation
 def gettype(q):
     return int(q & 0xFFFF)
@@ -114,7 +116,7 @@  def importparsers(hexversion):
     # of the currently-running Python interpreter, so we monkey-patch
     # sys.hexversion to simulate using different versions.
     code = ("import sys; sys.hexversion=%s; "
-            "import mercurial.parsers" % hexversion)
+            "import mercurial.cext.parsers" % hexversion)
     cmd = "python -c \"%s\"" % code
     # We need to do these tests inside a subprocess because parser.c's
     # version-checking code happens inside the module init function, and