diff --git a/mercurial/help.py b/mercurial/help.py --- a/mercurial/help.py +++ b/mercurial/help.py @@ -10,6 +10,7 @@ import itertools import os import re +import sys import textwrap from .i18n import ( @@ -310,12 +311,26 @@ def loaddoc(topic, subdir=None): """Return a delayed loader for help/topic.txt.""" + if getattr(sys, 'oxidized', None): + from importlib import resources + + def _docdata(): + docpkg = b'mercurial.helptext' + if subdir: + docpkg += b'.' + subdir + with resources.open_binary(pycompat.sysstr(docpkg), + pycompat.sysstr(topic + b".txt")) as dh: + return dh.read() + else: + def _docdata(): + docdir = os.path.join(util.datapath, b'helptext') + if subdir: + docdir = os.path.join(docdir, subdir) + path = os.path.join(docdir, topic + b".txt") + return util.readfile(path) + def loader(ui): - docdir = os.path.join(util.datapath, b'helptext') - if subdir: - docdir = os.path.join(docdir, subdir) - path = os.path.join(docdir, topic + b".txt") - doc = gettext(util.readfile(path)) + doc = gettext(_docdata()) for rewriter in helphooks.get(topic, []): doc = rewriter(ui, topic, doc) return doc