Patchwork D7419: help: port to ResourceReader API

login
register
mail settings
Submitter phabricator
Date Nov. 15, 2019, 3:59 a.m.
Message ID <differential-rev-PHID-DREV-3jamkzhstmjas4sjpymz-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/43255/
State New
Headers show

Comments

phabricator - Nov. 15, 2019, 3:59 a.m.
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




To: indygreg, #hg-reviewers
Cc: mercurial-devel
phabricator - Nov. 15, 2019, 4:03 a.m.
indygreg added a comment.
indygreg planned changes to this revision.


  I have other patches to attempt to do similar things for templating and rc.d files if there is interest in reviving this series.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7419/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7419

To: indygreg, #hg-reviewers
Cc: mercurial-devel

Patch

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