D7419: help: port to ResourceReader API
indygreg (Gregory Szorc)
phabricator at mercurial-scm.org
Fri Nov 15 03:59:02 UTC 2019
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
Previous commits introduced a mechanism to obtain an
importlib.abc.ResourceReader for Mercurial resource data.
This commit ports I/O in the help system to use this API.
By doing so, we abstract I/O away from the help system and
allow help files to be served from something that isn't
a traditional filesystem.
REPOSITORY
rHG Mercurial
BRANCH
default
REVISION DETAIL
https://phab.mercurial-scm.org/D7419
AFFECTED FILES
mercurial/help.py
CHANGE DETAILS
diff --git a/mercurial/help.py b/mercurial/help.py
--- a/mercurial/help.py
+++ b/mercurial/help.py
@@ -8,7 +8,6 @@
from __future__ import absolute_import
import itertools
-import os
import re
import textwrap
@@ -37,6 +36,9 @@
from .hgweb import (
webcommands,
)
+from .utils import (
+ procutil,
+)
_exclkeywords = {
"(ADVANCED)",
@@ -291,13 +293,19 @@
"""Return a delayed loader for help/topic.txt."""
def loader(ui):
- docdir = os.path.join(util.datapath, 'help')
+ reader = procutil.resourcereader('mercurial')
+
if subdir:
- docdir = os.path.join(docdir, subdir)
- path = os.path.join(docdir, topic + ".txt")
- doc = gettext(util.readfile(path))
+ resource = b'help/%s/%s.txt' % (subdir, topic)
+ else:
+ resource = b'help/%s.txt' % topic
+
+ with reader.open_resource(resource) as fh:
+ doc = gettext(fh.read())
+
for rewriter in helphooks.get(topic, []):
doc = rewriter(ui, topic, doc)
+
return doc
return loader
To: indygreg, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list