[PATCH 11 of 11 py3] extensions: fix extension module hunting on Python 3
Augie Fackler
raf at durin42.com
Sun Oct 9 10:16:53 EDT 2016
# HG changeset patch
# User Augie Fackler <augie at google.com>
# Date 1476019688 14400
# Sun Oct 09 09:28:08 2016 -0400
# Node ID e6a69e778cb02cada23352df512b8580026640d9
# Parent e89f400277d564c4a576ad8e4a6003a201993639
extensions: fix extension module hunting on Python 3
importlib is a firm believer that paths are really strings, not
bytes. Fortunately we have os.fsdecode to help us with that.
This also makes a few strings r-strings to make them bytes on Py2 and
str on py3. That might be too clever?
diff --git a/mercurial/extensions.py b/mercurial/extensions.py
--- a/mercurial/extensions.py
+++ b/mercurial/extensions.py
@@ -18,6 +18,7 @@ from .i18n import (
from . import (
cmdutil,
error,
+ pycompat,
util,
)
@@ -57,8 +58,9 @@ def find(name):
return mod
def loadpath(path, module_name):
- module_name = module_name.replace('.', '_')
+ module_name = module_name.replace(r'.', r'_')
path = util.normpath(util.expandpath(path))
+ path = os.fsdecode(path)
if os.path.isdir(path):
# module/__init__.py style
d, f = os.path.split(path)
@@ -85,7 +87,7 @@ def _importext(name, path=None, reportfu
# the module will be loaded in sys.modules
# choose an unique name so that it doesn't
# conflicts with other modules
- mod = loadpath(path, 'hgext.%s' % name)
+ mod = loadpath(path, pycompat.sysstr('hgext.%s' % name))
else:
try:
mod = _importh("hgext.%s" % name)
More information about the Mercurial-devel
mailing list