Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/help.py @ 43877:1390bb81163e
help: get helptext/ data from `resources` module if available
For PyOxidizer, we need to read configs using the `resources`
module. This patch makes it so we use that module if available
(i.e. Python >= 3.7). It does that by adding a new `open_resource()`
function to our `resourceutil` module.
Tested by running `$PYTHON ./hg help pager` for each $PYTHON in
{python2, python3.6, python3.7}.
Differential Revision: https://phab.mercurial-scm.org/D7622
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 12 Dec 2019 12:57:13 -0800 |
parents | 5be909dbe385 |
children | 52f0140c2604 |
comparison
equal
deleted
inserted
replaced
43876:66af68d4c751 | 43877:1390bb81163e |
---|---|
6 # GNU General Public License version 2 or any later version. | 6 # GNU General Public License version 2 or any later version. |
7 | 7 |
8 from __future__ import absolute_import | 8 from __future__ import absolute_import |
9 | 9 |
10 import itertools | 10 import itertools |
11 import os | |
12 import re | 11 import re |
13 import textwrap | 12 import textwrap |
14 | 13 |
15 from .i18n import ( | 14 from .i18n import ( |
16 _, | 15 _, |
312 | 311 |
313 def loaddoc(topic, subdir=None): | 312 def loaddoc(topic, subdir=None): |
314 """Return a delayed loader for help/topic.txt.""" | 313 """Return a delayed loader for help/topic.txt.""" |
315 | 314 |
316 def loader(ui): | 315 def loader(ui): |
317 docdir = os.path.join(resourceutil.datapath, b'helptext') | 316 package = b'helptext' |
318 if subdir: | 317 if subdir: |
319 docdir = os.path.join(docdir, subdir) | 318 package = b'helptext' + b'.' + subdir |
320 path = os.path.join(docdir, topic + b".txt") | 319 with resourceutil.open_resource(package, topic + b'.txt') as fp: |
321 doc = gettext(util.readfile(path)) | 320 doc = gettext(fp.read()) |
322 for rewriter in helphooks.get(topic, []): | 321 for rewriter in helphooks.get(topic, []): |
323 doc = rewriter(ui, topic, doc) | 322 doc = rewriter(ui, topic, doc) |
324 return doc | 323 return doc |
325 | 324 |
326 return loader | 325 return loader |