[PATCH 11 of 11 py3] extensions: fix extension module hunting on Python 3
Martijn Pieters
mj at zopatista.com
Sun Oct 9 10:32:49 EDT 2016
On 9 October 2016 at 16:16, Augie Fackler <raf at durin42.com> wrote:
> # 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.
>
os.fsdecode exists only in Python 3, I'm afraid.
> 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)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>
--
Martijn Pieters
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20161009/a45c68bc/attachment.html>
More information about the Mercurial-devel
mailing list